4 Replies Latest reply on Jan 17, 2008 7:21 AM by Fabrizio Di Fonzo

    Jsr181 typenamespace specification.

    Fabrizio Di Fonzo Newbie

      I deployed a pojo endpoint by using wsdl-tool with the following configuration file:


      <java-wsdl>
      
       <service name="MyWEBService" style="rpc"
       endpoint="mynamespace.WEBService"/>
      
       <namespaces target-namespace="http://mynamespace.com"
       type-namespace="http://mynamespace/types"
       />
      
       <mapping file="jaxrpc-mapping.xml"/>
       <webservices servlet-link="MyServlet"/>
      
       </java-wsdl>



      Given that this is an old style way to write a pojo endpoint, I'm writing a new one by using a jsr181:

      @WebService(name = "WEBService", targetNamespace = "http://mynamespace.com", serviceName = "MyWEBService")
      @SOAPBinding(style = SOAPBinding.Style.RPC)
      public class WEBServiceImpl {
      .....
      .....
      }
      

      Does anyone know a way to specify type-namesapce? Sorry for the silly question, but unfortunately, I've found this information nowhere.

      Thanks a lot,
      Fabrizio

        • 1. Re: Jsr181 typenamespace specification.
          Richard Opalka Master

          Hi,

          yes, you can annotate your custom java types with javax.xml.bind.annotation.XmlType annotation (see JAXB specification - http://www.jcp.org/en/jsr/detail?id=222) and specify namespace property there.

          • 2. Re: Jsr181 typenamespace specification.
            Richard Opalka Master

            Here's example:

            package org.mycompany.types;
            
            import javax.xml.bind.annotation.XmlAccessType;
            import javax.xml.bind.annotation.XmlAccessorType;
            import javax.xml.bind.annotation.XmlElement;
            import javax.xml.bind.annotation.XmlType;
            
            @XmlAccessorType(XmlAccessType.FIELD)
            @XmlType(name = "SpamResult", namespace="http://mycompany.org/types", propOrder = {
             "email",
             "fromAddress",
             "mailDate",
             "complaintDate",
             "mailbox",
             "complainer",
             "xRext",
             "accountName"
            })
            public final class SpamResult
            {
             @XmlElement(required = true, nillable = true)
             protected String email;
             @XmlElement(required = true, nillable = true)
             protected String fromAddress;
             @XmlElement(required = true, nillable = true)
             protected String mailDate;
             @XmlElement(required = true, nillable = true)
             protected String complaintDate;
             @XmlElement(required = true, nillable = true)
             protected String mailbox;
             @XmlElement(required = true, nillable = true)
             protected String complainer;
             @XmlElement(required = true, nillable = true)
             protected String xRext;
             @XmlElement(required = true, nillable = true)
             protected String accountName;
            
             public SpamResult()
             {
             }
            
             public SpamResult(String email, String fromAddress, String mailDate, String complaintDate, String mailbox, String complainer, String xRext, String accountName)
             {
             this.email = email;
             this.fromAddress = fromAddress;
             this.mailDate = mailDate;
             this.complaintDate = complaintDate;
             this.mailbox = mailbox;
             this.complainer = complainer;
             this.xRext = xRext;
             this.accountName = accountName;
             }
            
             public String[] get()
             {
             return new String[] { email, fromAddress, mailDate, complaintDate, mailbox, complainer, xRext, accountName };
             }
            }


            • 3. Re: Jsr181 typenamespace specification.
              Fabrizio Di Fonzo Newbie

              Thank you so much, Richard.

              I'll try using your suggested approach.

              Best regards,
              Fabrizio

              • 4. Re: Jsr181 typenamespace specification.
                Fabrizio Di Fonzo Newbie

                Hi,
                Unfortunately annotation on my custom type doesn't take any effect (I'm using jboss 4.2.2).

                My custom type looks like this now:

                package mycompany.exception;
                
                import java.io.Serializable;
                
                import javax.xml.bind.annotation.XmlAccessType;
                import javax.xml.bind.annotation.XmlAccessorType;
                import javax.xml.bind.annotation.XmlElement;
                import javax.xml.bind.annotation.XmlRootElement;
                import javax.xml.bind.annotation.XmlType;
                
                @XmlAccessorType(XmlAccessType.FIELD)
                @XmlType(name = "AlreadyExistsDeviceException", namespace="http://mycompany/types", propOrder = {
                 "errorMessage"
                })
                public class AlreadyExistsDeviceException extends Exception
                 implements Serializable {
                 @XmlElement(required = true, nillable = true)
                 private String errorMessage;
                
                
                 public AlreadyExistsDeviceException(String errorMsg) {
                
                 super(errorMsg);
                
                 this.errorMessage = errorMsg;
                
                 }
                
                 public String getErrorMessage() {
                
                 return errorMessage;
                
                 }
                
                }


                While my endpoint looks like the following:

                package mycompany;
                .....
                .....
                
                @Stateless
                @Remote(WEBServiceRemote.class)
                @WebService(name = "EndPointInterface", targetNamespace = "http://mycompany", serviceName = "MyServiceWEBService")
                @SOAPBinding(style = SOAPBinding.Style.RPC)
                @XmlSeeAlso({mycompany.exception.AlreadyExistsDeviceException.class)
                public class WEBServiceBean implements WEBServiceRemote, CodeControl {
                
                
                 @WebMethod
                 public void addDevice(String id, String type, String path) throws AlreadyExistsDeviceException {
                ......
                ......
                }
                
                }


                Using wsdl-tool I get a wsdl looking ike this:
                .....
                .....
                <types>
                .....
                .....
                 <schema targetNamespace='http://mycompany/types' xmlns='http://www.w3.org/2001/XMLSchema' xmlns:ns2='http://lang.java/' xmlns:ns3='
                http://annotation.lang.java/' xmlns:ns4='http://reflect.lang.java/' xmlns:ns5='http://security.java/' xmlns:ns6='http://cert.security.java/' xmlns:ns7='http
                ://www.w3.org/2001/XMLSchema' xmlns:ns8='http://util.java/' xmlns:ns9='http://net.java/' xmlns:soap11-enc='http://schemas.xmlsoap.org/soap/encoding/' xmlns:
                tns='http://webservice.ztc.alliedtelesyn.com/types' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
                 <import namespace='http://annotation.lang.java/'/>
                 <import namespace='http://cert.security.java/'/>
                 <import namespace='http://net.java/'/>
                 <import namespace='http://util.java/'/>
                 <import namespace='http://www.w3.org/2001/XMLSchema'/>
                 <import namespace='http://reflect.lang.java/'/>
                 <import namespace='http://lang.java/'/>
                 <import namespace='http://security.java/'/>
                 <complexType name='AlreadyExistsDeviceException'>
                 <sequence>
                 <element name='errorMessage' nillable='true' type='string'/>
                 </sequence>
                 </complexType>
                .....
                .....
                </types>
                .......
                .......
                


                While using annotation approach, I'm continuing getting the following wsdl:

                ....
                ....
                <types>
                .....
                .....
                 <xs:complexType name="AlreadyExistsDeviceException">
                 <xs:sequence>
                 <xs:element minOccurs="0" name="errorMessage" type="xs:string"/>
                 <xs:element minOccurs="0" name="message" type="xs:string"/>
                 </xs:sequence>
                 </xs:complexType>
                .....
                .....
                </types>
                ....
                ....


                Note that there's no namespace in the latter. Is there a way to discover what wrong is on my code? I set log4j debug level to TRACE but I haven't seen any Error.

                Any help will be really appreciated.
                Thanks a lot, Fabrizio