6 Replies Latest reply on Feb 1, 2005 7:10 PM by mette

    How to write a client that calls a document-style web servic

    mette

      I have created a JSE web service, document-style, and I am currently creating the client part, to test the deployed service.

      I have done a cut and paste of the client code in the Wiki, and replaced the names, url's and so forth, but wen i try to run it, I get the following exception:

      Exception in thread "main" javax.xml.rpc.ServiceException: java.lang.NullPointerException
      at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:125)
      at sandbox.mette.ws.device.WSClient.main(WSClient.java:46)
      Caused by: java.lang.NullPointerException
      at java.util.StringTokenizer.(StringTokenizer.java:139)
      at java.util.StringTokenizer.(StringTokenizer.java:155)
      at org.jboss.webservice.deployment.ServiceDescription.getPackageName(ServiceDescription.java:824)
      at org.jboss.webservice.deployment.ServiceDescription.initTypeMappings(ServiceDescription.java:798)
      at org.jboss.webservice.deployment.ServiceDescription.initServiceDescription(ServiceDescription.java:114)
      at org.jboss.webservice.deployment.ServiceDescription.(ServiceDescription.java:81)
      at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:120)
      ... 1 more

      My client code is:

      URL url =
      new URL("http://localhost:8080/ws4ee/services/SensorRegistryServiceJSE?wsdl");

      QName qname = new QName("urn:com:bonsaidevelopment:schemas:registry:SensorRegistryCommands.xsd",
      "SensorRegistryServiceJSE");

      ServiceFactory factory = ServiceFactory.newInstance();
      Service service = factory.createService(url, qname);

      It fails on the last line.

      Now, I found the following paragraph in the Wiki:

      This service can now be accessed from any webservice client. Here is a simple test case, that shows how a java client would first obtain the WSDL from the remote location, and then invoke getContactInfo on the service endpoint interface. Please note that in the case of document style web services, the client should be given a pointer to the jaxrpc-mapping.xml file, which the standard JAXRPC javax.xml.rpc.ServiceFactory? does not support.


      So, this may be the cause for my exception, but I cannot find any information on how to write a client with JBoss for document-style, or what the quite vague description "the client should be given a pointer to the jaxrpc-mapping.xml file" means. Also, if i do not use the standard JAXRPC service factory, then what am I supposed to use?


        • 1. Re: How to write a client that calls a document-style web se
          kanno

          Generally, the jax-rpc mapping file will be created when you use wscompile to generate the wsdl file. How exactly did you create the wsdl?

          There is a page on the wiki that explains it further:

          http://www.jboss.org/wiki/Wiki.jsp?page=WSClientDII

          The method with the following signature:

          public Service createService(URL wsdlLocation, URL mappingLocation, URL ws4eeMetaData, QName serviceName, String portName) throws ServiceException
          

          can be found in the org.jboss.webservice.client.* package which can be found in the client directory of your JBoss installation in the jar file: jboss-ws4ee-client.jar



          • 2. Re: How to write a client that calls a document-style web se
            mette

            I created the WSDL by hand, using available examples. I aso created the jx-rpc mapping file, and that part is fine. Howvere, the wiki did not explain what to do with this file, beyond " the client should be given a pointer to the jaxrpc-mapping.xml file, which the standard JAXRPC javax.xml.rpc.ServiceFactory? does not support.", which frankly did not mean anything to me.

            The interesting thing abou tthat WIKI entry (the url is if you are interested), is that all the examples before the client example use document style, but then the client example is written in a way that does not support document style. You may want to revise this as it is confusing at best for people using either style.

            I am glad that there is an alternate way of doing this, and the link you sent was very helpful, but I have an additional questions (and bear with me, as I am in many ways a novice to this):
            Now I have to provide the mapping file URL to the code, but I assume these files are not automatically hosted by JBoss, the way the WSDL is? Do I have to host them up myself, or maintain copies on the client side?

            • 3. Re: How to write a client that calls a document-style web se
              mette

              I tried using the code in the Wiki entry you linked to, changing names and namespaces as appropriate, obviously, and on the call to serviceFactory.createService, I get the exception below. Any idea what on earth it might mean???

              Exception in thread "main" javax.xml.rpc.ServiceException: org.xml.sax.SAXException: src-resolve: Cannot resolve the name 'j2ee:dewey-versionType' to a(n) type definition component. @ *unknown*[257,22]
               at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:167)
               at sandbox.mette.ws.device.WSClient.main(WSClient.java:55)
              Caused by: org.xml.sax.SAXException: src-resolve: Cannot resolve the name 'j2ee:dewey-versionType' to a(n) type definition component. @ *unknown*[257,22]
               at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
               at org.jboss.xml.binding.Unmarshaller.unmarshal(Unmarshaller.java:153)
               at org.jboss.xml.binding.Unmarshaller.unmarshal(Unmarshaller.java:140)
               at org.jboss.webservice.metadata.jaxrpcmapping.JavaWsdlMappingFactory.parse(JavaWsdlMappingFactory.java:62)
               at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:158)
               ... 1 more
              



              • 4. Re: How to write a client that calls a document-style web se
                thomas.diesler

                 

                org.jboss.webservice.deployment.ServiceDescription.getPackageName(ServiceDescription.java:824)


                What jboss version is this?

                Please check that you client uses a namespace aware XML parser like xerces, which can be enabled like this

                <sysproperty key="java.endorsed.dirs" value="${jboss.home}/lib/endorsed"/>
                



                • 5. Re: How to write a client that calls a document-style web se
                  mette

                  It was 4.0.0, I retried it in 4.0.1 with the same result:

                  Exception in thread "main" javax.xml.rpc.ServiceException: org.xml.sax.SAXException: src-resolve: Cannot resolve the name 'j2ee:dewey-versionType' to a(n) type definition component. @ *unknown*[257,22]
                   at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:167)
                   at sandbox.mette.ws.device.WSClient.main(WSClient.java:53)
                  Caused by: org.xml.sax.SAXException: src-resolve: Cannot resolve the name 'j2ee:dewey-versionType' to a(n) type definition component. @ *unknown*[257,22]
                   at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
                   at org.jboss.xml.binding.Unmarshaller.unmarshal(Unmarshaller.java:153)
                   at org.jboss.xml.binding.Unmarshaller.unmarshal(Unmarshaller.java:140)
                   at org.jboss.webservice.metadata.jaxrpcmapping.JavaWsdlMappingFactory.parse(JavaWsdlMappingFactory.java:63)
                   at org.jboss.webservice.client.ServiceFactoryImpl.createService(ServiceFactoryImpl.java:158)
                   ... 1 more
                  


                  I can try making sure about the setting, but where is it located???

                  • 6. Re: How to write a client that calls a document-style web se
                    mette

                    I found the problem that was causing the exception!

                    I do not remember exactly how I created the jax-rpc mapping file, but I assume I must have copied and pasted it from somewhere and changed the details to fit my own.

                    On the root element of the mapping file was the following schemaLocation:

                    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_jaxrpc_mapping_1_1.xsd"
                    


                    I have seen this schemaLocation used in several jax-rpc mapping files on boards here, and a JAX-RPC page mentions this schema location, so I assume this is a common thing to do.

                    When I go the schema at that location, I notice that it uses a lot of types in the same namespace (using the j2ee prefix) that it then doesn't define. It does however include a file j2ee_1_4.xsd, which I am unable to open from the stated location, so I assume that is where the problem lies. Being able to find the schema it goes into validatin mode, but being unable to load the entire definition the validation fails.

                    When I remove the schemaLocation attribute, it seems to skip validation, and my code completes and it sends the request to the server. Now if I can only get my web service to work (different thread), I should be all set... :-)