SRVE0777E: Exception thrown by application class

时间:2017-04-10 02:58:34

标签: rest jax-rs ibm-cloud

I have a JEE rest app for consume and build web service. When I use url of app in ibm bluemix I have an error in local server webSphere and also in Bluemix:

SRVE0777E: Exception thrown by application class

'tn.hunterViews.services.OfferService.afficherOffer:31'
java.lang.NullPointerException: 
at tn.hunterViews.services.OfferService.afficherOffer(OfferService.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethodAccessorImpl.java:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.ibm.ws.jaxrs20.server.LibertyJaxRsServerFactoryBean.performInvocation(LibertyJaxRsServerFactoryBean.java:674)
at [internal classes]

OffersService.java

package tn.hunterViews.services;

import java.util.List;

import javax.ejb.EJB;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import tn.hunterViews.business.OfferBusiness;
import tn.hunterViews.business.OfferBusinessRemote;
import tn.hunterViews.domain.Offer;

@Path("/Offers")
public class OfferService {

    @EJB 
    OfferBusinessRemote ofR;

    @GET
    @Path("")
    @Produces(MediaType.APPLICATION_JSON)
    public Response afficherOffer(){
        return Response.status(Status.OK).entity(ofR.getOffer()).build();
    }       
}

offersBuissness.java

package tn.hunterViews.business;

import java.util.List;

import javax.ejb.Stateless;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import tn.hunterViews.domain.Offer;
/**
 * Session Bean implementation class OfferBusiness
 */
@Stateless
public class OfferBusiness implements OfferBusinessRemote {

    @Override
    public List<Offer> getOffer() {

        Client cl = ClientBuilder.newClient();
        WebTarget target = cl.target("https://pihunterviewsdotnet.mybluemix.net/api");
        WebTarget off = target.path("offerApi");
        List<Offer> offers = off.request(MediaType.APPLICATION_JSON).get(new GenericType<List<Offer>>(){}) ;
        cl.close();
        return offers;
    }

    @Override
    public boolean createOffer(Offer offer) {
         Client cl = ClientBuilder.newClient();
            WebTarget target = cl.target("https://pihunterviewsdotnet.mybluemix.net/api");
        WebTarget off = target.path("offerApi");
        Response resp=target.request().post(Entity.entity(offer, MediaType.APPLICATION_JSON));

        if(resp.getStatus()!=201)
        return false;
        return true;
    }

    @Override
    public boolean updateOffer(int id, Offer offer) {
        if (id+""!=null && id!=0 && offer.getId()!=0)
        {
            Client cl = ClientBuilder.newClient();
             WebTarget target = cl.target("https://pihunterviewsdotnet.mybluemix.net/api/offerApi"+ id);
            target.request().build("PUT", Entity.entity(offer, MediaType.APPLICATION_JSON))
            .invoke();
            return true;
        }

        return false;
    }

    @Override
    public boolean deleteOffer(int id)  {
        if (id+""!=null && id!=0)
        {
        Client cl = ClientBuilder.newClient();
         WebTarget target = cl.target("https://pihunterviewsdotnet.mybluemix.net/api/offerApi"+ id);
        target.request().delete();
        return true;}
        return false;
    }    

    @Override
    public Offer findOfferById(int id) {
        Client cl = ClientBuilder.newClient();
        WebTarget baseUrl = cl.target("https://pihunterviewsdotnet.mybluemix.net/api/offerApi");
        WebTarget getPostURL=baseUrl.path(""+id);
        Response response = getPostURL.request(MediaType.APPLICATION_JSON).get();
        Offer offer=response.readEntity(Offer.class);
        response.close();
        cl.close();
        return offer;
    }       
}

Please help me with this problem. Thanks.

1 个答案:

答案 0 :(得分:0)

  

如果无法将@EJB注释解析为EJB,那么就可以   当服务器创建了一个实例时收到了一个失败   包含@EJB注释的类。因为那似乎不是   发生在你身上,相反,实例创建得很好   如果没有设置该字段,则服务器不会扫描您的   注释类或者您有javax.ejb.EJB注释类   作为您的应用程序的一部分打包。

     

我建议检查以下内容:

     
      
  • 确保未将javax.ejb.EJB类打包为注释的一部分
  •   
  • 检查WAR模块的web.xml是否有版本&gt; 2.4。不会扫描版本为2.4(或更早版本)的WAR模块进行注释。
  •   
  • 检查web.xml是否包含设置metadata-complete =&#34; true&#34;。此设置将关闭注释扫描。
  •   
     

来源http://www.developersite.org/102-95523-websphere-liberty