Rest方法会在Glassfish中发送错误,并返回对象列表

时间:2019-05-05 22:17:51

标签: java rest web-services glassfish

我正在尝试使用其余的Web服务来获取扩展SportEvent的SportMatchEvent对象的列表

此rest方法位于ejb中。在我的测试中,如果我尝试使用rest方法返回一个可以工作的String对象,但是我需要返回SportMatchEvents对象的列表。

我的体系结构如下:

实现远程ejb接口的

ejb具有以下架构:

@Path("eventosdeportivos")
@Singleton
public class ConwSportEventArrayList extends CopyOnWriteArrayList<SportEvent> implements RemoteConwSportEventsService, Serializable {
.......


@Override
    @GET
    @Produces(value = {MediaType.APPLICATION_XML})
    @Path("/eventos")
    public Response restGetSportEventsAsList() {
        List<SportMatchEvent> sportMatchEventsList = new ArrayList<>();
        for(SportEvent sportEvent : this.getSportEventsAsList()){
            if(sportEvent instanceof SportMatchEvent){
                sportMatchEventsList.add((SportMatchEvent)sportEvent);
            }
        }
        return Response.status(Response.Status.OK).entity(sportMatchEventsList).build();

    }

}
@XmlRootElement
public class SportMatchEvent extends SportEvent{
.....
.....

public SportMatchEvent(Sports sport, Competitions competition,Date date,Date eventCutDate, Boolean inPlay, String homeTeamName, String awayTeamName ){

        super(sport, competition,date, eventCutDate, inPlay);
        this.homeTeamName =  StringUtils.stripAccents(homeTeamName).toUpperCase();
        this.awayTeamName = StringUtils.stripAccents(awayTeamName).toUpperCase();
        this.eventName = generateEventName(this.homeTeamName, this.awayTeamName);
        this.eventId = generateEventId();

    }

}
public abstract class SportEvent implements Serializable{
....
....
}

我从Glassfish中得到的调用rest方法的错误是:

HTTP Status 500 - Internal Server Error
type Exception report

messageInternal Server Error

descriptionThe server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: java.lang.ClassCastException: org.glassfish.jersey.message.internal.OutboundJaxrsResponse cannot be cast to java.io.Serializable
root cause

java.lang.ClassCastException: org.glassfish.jersey.message.internal.OutboundJaxrsResponse cannot be cast to java.io.Serializable

0 个答案:

没有答案