zanata-client: need better error message for unexpected html response

Description

Soon, https;//translate.zanata.org/zanata/ will be shorten as
https://translate.zanata.org/ by using HTTP 301 (Moved Permanently).

However zanata-client failed to handled this:

Steps to repoduced:
1. Get zanata.xml from https://translate.stage.zanata.org/iteration/view/selinux-coloring-book/selinux-coloring-book
2. Change url to " https://translate.stage.zanata.org/zanata/" in
both zanata.xml and ~/.config/zanata.ini
3. zanata-cli -B -e pull

Actual:
[INFO] Loading project config from zanata.xml
[INFO] Loading user config from /home/dchen/.config/zanata.ini
Feb 25, 2016 4:17:21 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: A message body reader for Java class java.util.List, and Java type java.util.List<org.zanata.rest.dto.LocaleDetails>, and MIME media type text/html; charset=UTF-8 was not found
Feb 25, 2016 4:17:21 PM com.sun.jersey.api.client.ClientResponse getEntity
SEVERE: The registered message body readers compatible with the MIME media type are:
/ ->
com.sun.jersey.core.impl.provider.entity.FormProvider
com.sun.jersey.core.impl.provider.entity.StringProvider
com.sun.jersey.core.impl.provider.entity.ByteArrayProvider
com.sun.jersey.core.impl.provider.entity.FileProvider
com.sun.jersey.core.impl.provider.entity.InputStreamProvider
com.sun.jersey.core.impl.provider.entity.DataSourceProvider
com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider$General
com.sun.jersey.core.impl.provider.entity.ReaderProvider
com.sun.jersey.core.impl.provider.entity.DocumentProvider
com.sun.jersey.core.impl.provider.entity.SourceProvider$StreamSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$SAXSourceReader
com.sun.jersey.core.impl.provider.entity.SourceProvider$DOMSourceReader
com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLListElementProvider$General
com.sun.jersey.core.impl.provider.entity.XMLRootObjectProvider$General
com.sun.jersey.core.impl.provider.entity.EntityHolderReader

[ERROR] Execution failed:
com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.util.List, and Java type java.util.List<org.zanata.rest.dto.LocaleDetails>, and MIME media type text/html; charset=UTF-8 was not found
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:630)
at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:604)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:698)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:198)
at org.zanata.rest.client.ProjectIterationLocalesClient.getLocales(ProjectIterationLocalesClient.java:54)
at org.zanata.client.commands.OptionsUtil.fetchLocalesFromServer(OptionsUtil.java:113)
at org.zanata.client.commands.OptionsUtil.applyConfigFiles(OptionsUtil.java:100)
at org.zanata.client.commands.ArgsUtil.runCommand(ArgsUtil.java:41)
at org.zanata.client.ZanataClient.processArgs(ZanataClient.java:170)
at org.zanata.client.ZanataClient.main(ZanataClient.java:95)

Expected:
Pull without problem

Environment

None

Activity

Show:
Sean Flanigan
February 26, 2016, 7:28 AM

I would suggest that the client should detect invalid responses (bad media type such as HTML) and generate a meaningful error message to the user: perhaps something like:

Invalid media type (text/html <or whatever was received>) in REST response. Please check that the server URL is correct, including the protocol (http/https). If the URL is correct, there may be a configuration problem on the server.

Sean Flanigan
February 26, 2016, 7:06 AM

Although I guess it wouldn't hurt to have the client produce a useful error
message when an unexpected media type is returned by the server.


Sean Flanigan

Principal Software Engineer
Globalisation Tools Engineering
Red Hat

Sean Flanigan
February 26, 2016, 7:05 AM

Ah! In that case, the redirect is wrong. Can't expect the REST client to
understand HTML when it asked for json or xml.

On 26 February 2016 at 17:02, Patrick Huang (JIRA) <


Sean Flanigan

Principal Software Engineer
Globalisation Tools Engineering
Red Hat

Patrick Huang
February 26, 2016, 7:01 AM

If you type https://translate.stage.zanata.org/zanata/rest/projects/p/pahuang-training/iterations/i/master/locales in url, it returns 301 and then pointed to https://translate.stage.zanata.org/. That's why the exception in description (it returns the html page). I think jersey handles 301 correctly (given --log-http you will see it gets the home page html) but it can't handle the redirected html page (or should we say the redirect will cause all rest request to fail?)

Sean Flanigan
February 26, 2016, 5:51 AM

Patrick, this bug report is about https://translate.stage.zanata.org/zanata/ (which has some new redirections from /zanata to /) , not https://translate.stage.zanata.org/ (which has an older redirection from / to /zanata ) . I think that explains the responses you got.

Ready for Release

Assignee

Patrick Huang

Reporter

Ding-Yi Chen

Labels

None

Tested Version/s

None

Components

Sprint

None

Fix versions

Affects versions

Priority

Medium