Handle JAXB #XMLIDRef in .NET - java

I'm writing a web service using jax-ws. One of web service's methods returns bean, which contains reference to its parent. To prevent cyclic references I'm using JAXB #XMLID and #XMLIDRef annotations in my bean.
Then i'm generating proxy class for java client everything works OK and id resolves to Object properties. But then I'm generating web-service client proxy in Visual Studio for .NET, it interprets idrefs as string properties, not an Object.
Is it possible to generate proxy classes from wsdl for .NET with resolving of idrefs?

Out of the box Microsoft's tools won't do the job for you. You'll have to ask Microsoft to change the
wsdl generation tools. E.g.:
wsdl.exe: http://msdn.microsoft.com/library/7h3ystb6(VS.80).aspx
svcutil.exe: http://msdn.microsoft.com/en-us/library/aa347733.aspx
In a recent project I had to work around the short comings of these tools and modified the generated code using a Basic Script fixing what was not generated the way needed (in our case incompatibilities with the Java side wsdl generation)

Related

Instructing wsimport/jaxb to use existing model/domain classes

I humbly ask for your help in step-by-step way.
I'm working on a project which is managed by apache maven.
The project has several submodules
/pom.xml
/model/pom.xml
/server/pom.xml
/client/ws/pom.xml
/client/vaadin/pom.xml
server and ws depends on model
vaadin depends on ws
"model" project I have my hand-written domain classes which are annotated using JPA and XML annotations. Example below:
package com.example.domain.auth;
#Entity
#XmlType(name = "User", namespace = "auth.domain.example.com")
#XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
public class User implements Serializable {
#NotNull
private String username;
#NotNull
private String password;
#Temporal(value = TemporalType.DATE)
private java.util.Date accountExpirationDate;
public void veryComplexAction() { ... }
// getters & setters
}
"server" project hosts several WebServices which uses domain classes as both input and return types.
"ws" (client/ws) project is just a project with only WebService clients.
Project building is done copletly by maven. (wsgen & wsimport of wsdls using relative paths)
I don't have access to XSD files (well I do but) since they're generated during wsgen plugin execution on "server" project and have generated (semi-random) names which can change during development process since they're generated by wsgen.
Now since I have access to my model project I'd like to use it in "ws" and "vaadin" projects without the need to use generated model which don't have methods I've implemented in "model" project.
I have found that I need to use "episode" file to instruct jaxb compiler to skip generation domain classes.
The thing is I can't get it working because everyone give example where XSD is already available which in my project is generated during build process and contents of file "UserService_schema1.xsd" in next build can be in file "UserService_schemaN.xsd".
Acceptable solution:
generation of static xsd's during build process which have explicitly provided names and stay like this forever (even if regenerated) and using those xsd's generating episode files used in wsimport later
or
any solution which is completly automatic that I could type "mvn clean package" and all will be done for me like: generating static xsd's, episodes, wsdls, web service client wrapper classes using domain model from "model" project. (no manual copying of java files or episode files)
What I'd like to get (and probably not only me) example project or step-by-step tutorial on how to reuse existing domain model in webservice client project which is managed as a submodule of maven project. It can be even with one class, interface, enum. Just simple POJO demonstrating on how to configure everything.
What I've already checked:
http://stackoverflow.com/questions/11745465/jaxb-my-own-domain-model-and-suggestions
http://stackoverflow.com/questions/15907973/how-to-remove-auto-generated-classes-in-jax-ws-clients/16007685#16007685
http://jamablog.blogspot.com/2007/08/how-to-make-jax-ws-client-to-reuse.html
http://jamablog.blogspot.com/2007/08/how-to-make-jax-ws-client-reuse.html
http://sr-it.eu/wordpress/?p=135
http://metro.1045641.n5.nabble.com/Reusing-entity-classes-with-JAX-WS-bottom-up-td1061083.html
We have a similar setup. We using eclipse link and apache cxf together with jaxws. We don't generate client side model. We are using existing domain objects. EclipseLink helps you to annotate domain objects in an XML file. since our domain objects are in a seperate jar, we don't annotate the domain objects but use an xml file in the ws project to specify how to interpret the domain objects.
I did not put it together so can't provide you with a step by step instructions.

From WSDL to Java Objects - autogeneration?

I have the following requirements and thinking about how to best get java objects from a WSDL.
XML data comes from a public SOAP Webservice
I have to use JAXB
I want to automatically unmarshall the retrieved data to Java objects
Ideally I'd like to have java objects using JAXB Annotations. Are there any tools that I could combine to autogenerate these?
Sure, there are lots of ways to use JAX-WS (which uses JAXB for its XML binding) to generate a web service client.
You can execute it from the command-line:
http://www.mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
As part of your Maven build:
https://jax-ws-commons.java.net/jaxws-maven-plugin/
Or from within your Eclipse environment:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.jst.ws.cxf.doc.user%2Ftasks%2Fcreate_client.html
Yes, there are. With every jdk, there is an executable file called wsimport that does exactly what you want.
Here is an answer i gave to a similar question.

Confusion about web services

