简体   繁体   中英

Problems with RESTful return types

I get this error while trying to call a RESTful webservice method:

MessageBodyWriter not found for media type=text/xml, type=class [Ljava.lang.String;, genericType=class [Ljava.lang.String; .

Here is the way I call the method from my code :

 try{
         PINClient pin=new PINClient();

         String[] resp = pin.tramo(String[].class, "1");

             out.println("pin"+resp[1]);

         }catch(Exception e){
             out.println(e);
         }

The answer is supposed to come as a text/xml, as I specified in the RESTful webservice, but I don't know what is causing this problem. The webservice method:

@GET
    @Produces("text/xml")
    public String[] tramo(@QueryParam("tramo") String tramo) throws SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException {
        String[] pin=new String[300];
        Class.forName("oracle.jdbc.OracleDriver").newInstance();
        Connection conexion = DriverManager.getConnection("jdbc:oracle:thin:@172.17.56.133:1521:TRACK", "oc","oc");
        Statement stmt=conexion.createStatement();
        ResultSet rs1=stmt.executeQuery("select IDT.ROWID, IDT.ID_ID, IDT.ID_PST_ID, IDT.ID_UM_ID,IDT.ID_POS, IDT.ID_PULSOS, IDT.ID_LANZAR, TEL_FISKERNEL.TEL_COLOR_EXT, TEL_FISKERNEL.TEL_SEC_MONT,TEL_FISKERNEL.TEL_PRS_FAM,TEL_FISKERNEL.TEL_SORTENES_FAM from IDT,TEL_FISKERNEL where IDT.ID_UM_ID =  TEL_FISKERNEL.TEL_PIN and ID_PST_ID="+tramo+" order by ID_POS" );
        int i=0;
        while(rs1.next()){
            pin[i]=rs1.getString("ID_UM_ID");
            i++;           
        }
        rs1.close();
        stmt.close();
        conexion.close();


        return pin;


    }

And the webservice client:

  public <T> T tramo(Class<T> responseType, String tramo) throws ClientErrorException {
    WebTarget resource = webTarget;
    if (tramo != null) {
        resource = resource.queryParam("tramo", tramo);
    }
    return resource.request(javax.ws.rs.core.MediaType.TEXT_XML).get(responseType);
}

Retruning of Array,List is not possible directly. You can create a class with array and list as member and can return object of that class.

NB: REST cannot return Array or List

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM