Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EntityManager is not loaded in Axis2 WebService Skeleton Class

 
sreedhar sri
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am new to Webservices. I am developing webservice using axis2-1.6.2. I generated java classes using wsdl file through axis2.
WSDL2Java -uri file:///E:\Desktop\SampleSuscripciones.wsdl -p hn.com.sample.subscription -d adb -s -wv 1.1 -ss -sd -ssi

After that i generated stub and test class file using the related commands.
WSDL2Java -uri file:///E:\Desktop\SampleSuscripciones.wsdl -p hn.com.sample.subscription -d adb -s -t

In skelton class i wrote my business logic and used entity manager in this class like the following way.

Service Class:
----------------

@Stateless.
public class SampleSubscriptionsSkeleton implements SampleSubscriptionsSkeletonInterface{

@Inject
private EntityManager em;

public hn.com.sample.services.subscriptions.GetSubscriberResponse getSubscriber
( hn.com.sample.services.subscriptions.GetSubscriber getSubscriber)
{
System.out.println("Get subscriber method called in skeleton class:");
Random randNum = new Random();
GetSubscriberResponse resp = new GetSubscriberResponse();
System.out.println("Get Subscriber method called: ");
System.out.println("Entity manager obj in class:"+em);
CriteriaBuilderImpl cb = (CriteriaBuilderImpl)em.getCriteriaBuilder();
System.out.println("Criteria object in Skeleton class:"+cb);
CriteriaQuery<NewSaleSubscriber> criteria = cb.createQuery(NewSaleSubscriber.class);
Root<NewSaleSubscriber> subscriberInfo = criteria.from(NewSaleSubscriber.class);
Predicate predicate =cb.equal(subscriberInfo.get("available"), 1);
List<NewSaleSubscriber> ResultList = em.createQuery(criteria.select(subscriberInfo).where(predicate)).getResultList();
NewSaleSubscriber result= ResultList.get(randNum.nextInt(ResultList.size()));
SubscriberInfoType stype= new SubscriberInfoType();
stype.setFullName(result.getName());
stype.setMsisdn(Integer.parseInt(result.getPhone()));
stype.setSubscriberId(result.getId());
resp.setSubscriber(stype);

return resp;


//TODO : fill this with the necessary business logic
//throw new java.lang.UnsupportedOperationException("Please implement " + this.getClass().getName() + "#getSubscriber");
}

After this i generated .aar file using build. And uploaded .aar file in axis2 war in GlassFish server. The service is up and running.
In cient class while accessing the service it is giving the error in service class the entity manager object is null.


Client Class:
---------------
public class SampleSubscriptionsTest {

public static void main(String args[]) throws java.lang.Exception{

SampleSubscriptionsStub stub =
new SampleSubscriptionsStub ("http://sreedhar-cbd35e:9090/axis2/services/SampleSubscriptions");


doInOnly(stub);
}

public static void doInOnly(SampleSubscriptionsStub stub){
try{
GetSubscriber req = new GetSubscriber();
GetSubscriberResponse resp= new GetSubscriberResponse();
AuthorizationType type;
type=new AuthorizationType();
type.setProviderId("t123");
type.setAuthorizationToken("token1");
req.setMsisdn(123343);
req.setToken(type);
resp=stub.getSubscriber(req);
if(resp!=null){
System.out.println("Response not null:");
System.out.println("response:"+resp.getSubscriber().getSubscriberId());
}
else
System.out.println("Response is null");


System.out.println("done");
} catch(Exception e){
e.printStackTrace();
System.out.println("\n\n\n");
}
}

}


The problem is EntityManager is not injected in Skeleton class. Please any one give the suggestion to solve this problem.


Thanks,
Sreedhar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic