1 2 Previous Next 20 Replies Latest reply on Jan 14, 2008 5:07 PM by mjhammel

    Writing a client - no examples for BindingProvider based doc

    mjhammel

      Short background: I'm migrating a project from JBOSS 4.0.5GA that used Axis to generate WSDL interfaces for my JAX-RPC based clients.

      I've got a simple web service up under JBOSS. I can see it under http://localhost:8080/jbossws/services. It has a very simplistic Web Service that simply reads data from a table in the DB using EJB's generated using Hibernate to reveng an existing db. Accessing the WSDL through the localhost url requires a login userid and password, which seems to mean I have my database-based authentication setup correctly (or at least I think it does). The server side appears ready to access with a client.

      So I've read up on writing clients:
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=62678 (found the Wiki pages and sample explanations discussed there:
      http://jbws.dyndns.org/mediawiki/index.php?title=Samples)
      http://jbws.dyndns.org/mediawiki/index.php?title=JAX-WS_User_Guide#Service_client_handlers
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=123643
      http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools#Client_Side
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=108760
      http://www.jboss.com/index.html?module=bb&op=viewtopic&t=104091
      http://jbws.dyndns.org/mediawiki/index.php?title=Authentication
      http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools

      All the examples I can find show the use of BindingProvider to set the username and password. Some of these links suggest looking at the example code in the testsuite in the JBOSS source code. So I downloaded the JBOSS-4.2.2GA source but none of the code (any of it) uses BindingProvider.

      Then I discovered that the source was actually JBOSS-WS from http://labs.jboss.com/jbossws/downloads/. My first questions, then, are this: isn't WS included in the application server? Do I need to download the WS binary and add it to the JBOSS application server (for V4.2.2GA of the app server)? At the moment I've got a compile-time problem so have not been able to simply try it and find out.

      Looking through the examples in the WS source code I cannot find an example that seems to implement the simplistic code shown in the client example here:
      http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools#Client_Side

      I was hoping it would be as easy as this shows, with the added properties to the BindingProvider for username and password. The SimpleUserNameTestCase example uses a QName class and does a Service.create(), something the JAX-WS Tools page (http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools#Client_Side) recommends not doing.

      I've written this client, but it fails to compile with an error I've not seen in any discussions or in any googled pages:

      package wsTestJAXWS;
      
      import java.net.URL;
      import javax.xml.ws.*;
      import javax.jws.*;
      
      /* Web Services interfaces */
      import com.cei.crunch.server.subscriberservices.*;
      
      /* Crunch DB tables. */
      import com.cei.crunch.ejb.Subscriber;
      
      public class wsTestJAXWS {
      
       private static URL targetURL = null;
       private String subscriberID = null;
       private String pw = null;
       private String host = null;
       private String crunchServer = null;
       private Subscriber profile = null;
       SubscriberServicesEndpoint ss = null;
      
       private boolean serviceBind()
       {
       try {
      
       SubscriberServicesService service = new SubscriberServicesService();
       ss = service.getSubscriberServicesPort();
      
       /* Set NEW Endpoint Location */
       BindingProvider bp = (BindingProvider)ss;
       bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, crunchServer);
      
       /* Setup to authenticate with the server. */
       bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, subscriberID);
       bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, pw);
      
       return true;
       }
       catch (Exception e) {
       System.out.println("Failed to login to server.");
       System.exit(1);
       }
       return false;
       }
      
       public void run(String[] args) {
      
       /* Save the subscriber login information. */
       if ( args.length != 3 )
       {
       System.out.println("Missing command line args (userid, password, server).");
       System.exit(1);
       }
       this.subscriberID = args[0];
       this.pw = args[1];
       this.host = args[2];
      
       // crunchServer = "https://" + this.host + ":8443/Crunch/services/SubscriberServices";
       crunchServer = "http://" + this.host + ":8080/Crunch/services/SubscriberServices";
       System.out.println("Trying to connect to " + crunchServer + " as User: " + subscriberID + ", password: " + pw);
      
       /* Get the WSDL interfaces to the server. */
       if ( serviceBind() == false )
       {
       System.out.println("Login failed.");
       System.exit(1);
       }
      
       /* Retrieve subscriber profile information. */
       try {
       profile = ss.findSubscriber("CRUNCH-DEFAULT-SUPERUSER");
       }
       catch (Exception e) {
       System.out.println("Failed findSubscriber(): " + e.getMessage());
       e.printStackTrace();
       System.exit(1);
       }
       if ( profile == null )
       {
       System.out.println("findSubscriber() failed.");
       System.exit(1);
       }
      
       System.out.println("Subscriber name : " + profile.getFirstname());
       System.out.println("Subscriber email: " + profile.getEmailAddress());
       }
      
       public static void main(String[] args) {
       new wsTestJAXWS().run(args);
       }
      
      }


      The compile time error is this:

      -client.test:
       [javac] Compiling 1 source file to /home/mjhammel/src/cei/crunch/build/classes/client
       [javac] /home/mjhammel/src/cei/crunch/src/com/cei/crunch/clients/tests/wsTestJAXWS.java:74: cannot access javax.xml.bind.annotation.XmlAccessorType
       [javac] file javax/xml/bind/annotation/XmlAccessorType.class not found
       [javac] profile = ss.findSubscriber("CRUNCH-DEFAULT-SUPERUSER");
       [javac] ^
       [javac] /home/mjhammel/src/cei/crunch/src/com/cei/crunch/clients/tests/wsTestJAXWS.java:76: cannot access javax.xml.bind.annotation.XmlElement
       [javac] file javax/xml/bind/annotation/XmlElement.class not found
       [javac] catch (Exception e) {
       [javac] ^
       [javac] 2 errors


      I can't find any discussion on what the XmlAccessorType or XmlElement classes are or why they're being referenced at the specified points in my code.

      FYI: The SubscriberServicesService class is being generated using wsconsume (http://jbws.dyndns.org/mediawiki/index.php?title=Wsconsume).

      Any pointers to getting this first test client working with username/password login (BASIC authentication, with DatabaseServerLoginModule configured in my application-policy) would be greatly appreciated.


        • 1. Re: Writing a client - no examples for BindingProvider based
          asoldano

           

          "mjhammel" wrote:

          Then I discovered that the source was actually JBOSS-WS from http://labs.jboss.com/jbossws/downloads/. My first questions, then, are this: isn't WS included in the application server? Do I need to download the WS binary and add it to the JBOSS application server (for V4.2.2GA of the app server)?

          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.


          Looking through the examples in the WS source code I cannot find an example that seems to implement the simplistic code shown in the client example here:
          http://jbws.dyndns.org/mediawiki/index.php?title=JBossWS_JAX-WS_Tools#Client_Side

          Most of the examples use an equivalent generic way of getting the endpoint that is
          Service service = Service.create(wsdlURL, qname);
          MyEndpoint port = (MyEndpoint)service.getPort(MyEndpoint.class);
          

          however you can take a look at the org.jboss.test.ws.jaxws.samples.retail sample which also has a @WebServiceClient annotated service class generated through the tools.


          I was hoping it would be as easy as this shows, with the added properties to the BindingProvider for username and password.

          And it should be that easy. Take a look at the org.jboss.test.ws.jaxws.samples.context sample, it is a real simple test case and uses basic auth.


          I've written this client, but it fails to compile with an error I've not seen in any discussions or in any googled pages:

          package wsTestJAXWS;
          
          import java.net.URL;
          import javax.xml.ws.*;
          import javax.jws.*;
          
          /* Web Services interfaces */
          import com.cei.crunch.server.subscriberservices.*;
          
          /* Crunch DB tables. */
          import com.cei.crunch.ejb.Subscriber;
          
          public class wsTestJAXWS {
          
           private static URL targetURL = null;
           private String subscriberID = null;
           private String pw = null;
           private String host = null;
           private String crunchServer = null;
           private Subscriber profile = null;
           SubscriberServicesEndpoint ss = null;
          
           private boolean serviceBind()
           {
           try {
          
           SubscriberServicesService service = new SubscriberServicesService();
           ss = service.getSubscriberServicesPort();
          
           /* Set NEW Endpoint Location */
           BindingProvider bp = (BindingProvider)ss;
           bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, crunchServer);
          
           /* Setup to authenticate with the server. */
           bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, subscriberID);
           bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, pw);
          
           return true;
           }
           catch (Exception e) {
           System.out.println("Failed to login to server.");
           System.exit(1);
           }
           return false;
           }
          
           public void run(String[] args) {
          
           /* Save the subscriber login information. */
           if ( args.length != 3 )
           {
           System.out.println("Missing command line args (userid, password, server).");
           System.exit(1);
           }
           this.subscriberID = args[0];
           this.pw = args[1];
           this.host = args[2];
          
           // crunchServer = "https://" + this.host + ":8443/Crunch/services/SubscriberServices";
           crunchServer = "http://" + this.host + ":8080/Crunch/services/SubscriberServices";
           System.out.println("Trying to connect to " + crunchServer + " as User: " + subscriberID + ", password: " + pw);
          
           /* Get the WSDL interfaces to the server. */
           if ( serviceBind() == false )
           {
           System.out.println("Login failed.");
           System.exit(1);
           }
          
           /* Retrieve subscriber profile information. */
           try {
           profile = ss.findSubscriber("CRUNCH-DEFAULT-SUPERUSER");
           }
           catch (Exception e) {
           System.out.println("Failed findSubscriber(): " + e.getMessage());
           e.printStackTrace();
           System.exit(1);
           }
           if ( profile == null )
           {
           System.out.println("findSubscriber() failed.");
           System.exit(1);
           }
          
           System.out.println("Subscriber name : " + profile.getFirstname());
           System.out.println("Subscriber email: " + profile.getEmailAddress());
           }
          
           public static void main(String[] args) {
           new wsTestJAXWS().run(args);
           }
          
          }


          The compile time error is this:

          -client.test:
           [javac] Compiling 1 source file to /home/mjhammel/src/cei/crunch/build/classes/client
           [javac] /home/mjhammel/src/cei/crunch/src/com/cei/crunch/clients/tests/wsTestJAXWS.java:74: cannot access javax.xml.bind.annotation.XmlAccessorType
           [javac] file javax/xml/bind/annotation/XmlAccessorType.class not found
           [javac] profile = ss.findSubscriber("CRUNCH-DEFAULT-SUPERUSER");
           [javac] ^
           [javac] /home/mjhammel/src/cei/crunch/src/com/cei/crunch/clients/tests/wsTestJAXWS.java:76: cannot access javax.xml.bind.annotation.XmlElement
           [javac] file javax/xml/bind/annotation/XmlElement.class not found
           [javac] catch (Exception e) {
           [javac] ^
           [javac] 2 errors


          I can't find any discussion on what the XmlAccessorType or XmlElement classes are or why they're being referenced at the specified points in my code.

          FYI: The SubscriberServicesService class is being generated using wsconsume (http://jbws.dyndns.org/mediawiki/index.php?title=Wsconsume).


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

          • 2. Re: Writing a client - no examples for BindingProvider based
            mjhammel

             

            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.

            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.



            • 3. Re: Writing a client - no examples for BindingProvider based
              mjhammel

              I got a little further now. First, http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html explains the problem a bit - you can't use injection in Web apps, which I assume translates to Web Services. So I used the technique listed in the blog.

              This worked, eventually, after I added a couple of lines to my persistence.xml, as suggested by the JBOSS App Server entity config documentation (http://docs.jboss.org/ejb3/app-server/reference/build/reference/en/html/entityconfig.html#d0e193).

              updated persistence.xml

              <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"/>
               <property name="jboss.entity.manager.jndi.name" value="java:/CrunchPersistence"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/CrunchFactory"/>
               </properties>
               </persistence-unit>
              </persistence>


              The two jndi related properties bound the names specified in the property to the application so that they could be referenced an InitialContext.lookup() (see code below).

              Now I can see the Session Bean retrieving the data from the database, but then it immediately complains about some "lazy" thing:

              17:11:24,689 INFO [STDOUT] Subscriber.find(): em is not null; returning subscriber for guid = CRUNCH-DEFAULT-SUPERUSER
              17:11:25,015 INFO [STDOUT] Subscriber name : SuperUser
              17:11:25,015 INFO [STDOUT] Subscriber email: admin@localhost
              17:11:25,176 ERROR [LazyInitializationException] failed to lazily initialize a collection of role: com.cei.crunch.ejb.Subscriber.crunchroleses, no session or session was closed


              It should be noted that "crunchroleses" is a field in a generated class. The class, com.cei.crunch.ejb.Subscriber, is generated by the reverse engineering process provided through Hibernate in order to generate EJB code for an existing database. So maybe there is some (yet more) additional configuration of Hibernate that needs to be done.

              My Web Services code now looks like this:

              package com.cei.crunch.server.ws.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.server.util.SubscriberUtil;
              import com.cei.crunch.ejb.Subscriber;
              
              /* Make this an EJB3 service endpoint. */
              @Stateless
              @Remote(SubscriberServices.class)
              
              /* Make this an Web Services endpoint. */
              @WebService(endpointInterface = "com.cei.crunch.server.ws.SubscriberServices.SubscriberServicesEndpoint")
              @SOAPBinding(style = SOAPBinding.Style.RPC)
              
              /**
               * The .Crunch interface to Subscriber Services
               */
              public class SubscriberServices implements SubscriberServicesEndpoint {
              
               @WebMethod
               public Subscriber findSubscriber(String guid)
               {
               Subscriber s;
               SubscriberUtil su = new SubscriberUtil();
              
               s = su.find(guid);
               if ( s == null )
               System.out.println("su.find() returned null.");
               return s;
               }
              
              }


              My Session Bean code, which is called by the Web Services code above, looks like this:

              package com.cei.crunch.server.util;
              
              import javax.ejb.*;
              import javax.jws.soap.SOAPBinding;
              import javax.persistence.*;
              import javax.naming.InitialContext;
              import javax.transaction.UserTransaction;
              import javax.annotation.Resource;
              
              import com.cei.crunch.ejb.Subscriber;
              
              /* Make this an EJB3 service endpoint. */
              @Stateless
              
              /**
               * The .Crunch interface to Subscriber Services
               */
              public class SubscriberUtil implements SubscriberUtilInterface {
              
               @Resource
               private UserTransaction utx;
              
               public Subscriber find(String guid)
               {
               InitialContext ctx = null;
               EntityManager em = null;
               try {
               ctx = new InitialContext();
               em = (EntityManager) ctx.lookup("java:/CrunchPersistence");
               }
               catch (Exception e)
               {
               // throw new WebServiceException(ex);
               System.out.println("Subscriber.find(): context lookup failure.");
               e.printStackTrace();
               return null;
               }
              
               if ( em == null )
               {
               System.out.println("Subscriber.find(): em is null; can't find subscriber");
               return null;
               }
               else
               {
               Subscriber s = null;
               System.out.println("Subscriber.find(): em is not null; returning subscriber for guid = " + guid);
               try {
               utx = (UserTransaction) ctx.lookup("java:/comp/UserTransaction");
               utx.begin();
               s = em.find(Subscriber.class, guid);
               utx.commit();
               }
               catch (Exception e)
               {
               System.out.println("Subscriber.find(): find problem.");
               e.printStackTrace();
               }
               if ( s != null )
               {
               System.out.println("Subscriber name : " + s.getFirstname());
               System.out.println("Subscriber email: " + s.getEmailAddress());
               }
               return s;
               }
               }
              
              }


              You'll note that I manually create a UserTransaction here. This is because if I don't do this, no transaction is injected into the Session Bean by the @Resource (I don't know why). And if I don't create the UserTransaction before referencing the EntityManager (em), I get a null pointer exception when I do reference it.

              My best guess at this is that the UserTransaction is in the wrong place - it may need to go in the Web Services class before it calls the Session Bean. However, that's pretty much a WAG at this point.

              • 4. Re: Writing a client - no examples for BindingProvider based
                asoldano

                The EntityManager injection should work given you're using an EJB3 endpoint. I personally used it:

                WS endpoint & EJB SLSB impl:

                @Stateless
                @WebService(name="TestCaricoWS",
                 targetNamespace = "http://www.xxx.it/TestCarico",
                 serviceName = "TestCaricoWSService")
                @SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
                public class TestCaricoSessionBean implements TestCaricoInterface {
                
                 @Resource
                 private SessionContext ctx;
                
                 @PersistenceContext(unitName = "TestCarico")
                 private EntityManager manager;
                
                 @TransactionAttribute(TransactionAttributeType.REQUIRED)
                 @WebMethod(operationName="performTest")
                 @Oneway
                 public void performTest(@WebParam(name="uffa") Uffa uffa) {
                 Query query = manager.createQuery("from TestCarico where cdTestCarico>=:from and cdTestCarico<=:to");
                 query.setParameter("from", uffa.getFrom());
                 query.setParameter("to", uffa.getTo());
                 List<TestCarico> entities = query.getResultList();
                ....
                


                Interface:
                @Local
                public interface TestCaricoInterface {
                
                 public void performTest(Uffa uffa) throws Exception;
                ....
                


                Datasource:
                <?xml version="1.0" encoding="UTF-8"?>
                <datasources>
                
                 <xa-datasource>
                 <jndi-name>TestCaricoDatasource</jndi-name>
                 <track-connection-by-tx/>
                 <isSameRM-override-value>false</isSameRM-override-value>
                 <xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
                 <xa-datasource-property name="URL">jdbc:oracle:thin:@10.10.10.1:1523:MYSID</xa-datasource-property>
                 <xa-datasource-property name="User">user</xa-datasource-property>
                 <xa-datasource-property name="Password">pwd</xa-datasource-property>
                 <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
                 <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
                 <!-- Checks the Oracle error codes and messages for fatal errors -->
                 <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
                 <!-- Oracles XA datasource cannot reuse a connection outside a transaction once enlisted in a global transaction and vice-versa -->
                 <no-tx-separate-pools/>
                 <min-pool-size>1</min-pool-size>
                 <max-pool-size>100</max-pool-size>
                 <blocking-timeout-millis>5000</blocking-timeout-millis>
                 <idle-timeout-minutes>1</idle-timeout-minutes>
                 </xa-datasource>
                
                </datasources>
                


                persistence.xml:
                <?xml version="1.0" encoding="UTF-8"?>
                <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                 version="1.0">
                
                 <persistence-unit name="TestCarico">
                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
                 <jta-data-source>java:/TestCaricoDatasource</jta-data-source>
                 <properties>
                 <property name="hibernate.dialect"
                 value="org.hibernate.dialect.HSQLDialect" />
                 <property name="hibernate.show_sql" value="true" />
                 <property name="jboss.entity.manager.factory.jndi.name"
                 value="java:/TestCaricoEntityManagerFactory" />
                 </properties>
                 </persistence-unit>
                </persistence>
                


                Please note that no manual actions with transactions and so on is required.
                Hope this helps, anyway for qualified support about EJB3 questions also refer to http://www.jboss.com/index.html?module=bb&op=viewforum&f=221.

                • 5. Re: Writing a client - no examples for BindingProvider based
                  mjhammel

                  Thanks for the tip alessio. Unfortunately, it didn't really help. What I discovered, after some searching, is that injection doesn't work in 4.2.2GA and that the method I was using was correct in this case (5.0 is supposed to fix this issue, so I may upgrade to the beta eventually, after I get a better grasp of why things work in general). But I needed one more step: reference the size() for a set contained within the retrieved db object while in the current transaction. This eliminated all errors on the server side. The problem now is that the same set within that db object cannot be returned to the remote caller because of some problem converting from the set to XML (which causes some kind of infinite xml loop). I can return a value from the db object, but not the object. See http://forums.java.net/jive/thread.jspa?threadID=13670&start=15.

                  I'll move this discussion over to the EJB3.0 forum now, as this appears to be specific to that part of JBOSS 4.2.2GA.

                  Thanks again.

                  • 6. Re: Writing a client - no examples for BindingProvider based
                    asoldano

                     

                    What I discovered, after some searching, is that injection doesn't work in 4.2.2GA

                    This sounds quite strange to me...could please tell me where did you read this?
                    Thanks

                    P.s. unfortunately, nothing special to say about the infinite loop...

                    • 7. Re: Writing a client - no examples for BindingProvider based
                      mjhammel

                      Sorry - I didn't catch you're reply till today. I've been waiting for some feedback over in the EJB3 forum. I don't have all the links saved, but one that has some detailed explanation as to why it shouldn't work in web services at all is here:

                      http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html

                      The blog is old, but since it discusses how the specs say this shouldn't work it seemed fairly authoritative. There were other links I found as well, some newer than this one and related specifically to JBOSS. I just didn't save them. Even if injection could be made to work, if I can't return a table row using Hibernate generated EJB3 objects then this is of no use to me.

                      To be honest, I'm about ready to abandon EJB3/JAX-WS under JBOSS 4.2.2GA/Hibernate. I've been at this a month now and I still can't get a simple table row returned from my web service. The simplicity promised by EJB3 just seems like the complexity moved to new places.

                      While older and partially unsupported now, at least EJB2.1/JAX-RPC worked with JBOSS 4.05GA/Middlegen/Axis.

                      • 8. Re: Writing a client - no examples for BindingProvider based
                        asoldano

                         

                        "mjhammel" wrote:
                        Sorry - I didn't catch you're reply till today. I've been waiting for some feedback over in the EJB3 forum. I don't have all the links saved, but one that has some detailed explanation as to why it shouldn't work in web services at all is here:

                        http://weblogs.java.net/blog/ss141213/archive/2005/12/dont_use_persis_1.html


                        This is not your situation, you're not using the persistence context in a servlet, you need injection in a SLSB. And my previous post shows that it works.

                        Even if injection could be made to work, if I can't return a table row using Hibernate generated EJB3 objects then this is of no use to me.


                        I've just tried this too. It works more or less. I'm saying so since of course the problems you might have to face are lazy instantiation and cyclic referenced structure (that cannot be serialized into xml without references).


                        • 9. Re: Writing a client - no examples for BindingProvider based
                          jbn1v

                           


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

                          And then:

                          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).

                          What is your classpath? And what old jars did you need to remove? I have a similar problem getting a client to connect to a web service that has basic authentication enabled. On the service.create(wsdlURL, QName) call I get (my client worked fine before I enabled basic authentication):
                          org.jboss.ws.metadata.wsdl.WSDLException: Cannot parse wsdlLocation: http://localhost:8080/foo?wsdl
                          



                          • 10. Re: Writing a client - no examples for BindingProvider based
                            mjhammel

                             

                            "alessio.soldano@jboss.com" wrote:
                            This is not your situation, you're not using the persistence context in a servlet, you need injection in a SLSB. And my previous post shows that it works.


                            That may be, but then there is this discussion:

                            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=107353

                            In any case, I've done everything I think I need to do and it still doesn't work. I'd be happy for someone to show me what I've done wrong, but barring that I'd still have to say, in my case, it doesn't work.

                            I've just tried this too. It works more or less. I'm saying so since of course the problems you might have to face are lazy instantiation and cyclic referenced structure (that cannot be serialized into xml without references).


                            The "lazy" exception was due to Hibernate creating OneToMany annotations for fields in one table that were referenced by other tables. These references could not be serialized and caused the exceptions.

                            The references were created by Hibernate during the reverse engineering process because I had specified a foreign-key in other tables that pointed back to the first table. I removed the foreign-keys from my MySQL DB schema and the problem went away. The only drawback I can find on my end is that I need to add code to verify I don't have abandoned rows with links to rows that don't actually exist in other tables. Being a C programmer originally, I'm used to writing all my own checks like this, so it's not that big a deal. At least now I can pass back the serialized objects that represent db rows.

                            FWIW, I'm now passed this issue and trying to get access to the DB from a Schedulable. Like my Web Services class, injection does not seem to work there either. Unlike my Web Services class, I can't seem to find a work around in the schedulable because I don't know how to create a transaction and the method for retrieving the UserTransaction I used in the WS class doesn't work in a schedulable. See

                            http://www.jboss.com/index.html?module=bb&op=viewtopic&t=127493



                            • 11. Re: Writing a client - no examples for BindingProvider based
                              asoldano

                               

                              "mjhammel" wrote:
                              "alessio.soldano@jboss.com" wrote:
                              This is not your situation, you're not using the persistence context in a servlet, you need injection in a SLSB. And my previous post shows that it works.


                              That may be, but then there is this discussion:

                              http://www.jboss.com/index.html?module=bb&op=viewtopic&t=107353

                              In any case, I've done everything I think I need to do and it still doesn't work. I'd be happy for someone to show me what I've done wrong, but barring that I'd still have to say, in my case, it doesn't work.


                              Once again, you're not trying to use injection in a servlet, you need it in SLSB web service endpoint, don't you? The thread you linked talks about injection in servlets.
                              This said, going back to your problem, I would suggest you to start from the code I posted in this thread and modify it step by step according to your need.

                              • 12. Re: Writing a client - no examples for BindingProvider based
                                mjhammel

                                 

                                "jeff norton" wrote:

                                What is your classpath? And what old jars did you need to remove? I have a similar problem getting a client to connect to a web service that has basic authentication enabled. On the service.create(wsdlURL, QName) call I get (my client worked fine before I enabled basic authentication):
                                
                                org.jboss.ws.metadata.wsdl.WSDLException: Cannot parse wsdlLocation: http://localhost:8080/foo?wsdl
                                



                                To compile the client, my classpath includes the source to the client, the classes generated by wsconsume and the following:

                                <path id="client.wsconsume.classpath">
                                 <fileset dir="${jboss.lib.dir}/endorsed">
                                 <include name="xercesImpl.jar"/>
                                 </fileset>
                                 <fileset dir="${jboss.client.lib.dir}">
                                 <include name="*.jar"/>
                                 <exclude name="jaxws-rt.jar"/>
                                 </fileset>
                                 <fileset dir="${java.lib.dir}">
                                 <include name="tools.jar"/>
                                 </fileset>
                                 </path>


                                where
                                jboss.lib.dir = ${jboss.home}/lib
                                jboss.client.lib.dir = ${jboss.home}/client
                                java.lib.dir = ${java.home}/lib


                                I got rid of axis and mail libraries which were being used in the old build. I'm not using Axis in the new project (at least not yet). I also no longer reference an in-build copy of jboss-j2ee.jar (though this is still referenced from the jboss.client.lib.dir) and javax.servlet.jar which were used in the old build (note that I inherited some of this so wasn't clear on why some of those were being used in the first place).

                                I ran into your problem with not finding the WSDL location after switching to Basic Authentication. In order to get around this I don't try to retrieve the WSDL file from the server during the client build. I have the server side build generate the WSDL file for me using wsprovide, then the client side build reads that file instead of trying to retrieve the WSDL via a URL. My wsconsume looks like this now:

                                <wsconsume
                                 fork="true"
                                 verbose="true"
                                 destdir="${build.client.classes.dir}"
                                 sourcedestdir="${build.client.dir}"
                                 keep="true"
                                 wsdl="${build.server.dir}/resources/SubscriberServicesService.wsdl">
                                 <!-- wsdl="http://127.0.0.1:8080/Crunch?wsdl"> -->
                                 </wsconsume>


                                My wsprovide looks like this:

                                <wsprovide
                                 fork="false"
                                 keep="true"
                                 destdir="${build.server.dir}/wsdl"
                                 resourcedestdir="${build.server.dir}/resources"
                                 sourcedestdir="${build.server.dir}/source"
                                 genwsdl="true"
                                 verbose="true"
                                 sei="com.cei.crunch.server.ws.SubscriberServices.SubscriberServices">
                                 <classpath>
                                 <pathelement path="${build.server.classes.dir}/server"/>
                                 </classpath>
                                 </wsprovide>
                                


                                • 13. Re: Writing a client - no examples for BindingProvider based
                                  mjhammel

                                   

                                  "alessio.soldano@jboss.com" wrote:

                                  This said, going back to your problem, I would suggest you to start from the code I posted in this thread and modify it step by step according to your need.


                                  That would be fine but you only posted code snippets, not a complete working example. If you post the complete working example, I'll modify it to see if I can get it working.

                                  However, from your snippets, I can't see anything I haven't already tried.


                                  • 14. Re: Writing a client - no examples for BindingProvider based
                                    jbn1v

                                    I use the same wsprovide and wsconsume targets that you do, but the client still seems to need the WSDL in order to create the service endpoint. Thus I have:

                                    myService = Service.create(new URL("http://localhost:8080/serviceContextRoot?wsdl"), new QName(...));

                                    I tried using a file URL using the file generated by wsprovide but then I get:
                                    javax.xml.ws.WebServiceException: java.lang.IllegalArgumentException: Malformed endpoint address

                                    I wish there were at least a form of Service.create that would take a stream for the WSDL instead of a URL. Then I could pack the WSDL in the WAR. Even better of course would be for the client not to need the WSDL at all (the .NET client I generated from the WSDL doesn't need it, the Java one really shouldn't either). Have you been able to get that to work? If so a code snippet would be really nice. Thanks.

                                    1 2 Previous Next