2013-10-07 71 views
2

這是我從安卓的Java類型,類java.util.ArrayList和MIME媒體類型,應用/ XML的消息體的作家,沒有被發現

RESTClient rs = new RESTClient(WebServicePatterns.SERVICES_URL); 
    rs.addParam("role_id", "6"); 
    try 
    { 
    rs.sendParams_receiveText();// Call WebService 
    } 

    rs.getResponse() 

這裏調用的代碼是我RESTClient實現的方法。

public void sendParams_receiveText() throws Exception 
{ 
    http_client = new DefaultHttpClient(); 
    http_post = new HttpPost(uri); 
    http_post.setEntity(new UrlEncodedFormEntity(params)); 
    http_response = http_client.execute(http_post); 
    http_entity = http_response.getEntity(); 

    response = EntityUtils.toString(http_entity); 
} 

這裏是我的服務器端Web服務代碼

@Produces("application/xml") 
@Path("Services") 
@Singleton 
public class Services_Service 
{ 
    public Services_Service() 
    { 

    } 

@POST 
@Path("getServices") 
public List<ServicesBean> getServices(@FormParam("role_id") String role_id) 
{ 

    Services_DB db = new Services_DB(); 
    List<ServicesBean> services_data = db.myServices(role_id); 
    return services_data; 
} 

} 

這裏是myServices代碼

......... 
private TreeMap<Integer, ServicesBean> servicesData = new TreeMap<Integer, ServicesBean>(); 
......... 

public List<ServicesBean> myServices(String role_id) 
{ 

    List<ServicesBean> entireList = new ArrayList<ServicesBean>(); 
    ServicesBean bean = new ServicesBean(); 

    try 
    { 

     sql = "SELECT A,B,C from TESTTable where ......."; 

     rs = stmt.executeQuery(sql); 

     if (rs != null && rs.next()) 
     { 
      do 
      { 
       bean = new ServicesBean(); 

       bean.setService_id(rs.getString("A")); 
       bean.setService_name(rs.getString("B")); 
       bean.setService_short_name(rs.getString("C")); 

       int id = servicesData.size(); 
       servicesData.put(id, bean); 

      } while (rs.next()); 
     } 

     entireList.addAll(servicesData.values()); 
    } 


    return entireList; 

的問題是我得到這樣的錯誤。

7 Oct, 2013 5:08:05 PM com.sun.jersey.spi.container.ContainerResponse write 
SEVERE: A message body writer for Java type, class java.util.ArrayList, and MIME media type, application/xml, was not found 
7 Oct, 2013 5:08:05 PM com.sun.jersey.server.impl.application.WebApplicationImpl onException 
SEVERE: Internal server error 
javax.ws.rs.WebApplicationException 
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:241) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:724) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:647) 
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:638) 
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:309) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:425) 
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:590) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261) 
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844) 
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581) 
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447) 
    at java.lang.Thread.run(Thread.java:619) 

可能有人請幫助我。

回答

1

錯誤消息告訴你,澤西不知道如何將ServiceBeanList對象轉化爲有效的XML。

你缺少的是像JAXB這樣的對象編組器,它爲你完成這項工作。

看看this tutorial的第6章。這很好解釋。

2

消息正文寫入器,用於Java類的java.util.ArrayList,和Java類型的java.util.ArrayList,和MIME媒體類型application/XML未找到
問題是由在類的開頭添加XmlRootElement將解決(請參閱jaxb文檔) (需要服務器類路徑中的jaxb-impl.jar和jaxb-api.jar)

import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement

0

那麼排序和簡單的答案是。你不能直接將列表轉換爲xml。您需要將列表放入類中意味着制定您的用戶定義的數據類型並將其放入列表中。

你可以標記類作爲@XmlRootElement

那麼這將是轉換爲XML。

相關問題