As the title already status I'm running an Java RS Rest API. The GET method that is called successfully returns an object with the correct data. However, after returning the value something goes wrong resulting in a 500 page displayed in the browser.
The Get method looks like this:
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Verplaatsing> getAll(@QueryParam("start") String sD, @QueryParam("end") String eD, @QueryParam("auth") String authCode) {
/* First check the auth code */
/* First check the auth code */
if (authCode == null || !authCode.equals(service.getAuthcode(rightAll))) {
throw new WebApplicationException("Invalid or no auth key provided");
}
List<Verplaatsing> verplaatsing = new ArrayList<>();
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date start = dateFormat.parse(sD);
Date end = dateFormat.parse(eD);
verplaatsing = service.getAllVerplaatsing(start, end);
} catch (Exception ex) {
throw new WebApplicationException(Response.Status.EXPECTATION_FAILED);
}
return verplaatsing;
}
The Verplaatsing class returned by the REST service looks like this:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "verplaatsing")
@Entity (name = "VERPLAATSING")
@IdClass(VerplaatsingId.class)
public class Verplaatsing implements Serializable
{
@ManyToOne @Id
private Registratiekast registratiekast;
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
@Id
private Date verplaatsingDatum;
private double positie;
private double snelheid;
private String edge;
private String lane;
protected Verplaatsing()
{
}
public Verplaatsing(Registratiekast registratiekast, Date date, double positie, double snelheid, String edge, String lane)`enter code here`
{
this.registratiekast = registratiekast;
this.verplaatsingDatum = date;
this.positie = positie;
this.snelheid = snelheid;
this.edge = edge;
this.lane = lane;
}
public Date getVerplaatsingDatum()
{
return verplaatsingDatum;
}
public String getEdge()
{
return edge;
}
public String getLane()
{
return lane;
}
public double getPositie()
{
return positie;
}
public Registratiekast getRegistratiekast()
{
return registratiekast;
}
public double getSnelheid()
{
return snelheid;
}
@Override
public String toString() {
return "verplaatsing [registratiekast=" + this.registratiekast + ", date=" + this.verplaatsingDatum + ", positie="
+ this.positie + ", snelheid=" + this.snelheid + ", edge=" + this.edge + "]";
}
}
The weird thing is that there are no log items after a failed GET request. Which makes debugging this issue near impossible. The one major change I made to the code is moving the Verplaatsing class to another .jar. However, I can't imagine that is causing this problem.
Edit:
The entire WebService code:
@Path("verplaatsing")
@Stateless
public class VerplaastingREST {
private static String rightAll = "all";
private static String rightSingle = "single";
@Inject
VerplaatsingService service;
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Verplaatsing> getAll(@QueryParam("start") String sD, @QueryParam("end") String eD, @QueryParam("auth") String authCode) {
/* First check the auth code */
/* First check the auth code */
if (authCode == null || !authCode.equals(service.getAuthcode(rightAll))) {
throw new WebApplicationException("Invalid or no auth key provided");
}
List<Verplaatsing> verplaatsing = new ArrayList<>();
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date start = dateFormat.parse(sD);
Date end = dateFormat.parse(eD);
verplaatsing = service.getAllVerplaatsing(start, end);
} catch (Exception ex) {
throw new WebApplicationException(Response.Status.EXPECTATION_FAILED);
}
return verplaatsing;
}
@GET
@Path("{text}")
@Produces(MediaType.APPLICATION_JSON)
public List<Verplaatsing> getVerplaatsingen(@PathParam("text") String id, @QueryParam("start") String sD, @QueryParam("end") String eD, @QueryParam("auth") String authCode) {
/* First check the auth code */
if (authCode == null || (!authCode.equals(service.getAuthcode(rightAll)) && !authCode.equals(service.getAuthcode(rightSingle)))) {
throw new WebApplicationException("Invalid or no auth key provided");
}
List<Verplaatsing> verplaatsing = new ArrayList<>();
try {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
Date start = dateFormat.parse(sD);
Date end = dateFormat.parse(eD);
verplaatsing = service.getAllVerplaatsing(id ,start, end);
} catch (ParseException ex) {
throw new WebApplicationException(Response.Status.EXPECTATION_FAILED);
}
return verplaatsing;
}
}
glassfish/domains/{yourDomain}/logs
. My best guess at the error is the parsing of the JSON returned by the web service in your client code. How are you transforming theVerplaatsing
objects into JSON?