Reputation: 17
I got following problem. Iam coding a Restful Application with java and tomcat. Sofar this works fine. For example :
@GET
@Path("/String/")
@Produces(MediaType.APPLICATION_JSON)
public String getText()
{
String data = dothat();
return data;
}
(dothat(); connects to a java server, gets a string and returns it). When i call this mthod in my browser i CAN see the returned string.
However when i get a littlebit more complex and using a own class in a list like:
@GET
@Path("/test/")
@Produces(MediaType.APPLICATION_XML)
static public Response test3()
{
List<GpioPin> list = new ArrayList<GpioPin>();
GpioPin one = new GpioPin(0, "HIGH", "GPIO-5");
GpioPin two = new GpioPin(1, "LOW", "GPIO-1");
list.add(one);
list.add(two);
GenericEntity<List<GpioPin>> result = new GenericEntity<List<GpioPin>>(list) {
};
return Response.status(Status.OK).entity(result).build();
}
I get a Error 500 code returned.
Myclass GpioPin:
@XmlRootElement
public class GpioPin implements Serializable
{
/**
*
*/
private static final long serialVersionUID = -7583074316192202903L;
private int boardPosition;
private String gpioStatus;
private String gpioPort;
public GpioPin(int pos,String pinstate,String gpioPo)
{
boardPosition=pos;
gpioStatus=pinstate;
gpioPort=gpioPo;
}
public int getBoardPosition() {
return boardPosition;
}
public void setBoardPosition(int boardPosition) {
this.boardPosition = boardPosition;
}
public String getGpioStatus() {
return gpioStatus;
}
public void setGpioStatus(String gpioStatus) {
this.gpioStatus = gpioStatus;
}
public void setGpioPort(String gpioPort) {
this.gpioPort = gpioPort;
}
public String getGpioPort() {
return gpioPort;
}
}
the strangest part about this: I get no error message... neither in the brwoserimg below nor in any logs createt by Tomcat.
After reading several threads here about logging in Tomcat i managed to swap logging to log4j. But also log4j on debug level does not tell me anything about an error.
I cant resolve this problem. Does anybody has an idea?
Upvotes: 0
Views: 548
Reputation: 1588
You definitely need to get your logging corrected because that will give you clues as to what the problem is.
I'll take a shot in the dark here and say that you need to remove the "static" keyword from the test3() method. So it would look like this:
@GET
@Path("/test/")
@Produces(MediaType.APPLICATION_XML)
public Response test3()
{
List<GpioPin> list = new ArrayList<GpioPin>();
GpioPin one = new GpioPin(0, "HIGH", "GPIO-5");
GpioPin two = new GpioPin(1, "LOW", "GPIO-1");
list.add(one);
list.add(two);
GenericEntity<List<GpioPin>> result = new GenericEntity<List<GpioPin>>(list) {
};
return Response.status(Status.OK).entity(result).build();
}
Upvotes: 1