We have some existing Java code running on a Tomcat server that we want to allow code on another machine to execute, so we are looking into web services. I am new to web services and I think I'm probably doing something wrong here.
I have followed a few online tutorials on how to deploy a JAX-WS web service in Tomcat. I have created a web service class and annotated it with #WebService, written a web.xml and sun-jaxws.xml file, packaged those files (plus the JAX-WS jar files) into a .war file, and deployed it into Tomcat. That appears to be working, as I can load the WSDL file in a browser pointed at Tomcat.
It's the web service client I'm having trouble with. First of all, there are existing classes on the server side that get mapped into a database. We want to allow the client to use those same existing classes and create instances of out of them, invoke the web service, and then have the objects get stored into the database. However, when I ran the wsimport command against the server's WSDL file, it generated a bunch of Java classes, a lot of which are similar to our existing classes. I guess we have to use those instead of our existing classes? So much for code reuse, unless I'm confused, which is very possible.
So now I've written the client using those classes that wsimport generated. But I'm getting compile errors. Some of the fields in our existing Java classes are of type java.net.InetAddress. But for some reason, wsimport generated its own InetAddress class, and this is what it looks like:
package ems.server.webservices;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "inetAddress")
public class InetAddress {
}
Yeah it's just a class with nothing in it! So a lot of the compile errors I'm getting say:
WSClient.java:37: setAddress(ems.server.webservices.InetAddress) in ems.server.webservices.NetworkAddress cannot be applied to (java.net.InetAddress)
networkAddress.setAddress(InetAddress.getByName("1.1.1.1"));
I'm trying to create a java.net.InetAddress, but it wants me to use the empty class that was generated by wsimport. I must be doing something wrong here. Please enlighten me.
We have some existing Java code running on a Tomcat server that we
want to allow code on another machine to execute, so we are looking
into web services
Web services for this? Why?
First of all, there are existing classes on the server side that get
mapped into a database. We want to allow the client to use those same
existing classes....So much for code reuse
Really bad idea. The purpose of Web Services is not code-reusability but interoperability. Trying to reuse business classes that actually carry the semantics of the programing language you are using, is not only a bad practice but can lead you to many issues unless for most trivial web services where you also control the client.
when I ran the wsimport command against the server's WSDL file, it
generated a bunch of Java classes
When you run the wsimport all the necessary artifacts required for the web service client to communicate to the web server are created. This includes all the stub classes that help in transforming your classes during the SOAP marshalling/demarshalling
But I'm getting compile errors. Some of the fields in our existing
Java classes are of type java.net.InetAddress
java.net.InetAddress is a Java specific class. You should not be exposing that in the first place. That is why the code generator creates the empty java.net.InetAddress.
To be honest I can not give you a direct answer for making this work. The only I hint could give you is that if you annotate the InetAddress fields with #XmlTransient they will not be exposed in WSDL and you will not have that problem. Of course, you don't say if this field is needed for you so, perhaps my suggestion is useless to you.
But my recomendation is to switch your approach. You are on the wrong path IMHO.
The only recomendation is to change your approach.

How is build-wsdl2java.xml generated?

I've inherited the code base for a Java application which talks to a few SOAP web services. Proxy classes to do this are generated using an ANT task calling wsdl2java. As my Java experience is quite limited, I'm still trying to get my head around exactly how this all works.
There is a build-wsdl2java.xml file in the project that seems to contain the configuration information required for the class generation. The file as it stands currently has attributes that aren't currently supported (namespacesmapfile, overWriteTypes, testcaseoverwrite), but if I attempt to resolve this by changing the first to 'namespacemappingfile' and removing the others, the attributes revert back if the project is cleaned. The URL for the WSDL also reverts back if it is changed.
What controls the generation of this file, and where do I define the configuration parameters that it contains?
Finally found out what was controlling this and, more importantly, have got things compiling again. I'm using JBuilder 2008 (an Eclipse based Java IDE from Embarcadero Technologies), and it would appear the client proxy classes were generated from the WSDL by using JBuilders built in support for this, which is effectively a wrapper for wsdl2java as mentioned by Noergaarde.
In order to set settings such as the URL for the WSDL, I had to switch to the Modeling perspective, and use the Model Navigator to change the URL, by selecting the class under the Web Service Client node and using the Properties view.
When you do a build of your project, does the timestamp of build-wsdl2java.xml change? ie. is this file generated by the build in another ant file?
At any rate, it certainly sounds like your client stubs are generated using AXIS.
http://ws.apache.org/axis/java/user-guide.html#WSDL2JavaBuildingStubsSkeletonsAndDataTypesFromWSDL

Axis2 and customizing an XML schema in a bottom-up approach

I am using axis2 to create a web service from a java class I created. Everything works well, but I'd like to be able to customize the wsdl and I cannot figure out how to do it. I tried using some JAXB annotations with my objects (using axis1) but it had no effect on the wsdl generation.
I'd like to be able to specify nillable=true for some elements and make others required. I'd also like to be able to change element names and other things. Shouldn't axis2 look at the JAXB2.0 annotations if there's no WSDL included in the META-INF folder?
I have been trying to google how to map out the schema in a bottom-up approach but I have not had luck. The axis2 website only shows basic steps for creating a web service or a client, but nothing about customizing the schema.
To use JAXB annotation with AXIS2, you should have a look at this article :
Java Web services: JAXB and JAX-WS in Axis2
In Eclipse.org you find (Eclipse Helios) Eclipse IDE for Java EE Developers which is useful to create a web service easily and you can look at the documentation once for use of it effectively.

Categories

Resources