0

Web サービスで問題が発生しています --- Web サービスから映画リストを取得しようとしていますが、常にこの厄介なエラーが発生します。

ここに私のモデルがあります:

package de.hawhof.dm.kino.model;

import java.io.Serializable;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

@Entity
@XmlRootElement(name="movie")
public class Movie implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    int movieid;
    String name;
    String releaseDate;
    @Lob
    String critic;
    String runtime;
    @Lob
    String synopsis;
    String posterPath;
    String thumbnail;

    // user movie comment rating
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "movie")
    List<User_Movie_CR> userMovieCR;

    // cinema movie
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "movie")
    List<Cinema_Movie> cinemaMovie;

    // user film cinema table
    @OneToMany(mappedBy = "movie")
    Set<Cinema_Movie_User> cinema_movie_user;

    public Movie() {

    }

    public Movie(String name, String releaseDate, String critic,
            String runtime, String synopsis, String posterPath, String thumbnail) {
        this.name = name;
        this.releaseDate = releaseDate;
        this.critic = critic;
        this.runtime = runtime;
        this.synopsis = synopsis;
        this.posterPath = posterPath;
        this.thumbnail = thumbnail;
    }

//   toString
    public String toString() {
        return "Movie [name=" + name + ", releaseDate=" + releaseDate
                + ", critic=" + critic + ", runtime=" + runtime + ", synopsis="
                + synopsis + ", posterPath=" + posterPath + "]";
    }

    // setter and getter

}

ダオとファサードもありますが、元気に動いています!

ここに私のサービスがあります:

package de.hawhof.dm.kino.ws;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;

import de.hawhof.dm.kino.facade.MovieFacade;
import de.hawhof.dm.kino.model.*;

@Path("/movies")
public class MoviesResource {

    @Context
    UriInfo uriInfo;
    @Context
    Request request;
    MovieFacade movieFacade = new MovieFacade();

    @GET
    @Path("xml")
    @Produces(MediaType.TEXT_XML)
    public List<Movie> getMoviesBrowser() {
        List<Movie> movies = new ArrayList<Movie>();
        movies.addAll(movieFacade.listAll());


        return movies;
    }

    @GET
    @Path("XMLForApp")
    @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
    public List<Movie> getMovies() {
        List<Movie> movies = new ArrayList<Movie>();
        movies.addAll(movieFacade.listAll());
        return movies;
    }

    @GET
    @Path("onemovie")
    public Movie getMovie() {
        return new Movie("TEST!!!", "", "", "", "", "", "");
    }

    @GET
    @Path("count")
    @Produces(MediaType.TEXT_PLAIN)
    public String getCount() {
        int count = movieFacade.listAll().size();
        return String.valueOf(count);
    }

    @Path("{movie}")
    public MovieResource getMovie(@PathParam("movie") int movieid) {
        return new MovieResource(uriInfo, request, movieid);
    }

}

メソッド「onemovie」と「count」は正常に機能し、ブラウザにxmlが表示されますが、「XMLForApp」を呼び出すと、サーバーが例外をスローします。

私のクライアントはここにいます:

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.core.MediaType;


public class MovieWSClient {

    Client client;
    String movieList;

    public MovieWSClient() {
        client = ClientBuilder.newClient().register(getClass());
        movieList = client.target("http://localhost:8080/kino").path("/rest/movies/XMLForApp").request(MediaType.APPLICATION_JSON).get(String.class);
    }

    public String getMovieList() {
        return movieList;
    }
}

例外は次のとおりです。

SEVERE: Servlet.service() for servlet [Hello Servlet] in context with path [/kino] threw exception [An exception occurred processing JSP page /pages/public/hello.jsp at line 20

Stacktrace:] with root cause
javax.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
    at org.glassfish.jersey.client.JerseyInvocation.convertToException(JerseyInvocation.java:904)
    at org.glassfish.jersey.client.JerseyInvocation.translate(JerseyInvocation.java:749)
    at org.glassfish.jersey.client.JerseyInvocation.access$500(JerseyInvocation.java:88)
    at org.glassfish.jersey.client.JerseyInvocation$2.call(JerseyInvocation.java:650)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:228)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:421)
    at org.glassfish.jersey.client.JerseyInvocation.invoke(JerseyInvocation.java:646)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.method(JerseyInvocation.java:375)
    at org.glassfish.jersey.client.JerseyInvocation$Builder.get(JerseyInvocation.java:275)
    at de.hawhof.dm.kino.ws.MovieWSClient.<init>(MovieWSClient.java:16)
    at org.apache.jsp.pages.public_.hello_jsp._jspService(hello_jsp.java:77)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:419)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:471)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:402)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:329)
    at de.hawhof.dm.kino.servlet.HelloServlet.doGet(HelloServlet.java:21)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
4

2 に答える 2

0

@RequestScopedREST サービスに追加してみてください。

于 2013-07-25T05:31:35.687 に答える