0

I am creating a simple Android client for a web service I have built, to get a List from XML.

But I get this stacktrace:

8 16:07:39.272: E/ClientResponse(8460): A message body reader for Java class java.util.List, and Java type java.util.List<xx.xxxx.xxx.xxx.xxxx.xxxx.MessdatenPv>, and MIME media type application/xml was not found
02-18 16:07:39.272: E/ClientResponse(8460): The registered message body readers compatible with the MIME media type are:
02-18 16:07:39.272: E/ClientResponse(8460): */* ->
02-18 16:07:39.272: E/ClientResponse(8460):   com.sun.jersey.core.impl.provider.entity.StringProvider
02-18 16:07:39.272: E/ClientResponse(8460):   com.sun.jersey.core.impl.provider.entity.ReaderProvider
02-18 16:07:39.272: W/dalvikvm(8460): threadid=16: thread exiting with uncaught exception (group=0x41ed2930)
02-18 16:07:39.272: E/AndroidRuntime(8460): FATAL EXCEPTION: Thread-764
02-18 16:07:39.272: E/AndroidRuntime(8460): com.sun.jersey.api.client.ClientHandlerException: A message body reader for Java class java.util.List, and Java type java.util.List<xx.xxxx.xx.xx.xxxx.xxx.MessdatenPv>, and MIME media type application/xml was not found
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:549)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.sun.jersey.api.client.ClientResponse.getEntity(ClientResponse.java:523)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.sun.jersey.api.client.WebResource.handle(WebResource.java:686)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.sun.jersey.api.client.WebResource.access$300(WebResource.java:74)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:508)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.example.monitor.thread.Login.verifyLogin(Login.java:74)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at com.example.monitor.activity.LoginActivity$3.run(LoginActivity.java:152)
02-18 16:07:39.272: E/AndroidRuntime(8460):     at java.lang.Thread.run(Thread.java:856)

Here is the Client:

ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource webResource = client.resource(getBaseURI());
List<MessdatenPv> listMessdatenPv = webResource.path("test").path("helloworld/getMessdatenPv").accept(MediaType.APPLICATION_XML).get(new GenericType<List<MessdatenPv>>() {});

And the Webservice:

@GET
@Path("/getMessdatenPv")
@Produces(MediaType.APPLICATION_XML)
public List<MessdatenPvCommon> getMessdatenPv() throws Exception {
            List<MessdatenPvCommon> messdatenPvList = getMessdaten();
            return messdatenPvList;
        }

The ServiceFinder$ServiceIteratorProvider

package com.example.monitor.activity;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;

import android.util.Log;

import com.sun.jersey.spi.service.ServiceFinder.ServiceIteratorProvider;

public class AndroidServiceIteratorProvider<T> extends ServiceIteratorProvider<T>
{

  private static final String TAG = AndroidServiceIteratorProvider.class.getSimpleName();

  private static final String MESSAGE = "Unable to load provider";

  private static final HashMap<String, String[]> SERVICES = new HashMap<String, String[]>();

  private static final String[] com_sun_jersey_spi_HeaderDelegateProvider = {"com.sun.jersey.core.impl.provider.header.MediaTypeProvider",
                                                                             "com.sun.jersey.core.impl.provider.header.StringProvider"};

  private static final String[] com_sun_jersey_spi_inject_InjectableProvider = {};

  private static final String[] javax_ws_rs_ext_MessageBodyReader = {"com.sun.jersey.core.impl.provider.entity.StringProvider",
                                                                     "com.sun.jersey.core.impl.provider.entity.ReaderProvider"};

  private static final String[] javax_ws_rs_ext_MessageBodyWriter = {"com.sun.jersey.core.impl.provider.entity.StringProvider",
                                                                     "com.sun.jersey.core.impl.provider.entity.ReaderProvider"};

  static
  {
    SERVICES.put("com.sun.jersey.spi.HeaderDelegateProvider", com_sun_jersey_spi_HeaderDelegateProvider);
    SERVICES.put("com.sun.jersey.spi.inject.InjectableProvider", com_sun_jersey_spi_inject_InjectableProvider);
    SERVICES.put("javax.ws.rs.ext.MessageBodyReader", javax_ws_rs_ext_MessageBodyReader);
    SERVICES.put("javax.ws.rs.ext.MessageBodyWriter", javax_ws_rs_ext_MessageBodyWriter);
    SERVICES.put("jersey-client-components", new String[] {});
    SERVICES.put("com.sun.jersey.client.proxy.ViewProxyProvider", new String[] {});
  }


  @SuppressWarnings("unchecked")
  @Override
  public Iterator<Class<T>> createClassIterator(Class<T> service, String serviceName, ClassLoader loader, boolean ignoreOnClassNotFound)
  {

    String[] classesNames = SERVICES.get(serviceName);
    int length = classesNames.length;
    ArrayList<Class<T>> classes = new ArrayList<Class<T>>(length);
    for (int i = 0; i < length; i++)
    {
      try
      {
        classes.add((Class<T>) Class.forName(classesNames[i]));
      }
      catch (ClassNotFoundException e)
      {
        Log.v(TAG, MESSAGE, e);
      }
    }
    return classes.iterator();
  }


  @Override
  public Iterator<T> createIterator(Class<T> service, String serviceName, ClassLoader loader, boolean ignoreOnClassNotFound)
  {

    String[] classesNames = SERVICES.get(serviceName);
    int length = classesNames.length;
    ArrayList<T> classes = new ArrayList<T>(length);
    for (int i = 0; i < length; i++)
    {
      try
      {
        classes.add(service.cast(Class.forName(classesNames[i]).newInstance()));
      }
      catch (IllegalAccessException e)
      {
        Log.v(TAG, MESSAGE, e);
      }
      catch (InstantiationException e)
      {
        Log.v(TAG, MESSAGE, e);
      }
      catch (ClassNotFoundException e)
      {
        Log.v(TAG, MESSAGE, e);
      }
    }

    return classes.iterator();
  }
}

This trouble occurs only in eclipse adt, in eclipse kepler it works..

Can anybody help me on this.

Berger
  • 25
  • 5

1 Answers1

1

JAXB is not included in Android by default. Take a look at the answers of this question. I would suggest you the same as these answers: to use either JSON (Jackson) instead of XML, or use a different XML parsing (Java DOM, XPath, SimpleXML) / binding (XStream) library in your client.

Community
  • 1
  • 1
Daniel Szalay
  • 4,041
  • 12
  • 57
  • 103