500er => com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException

Andyx1975

Mitglied
Hallo,

ich bin ziemlich neu im Bereich Webprogrammierung und ich habe ein Problem mit Restful bei dem ich nicht mehr weiter weiß und keine Lösung finde. Ich bekomme den folgenden Fehler der durch die rot markierte Zeile verursacht wird:

@GET
@Produces(MediaType.APPLICATION_XML)
@Path("{id}")
public DEmail read(@PathParam("id") long id) {
return em.find(DEmail.class, id);
}



Java:
Aug 16, 2011 11:07:17 AM com.sun.jersey.api.core.WebAppResourceConfig init
Information: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
Aug 16, 2011 11:07:18 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Information: Root resource classes found:
  class uds.web.admin.server.EmailService
Aug 16, 2011 11:07:18 AM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Information: Provider classes found:
  class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
  class org.codehaus.jackson.jaxrs.JacksonJsonProvider
  class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
  class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
Aug 16, 2011 11:07:18 AM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
Information: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
Aug 16, 2011 11:07:37 AM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
Schwerwiegend: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
java.lang.NullPointerException
	at uds.web.admin.server.EmailService.read(EmailService.java:53)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:324)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)


Die Klasse DEmail sieht wie folgt aus:
Java:
package uds.web.admin.server;

import java.io.Serializable;
import java.lang.Boolean;
import java.lang.Integer;
import java.lang.String;
import java.util.Date;

import javax.persistence.*;
import static javax.persistence.GenerationType.SEQUENCE;
import static javax.persistence.TemporalType.TIMESTAMP;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Entity implementation class for Entity: DEmail
 *
 */
@Entity
@XmlRootElement
@Table(name = "email_sended")
@NamedQuery(name = "findEmails", query = "SELECT e FROM DEmail e")
public class DEmail implements Serializable {

	
	@Id
	@GeneratedValue( strategy = SEQUENCE )
	@Column(columnDefinition="SERIAL")
    private Integer email_id;
	
	@Column
	private String ToRecipients;
	
	@Column
	private String CcRecipients;
	
	@Column
	private String BccRecipients;
	
	@Column
	private String headline;
	
	@Column(columnDefinition="TEXT")
	private String email_text;
	
	@Column
	private String email_type;
	
	@Column
	private Boolean selfCopy;
	
	@Column
	private String creator;
	
	@Column
	@Temporal( TIMESTAMP )
    private Date creations_date;
	
	private static final long serialVersionUID = 1L;
	
	
	
	
	

	public DEmail() {
		super();
	}   
	public Integer getEmail_id() {
		return this.email_id;
	}

	public void setEmail_id(Integer email_id) {
		this.email_id = email_id;
	}   
	public String getToRecipients() {
		return this.ToRecipients;
	}

	public void setToRecipients(String ToRecipients) {
		this.ToRecipients = ToRecipients;
	}   
	public String getCcRecipients() {
		return this.CcRecipients;
	}

	public void setCcRecipients(String CcRecipients) {
		this.CcRecipients = CcRecipients;
	}   
	public String getBccRecipients() {
		return this.BccRecipients;
	}

	public void setBccRecipients(String BccRecipients) {
		this.BccRecipients = BccRecipients;
	}   
	public String getHeadline() {
		return this.headline;
	}

	public void setHeadline(String headline) {
		this.headline = headline;
	}   
	public String getText() {
		return this.email_text;
	}

	public void setText(String text) {
		this.email_text = text;
	}   
	public String getEmail_type() {
		return this.email_type;
	}

	public void setEmail_type(String email_type) {
		this.email_type = email_type;
	}   
	public Boolean getSelfCopy() {
		return this.selfCopy;
	}

	public void setSelfCopy(Boolean selfCopy) {
		this.selfCopy = selfCopy;
	}   
	public String getCreator() {
		return this.creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}   
	public Date getCreations_date() {
		return this.creations_date;
	}

	public void setCreations_date(Date creations_date) {
		this.creations_date = creations_date;
	}
   
}


Meine Providerklasse sieht wie folgt aus:
Java:
package uds.web.admin.server;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


// http://localhost:8888/rest/emails/1

/**
 * Session Bean implementation class EmailService
 */
@Stateless
@LocalBean
@Path("/emails")
public class EmailService {

    /**
     * Default constructor. 
     */
    public EmailService() {

    }
    
    
    @PersistenceContext(unitName="EmailService", type=PersistenceContextType.TRANSACTION)
    EntityManager em;

    @POST
    @Consumes(MediaType.APPLICATION_XML)
    public void create(DEmail email) {
        em.persist(email);
    }
    
    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("{id}")
    public DEmail read(@PathParam("id") long id) {
        return em.find(DEmail.class, id);
    }
    
    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("readAll")
    public List<DEmail> readAll(){

        Query  query = em.createNamedQuery("findEmails");
        List<DEmail> email = query.getResultList();

        System.out.println("email : "+email);

        return email;

     }
    
   
    

}


