EJB NullPointerException JAX-RS REST WebService

Dieses Thema EJB NullPointerException JAX-RS REST WebService im Forum "Application Tier" wurde erstellt von Kokscola, 7. Feb. 2014.

Thema: EJB NullPointerException JAX-RS REST WebService Hi, ich habe ein REST-WebService im Weblogic mit Jersey nach dem Tutorial erstellt: Develop an Apache HttpClient...

  1. Kokscola
    Kokscola Neues Mitglied
    Hi,

    ich habe ein REST-WebService im Weblogic mit Jersey nach dem Tutorial erstellt:
    Develop an Apache HttpClient client for Android to a JAX-RS web service

    Nun möchte ich in meine Resource Klasse eine Bean injizieren. Leider bekomme ich aber eine NullPointerException, wenn ich eine Methode dieser Bean aufrufen möchte. Weill die "@Inject private MessdatenShowBean messdaten;" null ist...

    Resource Klasse:
    Code (Java):

    package test;

    import java.math.BigDecimal;

    import javax.enterprise.context.RequestScoped;
    import javax.inject.Inject;
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.Produces;

    import xx.xxxx.xxx.xxx.xxx.MessdatenShowBean;

    @RequestScoped
    @Path("/helloworld")
    public class Resource {

        @Inject
        private MessdatenShowBean messdaten;

        @GET
        @Path("/getMessdatenShow")
        public BigDecimal getMessdaten() {     
            return messdaten.getLastValues("XXXXX").getAusNum();
        }

        @GET
        @Produces("text/html")
        @Path("/html")
        public String getHTMLMessage() {

            return "<html> " + "<title>" + "TEST CONNECTION JAX-RS" + "</title>" + "<body><center><h1>" + "TEST CONNECTION JAX-RS" + "</body></h1></center>" + "</html>";

        }
    }
     
    Die "getMessdaten()"-Methode liefert ein NullPointerException. Die "getHTMLMessage"-Methode gibt den angegebenen String aus.

    MessdatenShowBean:
    Code (Java):

    /**
     *
     */

    package xx.xxxx.xxx.xxx.xxx;

    import ....

    @Remote(MessdatenShow.class)
    @TransactionManagement(value = TransactionManagementType.BEAN)
    @Stateless(name = "MessdatenShowBean", mappedName = "xx.xxxx.xxx.xxx.xxx.MessdatenShowBean")
    @Local
    public class MessdatenShowBean implements MessdatenShow
    {
      @PersistenceContext(unitName = "xx.xxxx.xxx.xxx.xxxx")
      private EntityManager em;


      @Resource
      private SessionContext ctx;

     
      private Logger logger;
      private LogMessageBuilder<MessdatenShowBean> lmb;


      /**
       * Default constructor.
       */

      public MessdatenShowBean()
      {
      }


      @PostConstruct
      private void initialize()
      {
        this.logger = new LoggerFactory().getLoggerInstance();
        this.lmb = new LogMessageBuilder<>(this, this.ctx);
        this.logger.debug("MessdatenShowBean.@PostConstruct"); //$NON-NLS-1$
      }

    ....

     
    Fehlermeldung im Server, wenn ich die getMessdaten()-Methode aufrufe:

    Code (Java):
    <07.02.2014 15:05 Uhr MEZ> <Error> <HTTP> <WL-101020> <[ServletContext@14140392[app:xx.xxxx.xxx.xxxEAR module:test-app path:null spec-version:3.0]] Servlet failed with an Exception
    java.lang.NullPointerException
        at test.Resource.getMessdaten(Resource.java:23)
        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:302)
        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:1511)
        at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1442)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1391)
        at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1381)
        at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:538)
        at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:716)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:844)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:280)
        at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:254)
        at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:136)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:341)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:238)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3363)
        at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3333)
        at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
        at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
        at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
        at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2220)
        at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2146)
        at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2124)
        at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1564)
        at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
        at weblogic.work.ExecuteThread.execute(ExecuteThread.java:295)
        at weblogic.work.ExecuteThread.run(ExecuteThread.java:254)
    >
     
    Kann mir jemand ein Tipp geben warum ich die Bean nicht injiziert bekomme?

    Danke.
     
    Zuletzt bearbeitet: 7. Feb. 2014
  2. Vielleicht hilft dir das kostenlose Training weiter --> (hier klicken)