[jboss-user] [JBossWS] - Re: Writing a client - no examples for BindingProvider based

mjhammel do-not-reply at jboss.com
Fri Jan 4 14:37:49 EST 2008


anonymous wrote : The application server includes a webservice stack (JBossWS) you can of course use without any further installation. However you would probably want to upgrade the ws stack since JBossWS is released more often than the application server. 

Okay.  I'll look into doing this. I downloaded the binary dist and found the Install doc.

anonymous wrote : This seems to me an issue with the libraries in your classpath. Check for example that jaxb-api.jar is in your classpath.

That fixed it.  The compile completed, although running the client needed more classpath fixups (some jars included in the classpath for the old version of the build for 4.0.5GA needed to be removed as well).

Thanks for the tips.  I'm much closer now.  My client actually connects to the web service endpoint and passes in an argument (which the web service prints to the console), but the EntityManager is not being injected.  I was going to move this question to another forum but now I'm not sure which forum it belongs in:  JBossWS, Persistance/Hibernate or EJB3.0?  So for now I'll post here.

Here is my web service code, based on the EJB3.0 TrailBlazer examples (http://trailblazer.demo.jboss.com/EJB3Trail/):

package com.cei.crunch.server.SubscriberServices;
  | 
  | import javax.ejb.*;
  | import javax.jws.WebService;
  | import javax.jws.WebMethod;
  | import javax.jws.soap.SOAPBinding;
  | import javax.persistence.*;
  | import javax.naming.InitialContext;
  | 
  | import com.cei.crunch.ejb.Subscriber;
  | import com.cei.crunch.ejb.Subscribersession;
  | 
  | /* Make this an EJB3 service endpoint. */
  | @Stateless
  | @Remote(SubscriberServices.class)
  | 
  | /* Make this an Web Services endpoint. */
  | @WebService(endpointInterface = "com.cei.crunch.server.SubscriberServices.SubscriberServicesEndpoint")
  | @SOAPBinding(style = SOAPBinding.Style.RPC)
  | 
  | /**
  |  * The .Crunch interface to Subscriber Services
  |  */
  | public class SubscriberServices implements SubscriberServicesEndpoint {
  | 
  |     @PersistenceContext (unitName="Crunch")
  |     EntityManager em;
  | 
  |     public void createSubscriber(Subscriber subscriber)
  |     {
  |         if ( em != null )
  |             em.persist(subscriber);
  |         else
  |             System.out.println("SubscriberServices: em is null; can't create subscriber");
  |     }
  | 
  |     @WebMethod
  |     public Subscriber findSubscriber(String guid)
  |     {
  |         System.out.println("findSubscriber: guid = " + guid);
  |         if ( em == null )
  |         {
  |             System.out.println("SubscriberServices: em is null; can't find subscriber");
  |             return null;
  |         }
  |         else
  |             return em.find(Subscriber.class, guid);
  |     }
  | 
  |     public void createSubscriberSession(Subscribersession session)
  |     {
  |         em.persist(session);
  |     }
  | 
  |     public Subscribersession findSubscriberSession(String guid)
  |     {
  |         return em.find(Subscribersession.class, guid);
  |     }
  | }

My client code looks the same as in my original post.  When the client is run the server console prints out the inbound guid and then prints that em is null.

12:12:28,276 INFO  [STDOUT] findSubscriber: guid = CRUNCH-DEFAULT-SUPERUSER
  | 12:12:28,276 INFO  [STDOUT] SubscriberServices: em is null; can't find subscriber

My persistence.xml looks like this:

<persistence>
  |     <persistence-unit name="Crunch">
  |         <jta-data-source>java:/CrunchDS</jta-data-source>
  |         <properties>
  |             <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
  |             <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
  |             <property name="hibernate.connection.url" value="jdbc:mysql://localhost/crunch"/>
  |             <property name="hibernate.connection.username" value="root"/>
  |         </properties>
  |     </persistence-unit>
  | </persistence>

I've read in a few places that PersistenceContext injection doesn't work in web services (even to the point that the relevant spec says it's not supported, apparently), but I'm confused on what the alternative is supposed to be.



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4117180#4117180

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4117180



More information about the jboss-user mailing list