Meine web.xml:
Java:
<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<!-- Default page to serve -->
	<welcome-file-list>
		<welcome-file>GWebAdmin.html</welcome-file>
	</welcome-file-list>
	<display-name>Emails</display-name>
	<servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <persistence-context-ref>
        <persistence-context-ref-name>persistence/em</persistence-context-ref-name>
        <persistence-unit-name>EmailService</persistence-unit-name>
    </persistence-context-ref>

</web-app>
 

genodeftest

Erfahrenes Mitglied
zum Zeitpunkt des Aufrufes von EmailManager.read() ist der EntityManager em nicht initialisiert. Warum weiß ich leider auch nicht.
 

Andyx1975

Mitglied
So jetzt habe ich meine ServiceKlasse angepasst....diese sieht jetzt wie folgt aus und ich bekomme den folgenden Fehler:

Java:
package uds.web.admin.server;

import java.util.List;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.Query;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;


// http://localhost:8888/rest/emails/1

/**
 * Session Bean implementation class EmailService
 */
@Stateless
@LocalBean
@Path("/emails")
public class EmailService {

    /**
     * Default constructor. 
     */
    public EmailService() {

    }
    
    
    @PersistenceContext(unitName="EmailService", type=PersistenceContextType.TRANSACTION)
    private static final String PERSISTENCE_UNIT_NAME = "WebAdmin";
    private static EntityManagerFactory factory; 
    

    @POST
    @Consumes(MediaType.APPLICATION_XML)
    public void create(DEmail email) {
        factory = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT_NAME );
        EntityManager em = factory.createEntityManager();
        em.persist(email);
    }
    
    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("{id}")
    public DEmail read(@PathParam("id") long id) {
        factory = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT_NAME );
        EntityManager em = factory.createEntityManager();
        return em.find(DEmail.class, id);
    }
    
    @GET
    @Produces(MediaType.APPLICATION_XML)
    @Path("readAll")
    public List<DEmail> readAll(){

        
        factory = Persistence.createEntityManagerFactory( PERSISTENCE_UNIT_NAME );
        EntityManager em = factory.createEntityManager();
        Query  query = em.createNamedQuery("findEmails");
        List<DEmail> email = query.getResultList();

        System.out.println("email : "+email);

        return email;

     }
    
   
    

}

Fehlermeldung:

Java:
Aug 16, 2011 4:57:46 PM com.sun.jersey.api.core.WebAppResourceConfig init
Information: Scanning for root resource and provider classes in the Web app resource paths:
  /WEB-INF/lib
  /WEB-INF/classes
Aug 16, 2011 4:57:47 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Information: Root resource classes found:
  class uds.web.admin.server.EmailService
Aug 16, 2011 4:57:47 PM com.sun.jersey.api.core.ScanningResourceConfig logClasses
Information: Provider classes found:
  class org.codehaus.jackson.jaxrs.JsonParseExceptionMapper
  class org.codehaus.jackson.jaxrs.JacksonJsonProvider
  class org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
  class org.codehaus.jackson.jaxrs.JsonMappingExceptionMapper
Aug 16, 2011 4:57:47 PM com.sun.jersey.server.impl.application.WebApplicationImpl _initiate
Information: Initiating Jersey application, version 'Jersey: 1.8 06/24/2011 12:17 PM'
Aug 16, 2011 4:58:08 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
Schwerwiegend: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container
javax.persistence.PersistenceException: No Persistence provider for EntityManager named WebAdmin
	at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
	at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source)
	at uds.web.admin.server.EmailService.read(EmailService.java:59)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:601)
	at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
	at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185)
	at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
	at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
	at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
	at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
	at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
	at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
	at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
	at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
	at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
	at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
	at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
	at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
	at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
	at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
	at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
	at org.mortbay.jetty.Server.handle(Server.java:324)
	at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
	at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)
	at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
	at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
	at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
	at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
	at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)


Persistance.xml:
Java:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="WebAdmin" transaction-type="RESOURCE_LOCAL">
		<class>uds.web.admin.server.DEmail</class>
		<class>uds.web.admin.server.DUploads</class>
		<properties>
			<property name="javax.persistence.jdbc.url" value="jdbc:postgresql:/<ip><port>/<dbname>"/>
			<property name="javax.persistence.jdbc.user" value="xxxxxxxxxxx"/>
			<property name="javax.persistence.jdbc.password" value="xxxxxxxxx/>
			<property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
		</properties>
	</persistence-unit>
</persistence>
 
Zuletzt bearbeitet: