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

mjhammel do-not-reply at jboss.com
Thu Jan 3 16:13:21 EST 2008


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.


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

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



More information about the jboss-user mailing list