This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Web Services and the fly likes EntityManager is not loaded in Axis2 WebService Skeleton Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "EntityManager is not loaded in Axis2 WebService Skeleton Class" Watch "EntityManager is not loaded in Axis2 WebService Skeleton Class" New topic
Author

EntityManager is not loaded in Axis2 WebService Skeleton Class

sreedhar sri
Greenhorn

Joined: Sep 05, 2012
Posts: 9
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.
 
Don't get me started about those stupid light bulbs.
 
subject: EntityManager is not loaded in Axis2 WebService Skeleton Class
 
Similar Threads
Creating webservice using Axis2
Axis2 Soap envelope not generating required namespaces.
Facing Problems Running My First WebService
Generate a WS from Spring Service
Not able to hit the webservice when deployed in tomcat.