facebook

WebService Client and JAXBElement

  1. MyEclipse Archived
  2.  > 
  3. Web Services
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #265240 Reply

    trans888
    Member

    IF I try and generate a client from a live WSDL document, I get a client that seems to have lots of JAXB requirements.

    
      public static void main(String[] args)
        {
    
        TCEScratchStoreWebServiceClient client = new TCEScratchStoreWebServiceClient();
    
        //create a default service endpoint
        TCEScratchStoreWebServicePortType tCEScratchStoreWebServicePortType = client
            .getTCEScratchStoreWebServicePortTypeLocalEndpoint();
    
        //TODO: Add custom client code here
        //
        //tCEScratchStoreWebServicePortType.yourServiceOperationHere();
        Request req = new Request();
        req.setUserId("Alph");                                        // ERROR HERE
        Response resp = tCEScratchStoreWebServicePortType.store(req);
        System.out.println("Response: " + resp.getMessage());
        
        System.out.println("test client completed");
        System.exit(0);
        }
    

    I get a compile error on the marked line:

    
    The method setUserId(JAXBElement<String>) in the type Request is not applicable for the arguments (String)
    

    The import of the WSDL document from the live server went very smoothly…as far as I could tell…the code looks OK.

    I also note that the methods on ‘resp’ are also defined in terms of JAXBElement<String>.

    When I did the import, I was asked to add the XFire JAXB2 libraries to the classpath, which I did.

    I have been able to consume the EXACT service using Oracle’s JDeveloper…no problems at all, and no messing with JAXBElement.

    I HAVE seen the “consume Amazon service” demo at:

    http://www.myeclipseide.com/images/tutorials/feature_overview/MEFO%20-%20Main%20-%20Low%20Quality.htm

    and I HAVE seen the demo at:

    http://www.myeclipseide.com/images/tutorials/demos/terra_server_client/tutorial.html

    Any thoughts/suggestions?

    Cheers,

    Alph

    #265246 Reply

    trans888
    Member

    Found at:

    http://archive.xfire.codehaus.org/user/8412547.post@talk.nabble.com

    
    @XmlElement(minOccurs="1", nillable=false)
    public String getUsername()
      {
       return userName;
       }
    

    This is not perfect (the service POJO now has to know that it is being advertised and how/with what framework), but it seems to work.

    There exists an xfire JIRA:

    http://jira.codehaus.org/browse/XFIRE-843

    This is currently at ‘minor’ priority. Perhaps the myeclipse people could get this priority raised (I assume you guys have some ‘clout’)? It seems to me to invalidate the demos I saw (and the myeclipse WebServices ‘story’ at this point in time).

    Cheers,

    Alph

    #267955 Reply

    @trans888 wrote:

    This is not perfect (the service POJO now has to know that it is being advertised and how/with what framework), but it seems to work.

    I’m not sure how this “work around” works.

    I too am stuck on this. I have a webservice that takes a custom class as a parameter — and the web client generator generated that class — but instead of “strings” it uses JAXBElements.

    How do I work with JAXBElements?

    Lee

    #268000 Reply

    tomeksz
    Member

    The only solution ( currently, but i’ll try to look at this little deeper sometime later ) is to save WSDL to your local disk, replace minOccur=”0″ to minOccur=”1″ and regenerate the client code again. Then instead of JaxbElment<String>, String type should be generated.

    #269452 Reply

    mfkilgore
    Member

    I am about to try the “workaround” of changing the wsdl by hand. Has anyone come up with a better alternative? Is there a way the generated WSDL can be corrected?

    #269456 Reply

    tomeksz
    Member

    Currently i don’t know any other way to workaround this problem ( This is how Jaxb 2.x works ), but i’m not Jaxb expert.
    To make WSDL modification little easer,probably creating XSLT transformation to fix this, shouldn’t be very hard.

    #269558 Reply

    tomeksz
    Member

    Hmm, maybe there is another way to workaround it. Code generator takes externalBinding parameter which allows to control some generation result ( http://xfire.codehaus.org/Client+and+Server+Stub+Generation+from+WSDL ), but currently i’m too busy to investigate it. So if you have any friend with Jaxb skill, ask him/her if this can be helpfull 🙂 And of course let us know 😉

    #289303 Reply

    bdemchak
    Participant

    OK … I have a solution that seems to work. The problem is indeed that the generateElementProperty must be set to false. Setting it false generates a String type instead of the JAXBElement<String> … which appears to amount to requiring a String instead of having an optional String. In Java, requiring a String is the only semantic provided by the Java syntax, so we’re really not losing anything by doing this.

    This is a JAXB issue that can be controlled by a so-called bindings file. I called mine “javaBindings.xml”, and it was for a WSDL file available from my server as “http://localhost:81/services/PALMS?wsdl&#8221;. The bindings file looks like this:

    <jaxb:bindings version="2.0"
        xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
        xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jaxb:bindings schemaLocation="http://localhost:81/services/PALMS?wsdl">
            <jaxb:bindings node="/xs:schema">
                <jaxb:globalBindings>
                    <xjc:generateElementProperty>false</xjc:generateElementProperty>
                </jaxb:globalBindings>
            </jaxb:bindings>
        </jaxb:bindings>
    </jaxb:bindings>

    Undoubtedly, your WSDL file will be some other name … insert it instead of mine.

    And to use this with wsdl2java, name the file using the -b parameter. So, my invocation was:

    wsdl2java -client -b javabindings.xml http://localhost:81/services/PALMS?wsdl

    And viola … out pops declarations with String instead of JAXBElement<String>

    Whew!

    #289497 Reply

    bonzaixxs
    Member

    Hi there,
    I’m a complete newbie to JAXB, and have read this whole mail thread. Where do you store the bindings xml file? Is there a way to invoke this xml file within the ws-gen Ant task in the builld.xml of your project?

    Thanks in advance.

    #289499 Reply

    bdemchak
    Participant

    Good questions.

    I don’t have a good solution. For my project, I put the bindings file in the top level of my project directory, and I created an ANT file to build the proxies. I did not hook them into the overall project build. It’s a little tricky when you think about it … I’m getting my WSDL from the server, which would have to be up for the proxy generation to succeed. That sounds like a pretty uneasy dependency for a common operation like a build. So, for now, I deal with regenerating the proxies whenever I change the service. FYI, here’s my ANT file:

    <?xml version="1.0" encoding="UTF-8"?>
    <project name="PALMS_Server_dist" default="all" basedir=".">
    <!-- adapted from http://cwiki.apache.org/CXF20DOC/ant-tasks.html -->
    <!-- adapted from http://cwiki.apache.org/CXF20DOC/wsdl-to-java.html -->
    
    <!-- CXF properties -->
      <property name="cxf.home" value="E:/Sysprog/ESB/apache-cxf-2.1.2/"/>
        
    <!-- input properties -->
      <property name="wsdl-src" value="http://localhost:81/services/PALMS?wsdl"/>
        
    <!-- output properties -->
      <property name="out-src" value="src"/>    
        
    <!-- init target -->  
      <target name="init">
        <tstamp/>
      </target>
    
       <path id="cxf.classpath">
          <fileset dir="${cxf.home}/lib">
             <include name="*.jar"/>
          </fileset>
       </path>
    
    <!-- server target -->  
      <target name="wsdl" depends="init" description="Captures WSDL and creates proxies">
        <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
          <arg value="-client"/>
          <arg value="-b"/>
          <arg value="javaBindings.xml"/>
          <arg value="-d"/>
          <arg value="${out-src}"/>
          <arg value="${wsdl-src}"/>
          <classpath>
            <path refid="cxf.classpath"/>
          </classpath>
        </java>
      </target>
    
    <!-- all target -->  
      <target name="all" depends="wsdl" description="Builds the whole project">
        <echo>Doing all</echo>
      </target>
    
    <!-- clean target -->  
      <target name="clean" description="Removes previous build">
      </target>
    </project>
    #298583 Reply

    thefarmer
    Member

    Sun recommends the generateElementProperty but it has some drawbacks.
    The page is titled “Customizations for WCF Service WSDL”

    http://java.sun.com/webservices/reference/tutorials/wsit/doc/DataBinding5.html

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: WebService Client and JAXBElement

You must be logged in to post in the forum log in