I'm writing a bridge between two old application on our network. One has a webservice that takes URL encoded parameters (GET) and returns an XML document. Like this:
http://mytest.com/getData/?format=xml&dateStart=2012-01-01
My question is this - I can use the XSD for the xml returned and marshall it into Java objects (xjc defined).. but is there any way to map the requests/responses to a jax-ws webservice (or similar?) It's not SOAP - so I can't go the WSDL, CXF/JAX-WS route, can I?
I was really hoping for an elegant solution to this without having to code it all from scratch (URL request , returned stream, then marshal). Is there a framework out there that would allow me configure a request? I thought WSDL supported verb="GET" but sadly, I can't seem to get it working with Apache CXF and WSDL2JAVA.
Am I totally off base here?
I think JAX-RS may be of use here. Just create XSD schemas and convert them to Java classes, and use a REST client for that site.
You can probably do it with CXF too. See here.
Check out WSGen or you can add ?WSDL to the end of your JAX-WS endpoint to get the generated WSDL. This way all you have to do is create your JAX-WS annotated classes similar to your JAX-RS ones and the WSDL is generated and it should be able to handle your XJC generated objects with no problems.
http://metro.java.net/guide/ch02.html#create-a-metro-web-services-endpoint
Related
I was wondering if it was actually possible to create a Java SOAP Webservice without using it's WSDL.
Context:
The idea is that I have to mock a webservice, so I have its WSDL. The mock will only read the soap request, search if there are any similar request (as key in a map) and send the matching response (as its value). This is for automated testing purpose. The problem is not the "map" part.
Anyway, I've been using Axis and eclipse to generate classes and files and load them in tomcat from the WSDL. So far it've been a mess, with a lot of compatibility issues between these components. And it's gonna be much more difficult to compare the input or serialize the output to do what I want this way.
I thought about creating a REST endpoint and send the soap request through it (so I would directly get the SOAP request !), but I rode somewhere that soap request weren't valid and wouldn't be retreived by the REST endpoint... Also, won't the client application throw an error if there is no WSDL at this address ?
My question is:
Is there a way to create an access point, that looks like a SOAP Webservice (from clients), but which allows me to get the full soap request (as a String for example) and send a response (still as a String) inside a Java app?
Complements:
I'm looking for something, a library, maybe just an annotation on Servlets, that doesn't needs (if possible) to generate a huge load of classes and xml files everywhere. The app would be running on tomcat (but I can be a basic Java app). Using maven and spring wouldn't be a problem.
Thanks in advance !
Normally, clients do not require an WSDL. But it is a nice feature - use a normal servlet and handle the "?WSDL" manually. Then use some simple XPath or parse logic to extract the payload as a DOM document.
I'm creating a WSDL-first webservice with spring-ws in gradle.
Some examples I have been looking at
(e g https://spring.io/guides/gs/producing-web-service/ )
it seems they will only generate the java-classes from the XSD-schema,
but no java-interface (or abstract-class) from the WSDL service-operations?
Also, in the spring-ws doc, it says "... in Spring-WS, writing the WSDL by hand is not required ...".
Is it correctly understood that spring-ws will not generate any java-interface or class for the actual service itself?
Is it possible to override this default behaviour and force it to do so?
I would like to ensure the full WSDL is correctly and completely implemented...
With spring-ws you can build contract first WS, although it is not necessary to build your WSDL, because it can generate it dynamically.
For java objects, spring-ws allows you to marshall/unmarshall using jaxb2 or similar. This way, you can obtain java classes from XSD, but this code generation is made by the marshaller.
From a server point of view, you create WS Endpoints that match WSDL operations. That Endpoints are annotated and bound to a request/response java objects. Thus, spring can generate dynamically WSDL, but you can use your own WSDL.
From a client point of view, you need a WSTemplate that needs to retrieve a WSDL (static or dynamic, it doesn't mind). Using this way, WSTemplate ensure you can call all server endpoints, without implementing client stubs or generated code.
I rather prefer to use static WSDL, because dynamic generation can't ensure that your WSDL change if you upgrade Spring or so, and this could break compatibility with your clients.
However, while I am developing I use dynamic WSDL, for the shake of simplicity. Once I have the service I want, I get dynamically generated WSDL (customize if I need) and use it as static. That WSDL is full for all the endpoints.
Hope it helps!
If you want only interfaces from WSDL just use wsimport command. Its part of jdk so no extra things needed.
run the commend: wsimport -keep wsdlUrl
it will generate all the interfaces and client code (.java as well as .class)to hit the web service. just search your interface.
Let your generated URL is :http://www.host.com/testservice?WSDL
then commend will be wsimport -keep http://www.host.com/testservice?WSDL
there are much more options with wsimport commend use as you want.
http://docs.oracle.com/javase/7/docs/technotes/tools/share/wsimport.html
ws import generate all the client side code.
asn wellm as much more things try wsimport, wsgen for more details
I work with REST service provided by RESTeasy. It's REST, so there is no WSDL, right? Does that mean that I have to write all entities on my own and do unmarshalling on my own?
If it would be rest service, I could just download WSDL and then generate client from it. How do i do it with REST, that is served as xml in Atom feed?
I don't really see any advantage in REST, if it has no way of generating client and doesn't provide any public specification of entities.
Thank you for your help.
Correct, with REST, there's no WSDL like there's with SOAP. That does not mean there's no unmarshalling directly to objects however. You can still use Jax-RS to bind the JSON/XML to an object, so you'll have the flexibility of mapping directly like you would in SOAP, you just need to build this class rather than letting SOAP build it for you.
Consider the example here
I have a WSDL url(http:localhost:8080/userdata?wsdl) and I want to create a request to this webservice so I can fetch the data for further processing. Can I do this without wsimport?
If I have to create package from wsimport, how I can create a client which will use generated classes to create the XML request?
If I can do this without wsimport , how I can create a client which will create the XML request?
New to webservices, links to documentation would be appreciated. I am trying to understand this at the moment http://java.dzone.com/news/5-techniques-create-web-servic
You can use CXF wsdl2Java to generate a client code for the web service.
Once you run the wsdl2java , you will get a set of java classes generated for you. You can then use those classes to call the services without any explicit conversion of XML - the underlying framework will do it for you automatically. You can start with http://cxf.apache.org/docs/how-do-i-develop-a-client.html
I proposed CXF while you can look for many other alternatives - However, i have found CXF to be very feature rich and will help you in developing/working with web services.
On top of what Akhilesh said you can also create a Dynamic client for invoking WSDL. I have done it recently and i found it a little bit better then using CXF as dynamic client does not generate any code whatsoever. You just pass in the parameters to it and it does all the job for you. You can find a "shell" to build your own client HERE
I'm using JaxWs/JaxB in a webservice, but I don't like the fact that all my xml files (be it the ones I send or receive) contain SOAP envelopes. How can I get rid of those?
All I need is a clean xml file that the web service returns without any SOAP envelope. That part of the xml file is redundant in my case.
I have spent several days on this, but I just can't seem to get rid of it.
jaxws is a technology for creating webservices using the SOAP protocol, which by definition includes the SOAP envelope. if you don't want the SOAP envelope, don't use jaxws/SOAP. you could instead use one of the jaxrs related technologies (e.g. jersey), or you could simply implement a servlet which accepts xml data.
You can use JIBX for this purpose: http://jibx.sourceforge.net/