Note that there are some explanatory texts on larger screens.

plurals
  1. POWriting a REST webservice with @XmlRootElement
    primarykey
    data
    text
    <p>I'm trying to write a REST webservice in Java (using Netbeans, Glassfish and Jersey).</p> <p>I've written a small app and it works. But then I tried the following:</p> <pre><code>package service; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.ws.rs.*; import javax.ws.rs.core.Response; import converter.FlyedpConverter; import entities.FlysCombination; @Path("/getdates") public class FlyedpResource { @GET @Path("{date}") @Produces({"application/json"}) public Response get(@PathParam("date") String date) throws IOException { FlysCombination comb = new FlysCombination(); FlysCombination x = FlysCombination.instance(); comb = x.getcomb(date); System.out.println(comb.toString()); if (comb == null) { return Response.status(Response.Status.NOT_FOUND).build(); } return Response.ok(comb).build(); } } </code></pre> <p>My class <code>FlysCombination</code>:</p> <pre><code>package entities; import converter.FlyedpConverter; import java.util.ArrayList; public class FlysCombination { public FlysCombination() {} public static FlysCombination flycomb = null; public static FlysCombination instance() { if (flycomb == null) { flycomb = new FlysCombination(); } return flycomb; } private String session; @SuppressWarnings("rawtypes") private ArrayList combinations = new ArrayList(); public FlysCombination(String session,ArrayList combinations) { this.session=session; this.combinations=combinations; } public ArrayList getcombinations() { return combinations; } public void setcombinations(ArrayList goingthere) { this.combinations = goingthere; } public String getsession() { return session; } public void setsession(String session) { this.session = session; } public FlysCombination getcomb(String a) { FlyedpConverter fly = new FlyedpConverter (a); combinations.add(fly); session="sdjkbsqdjhf"; FlysCombination flycomb = new FlysCombination (session,combinations); return(flycomb); } } </code></pre> <p>And <code>FlyedpConverter</code>:</p> <pre><code>package converter; public class FlyedpConverter { private String keydate; public FlyedpConverter(String keydate) { this.keydate=keydate; } public String getkeydate() { return keydate; } public void setkeydate(String keydate) { this.keydate = keydate; } } </code></pre> <p>I'm getting the following error:</p> <pre><code>Status: 500 (Internal Server Error) javax.ws.rs.WebApplicationException at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:268) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1029) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:941) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:932) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:384) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:451) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:632) at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97) at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:165) at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791) at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693) at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954) at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170) at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102) at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88) at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76) at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53) at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57) at com.sun.grizzly.ContextTask.run(ContextTask.java:69) at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330) at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309) at java.lang.Thread.run(Thread.java:680) </code></pre> <p>I think that the problem is in the <code>@XmlRootElement</code>, I don't know where write it... When I debug, the com variable contains a result, so the problem is in <code>return Response.ok(comb).build();</code> </p> <p>Can someone help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload