Salve a tutti,
ho necessita di sviluppare un webservice con java ee rest.
Attualmente su java ee ho esperienza solo con ejb e webservice soap.
Vorrei che questo webservice ricevesse richieste http e rispondesse con messaggi json.
Per ora non mi sono chiari ancora alcuni aspetti, ma sono riuscito a realizzare un helloworld http, che ritornasse un text/html con scritto helloworld.
Ho quindi provato a farlo in Json, ma non ci sono saltato fuori
Vi chiedo di guidarmi e indicarmi dove sto sbagliando, per cercare di capire meglio, questa e' la resource nel WAR (WSResponse e' l'oggetto che vorrei serializzare).
Se invoco la pagina ottengo:codice:@Path("reports") @Stateless @Produces({"application/xml", "application/json"}) @Consumes({"application/xml", "application/json", "text/html"}) public class ReportResource { @Context private UriInfo context; /** Creates a new instance of ReportResource */ public ReportResource() { } /** * Retrieves representation of an instance of com.comunichiamo.rest.ReportResource * @return an instance of java.lang.String */ @GET public String getJson() { //TODO return proper representation object //throw new UnsupportedOperationException(); Gson gson = new Gson(); WSResponse ws = new WSResponse(); ws.setAnswer("hello world"); return gson.toJson(ws); } ...
Grazie mille, spero in una vostra risposta e consiglio per capire.HTTP Status 500 -
type Exception report
message
descriptionThe server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NoClassDefFoundError: com/google/gson/Gson
root cause
java.lang.NoClassDefFoundError: com/google/gson/Gson
root cause
java.lang.ClassNotFoundException: com.google.gson.Gson
note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1 logs.
A presto e ciao a tutti!


Rispondi quotando