Sto utilizzando Apache CXF per creare un'applicazione semplice e riposante. Ho una classe client che pubblica un oggetto JSON sul server e il server restituisce un JSON dopo alcune manipolazioni. ma quando eseguo il codice ottengoNon è stato trovato alcun writer del corpo del messaggio: JSON: Apache CXF: RestFul Webservices
"org.apache.cxf.interceptor.Fault: .No message body writer has been found for class:
class org.codehaus.jettison.json.JSONObject, ContentType : application/json."
Il mio codice cliente:
public class Client {
public static void main(String[] args) {
try{
URI uri = new URI("http://localhost:8022/RestDemo");
WebClient client = WebClient.create(uri);
String ret = client.path("rest").path("server").path("welcome").accept(MediaType.TEXT_PLAIN).get(String.class);
System.out.println(ret);
JSONObject json = new JSONObject();
json.put("name", "ronaldo");
json = client.path("rest").path("server").path("op").type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(json, JSONObject.class);
System.out.println(json);
System.out.println(json.has("reverse")?json.getString("reverse"):"dont have");
}catch(Exception e){
System.out.println("e"+e.getLocalizedMessage());
e.printStackTrace();
}
}
}
prega di aiuto.
Il problema è che ogni volta che eseguo il codice ottengo l'eccezione "No body writer per org.codehaus.jettison.json". Non sono un programmatore esperto e questa è la mia prima volta con servizi rilassanti. Cxf supporta l'oggetto json in un modo che ho usato nel mio codice? Ho usato jersey framework che ha permesso questo tipo di codici senza errori e inoltre non ho menzionato alcun provider nel mio web.xml. Si prega di notare che preferirei una soluzione non primavera. – Sikorski