| Author |
Message |
|
|
Post subject: WebService Client and JAXBElement<String>
Posted: Jan 26, 2007 - 10:31 PM
|
|
Veteran Member


Joined: Nov 20, 2006
Posts: 25
|
|
IF I try and generate a client from a live WSDL document, I get a client that seems to have lots of JAXB requirements.
| Code: |
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:
| Code: |
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 |
|
|
| |
|
|
|
 |
|
|
Post subject: Found a workaround...
Posted: Jan 27, 2007 - 10:59 AM
|
|
Veteran Member


Joined: Nov 20, 2006
Posts: 25
|
|
Found at:
http://archive.xfire.codehaus.org/user/8412547.post@talk.nabble.com
| Code: |
@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 |
|
|
| |
|
|
|
 |
|
|
Post subject: Re: Found a workaround...
Posted: Mar 23, 2007 - 09:11 PM
|
|

Joined: Jul 12, 2005
Posts: 55
|
|
| 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 |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Mar 26, 2007 - 01:34 PM
|
|
Registered Member


Joined: Feb 27, 2007
Posts: 88
|
|
| 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. |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Apr 26, 2007 - 08:37 PM
|
|
Veteran Member


Joined: Dec 15, 2003
Posts: 34
|
|
| 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? |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Apr 26, 2007 - 10:14 PM
|
|
Registered Member


Joined: Feb 27, 2007
Posts: 88
|
|
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. |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Apr 30, 2007 - 07:59 PM
|
|
Registered Member


Joined: Feb 27, 2007
Posts: 88
|
|
| 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 ;) |
|
|
| |
|
|
|
 |
|
|
Post subject:
Posted: Sep 24, 2008 - 03:49 AM
|
|
Joined: Sep 24, 2008
Posts: 2
|
|
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". The bindings file looks like this:
| Code: | <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! |
|
|
| |
|
|
|
 |
|
|
Post subject: Where to store the bindings xml?
Posted: Sep 29, 2008 - 03:25 PM
|
|
Joined: Sep 29, 2008
Posts: 1
|
|
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. |
|
|
| |
|
|
|
 |
|
|
Post subject: RE: Where to store the bindings xml?
Posted: Sep 29, 2008 - 03:57 PM
|
|
Joined: Sep 24, 2008
Posts: 2
|
|
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:
| Code: | <?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> |
|
|
|
| |
|
|
|
 |
|
|