You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ambari.apache.org by "Thomas Decaux (JIRA)" <ji...@apache.org> on 2018/01/18 13:59:00 UTC

[jira] [Commented] (AMBARI-9016) API not taking or responding with application/json

    [ https://issues.apache.org/jira/browse/AMBARI-9016?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16330539#comment-16330539 ] 

Thomas Decaux commented on AMBARI-9016:
---------------------------------------

It looks like something else is doing the JSON decode before:
{code:java}
18 Jan 2018 14:47:36,681 ERROR [ambari-client-thread-27] ContainerResponse:419 - The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 1 column 2
 at com.google.gson.Gson.fromJson(Gson.java:806)
 at com.google.gson.Gson.fromJson(Gson.java:761)
 at org.apache.ambari.server.api.GsonJsonProvider.readFrom(GsonJsonProvider.java:60)
 at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:490)
 at com.sun.jersey.server.impl.model.method.dispatch.EntityParamDispatchProvider$EntityInjectable.getValue(EntityParamDispatchProvider.java:123)
 at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:86)
 at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
 at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
 at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
 at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
 at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
 at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
 at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
 at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
 at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409){code}

> API not taking or responding with application/json
> --------------------------------------------------
>
>                 Key: AMBARI-9016
>                 URL: https://issues.apache.org/jira/browse/AMBARI-9016
>             Project: Ambari
>          Issue Type: Bug
>          Components: ambari-server
>    Affects Versions: 1.7.0
>            Reporter: Sean Roberts
>            Priority: Minor
>              Labels: newbie
>
> The  stack advisor API does not accept application/json even though it expects JSON files.
> And it responds with "text/plain" even though the content it is sending is JSON.
> This breaks most any http library or application. Such as those made to work with RESTful APIs.
> The API does not accept JSON and when it responds with JSON it says it's "text/plain":
> {code}
> $ curl -v -u admin\
>   -H "Content-Type: application/json" -H x-requested-by:useless \
>   http://localhost:8080/api/v1/stacks/HDP/versions/2.4/recommendations -d @temp.json
> < HTTP/1.1 500 Server Error
> < Content-Type: text/plain; charset=ISO-8859-1
> {
>   "status": 500,
>   "message": "Server Error"
> }
> {code}
> Meanwhile it accepts JSON as text/plain and still responds with "text/plain" even though it is sending JSON:
> {code}
> $ curl -v -u admin\
>   -H "Content-Type: test/plain" -H x-requested-by:useless \
>   http://localhost:8080/api/v1/stacks/HDP/versions/2.4/recommendations -d @temp.json
> > POST /api/v1/stacks/HDP/versions/2.4/recommendations HTTP/1.1
> > Content-Type: test/plain
> < HTTP/1.1 200 OK
> < Content-Type: text/plain
> {
>   "resources" : [
>     {
>       "href" : "http://localhost:8080/api/v1/stacks/HDP/versions/2.4/recommendations/8",
> ... snipped the rest of the JSON since it's not needed ...
> {code}
> This is the file that was sent:
> {code}
> $ cat temp.json
>     {
>       "recommend" : "configurations",
>       "services" : [ "AMBARI_METRICS","HDFS","HIVE","MAPREDUCE2","PIG","TEZ","YARN","ZOOKEEPER" ],
>       "hosts" : [ "ip-10-0-1-159.ec2.internal","ip-10-0-1-31.ec2.internal","ip-10-0-1-32.ec2.internal","ip-10-0-1-33.ec2.internal" ]
>     }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)