ambari-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Qing Chi 79624 <c...@vmware.com>
Subject Why the Content-Type always is text/plain using ambari REST API?
Date Thu, 12 Jun 2014 04:12:33 GMT
Hi guys,

Following is content of TestAmbariRestApi class. Why the Content-Type always is text/plain
on the response using ambari REST API?


import com.sun.jersey.api.client.Client;

import com.sun.jersey.api.client.ClientResponse;

import com.sun.jersey.api.client.WebResource;

import com.sun.jersey.api.client.config.ClientConfig;

import com.sun.jersey.api.client.config.DefaultClientConfig;

import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

import com.sun.jersey.api.json.JSONConfiguration;

import com.vmware.bdd.api.model.ApiClusterList;


import java.net.URI;


import javax.ws.rs.core.MediaType;

import javax.ws.rs.core.UriBuilder;


public class TestAmbariRestApi {


   private static URI getBaseURI() {

      return UriBuilder.fromUri("http://10.141.73.63:8080/api/v1").build();

   }


   public static void main(String[] args) {

      ClientConfig config = new DefaultClientConfig();

      config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);


      Client client = Client.create(config);

      client.addFilter(new HTTPBasicAuthFilter("admin", "admin"));


      WebResource resource = client.resource(getBaseURI());


      ClientResponse response;

      response = resource.path("clusters").accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_JSON).get(ClientResponse.class);


      System.out.println(response.getStatus());

      System.out.println(response.getHeaders().get("Content-Type"));

      System.out.println(response.getEntity(ApiClusterList.class));

   }

}


Result of running TestAmbariRestApi,


406

[text/plain;charset=ISO-8859-1]

Jun 12, 2014 11:58:43 AM com.sun.jersey.api.client.ClientResponse getEntity

SEVERE: A message body reader for Java class com.vmware.bdd.api.model.ApiClusterList, and
Java type class com.vmware.bdd.api.model.ApiClusterList, and MIME media type text/plain; charset=ISO-8859-1
was not found

Jun 12, 2014 11:58:43 AM com.sun.jersey.api.client.ClientResponse getEntity

SEVERE: The registered message body readers compatible with the MIME media type are:

text/plain; charset=ISO-8859-1 ->

  com.sun.jersey.core.impl.provider.entity.StringProvider

  com.sun.jersey.core.impl.provider.entity.ReaderProvider

*/* ->

  com.sun.jersey.core.impl.provider.entity.FormProvider

  com.sun.jersey.core.impl.provider.entity.MimeMultipartProvider

  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.json.impl.provider.entity.JSONJAXBElementProvider$General

  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

  com.sun.jersey.json.impl.provider.entity.JSONRootElementProvider$General

  com.sun.jersey.json.impl.provider.entity.JSONListElementProvider$General


Exception in thread "main" com.sun.jersey.api.client.ClientHandlerException: A message body
reader for Java class com.vmware.bdd.api.model.ApiClusterList, and Java type class com.vmware.bdd.api.model.ApiClusterList,
and MIME media type text/plain; charset=ISO-8859-1 was not found

at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:630)

at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:586)

at com.vmware.bdd.api.TestAmbariRestAPI.main(TestAmbariRestAPI.java:37)



And I used the following command, and the Content-Type is text/plain on response.


curl -H "Content-Type: application/json" -H  "X-Requested-By: ambari" -X GET --user "admin:admin"
-i http://10.141.73.63:8080/api/v1/clusters/


HTTP/1.1 200 OK

Set-Cookie: AMBARISESSIONID=1i36z3duc4cjr561r6deiub8;Path=/

Expires: Thu, 01 Jan 1970 00:00:00 GMT

Content-Type: text/plain

Content-Length: 422

Server: Jetty(7.6.7.v20120910)


{

  "href" : "http://10.141.73.63:8080/api/v1/clusters/",

  "items" : [

    {

      "href" : "http://10.141.73.63:8080/api/v1/clusters/test",

      "Clusters" : {

        "cluster_name" : "test",

        "version" : "HDP-2.1"

      }

    }

  ]

}

Anybody give me some help?

Thanks,

-qing

Mime
View raw message