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.
Related
I have to request a PHP page with 3 Parameters (e.g. www.test.com/index.php?name=mrTest&no=1&id=10001). I'm using WSDL2JAVA for other Services and am now wondering if it is possible to generate a similar Service for this case. This PHP page Returns an XML. I'm just consumer/client of the Service.
I could also make a simple request and then use JAXB to parse the XML but i would like to implement all my Services the same way.
So, does anybody has already implement a php page consumer using WSDL2JAVA?
Best regards
So from my understanding this is a simple PHP page not a SOAP service. Remember XML is just the protocol used in a SOAP service however a SOAP service consists out of a WSDL that is published describing operations and how to call those operations.
A simple PHP page even if it returns XML data is NOT a SOAP service and thus does NOT have a WSDL. You wont be able to use WSDL2JAVA for that.
This PHP page seems more like a REST type service that returns XML instead of JSON. To be honest it really sounds like a REST service.
Try using the latest SOAPUI to connect to the page and see if you can use the REST project type with this page. If it is a REST service it might have a WADL file. YOu can use the WADL2JAVA cxf utility to generate classes to you. HOwever this is a BIG might as most REST services dont use WADL's yet. See this link on CXF
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
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/
I need comunicating using java with a WebService that uses the WSDL technology.
I tried some libraries but with no success, thus, I decided to do it manually.
My plan is getting a .xml which uses the comunication (filtering with fiddler for example) and copy it manually building a string. So the .xml will be ok. Do I need to take care of anything else?
Do I have to do any more? Http request, response?
I wouldn't like to create all the structure for the xml and after that, find that I can't continue the comunication.
Thanks
Java comes with a complete API for XML Web Services, this is JAX-WS. (lot of documentation available with a simple serach with google)
it allows developers to build a working client with very little effort starting from a WSDL file (seems your case)
I really discourage you to build the client by yourself. You should care about SOAP message building, message sending, response parsing and so on.
Im a little confused on the varying definitions and implementations of web services available as implementations. Need some clarification please.
Ones I have used till now:
If a vendor gives me a specific format of XML that I can send populated with data to request and I make a simple HTTP POST over the internet passing in the XML String as the payload, is this a web service call ? If so, is there a specific name to it, this kind of web service ? Because obviously, it does not use anything like Axis, WSDL or SOAP to establish this connection.
A variant of this is If the vendor gives me an XSD, I use JAXB to make a java class out of it and pass in the serialized version of the object, which eventually works out to be the same as option 1.
RESTful web service: Vendor gives me a URL like http://restfulservice/products and I can make HTTP Requests to the URL and depending on what HTTP verb I use, the appropropriate action is called and the response sent over the wire.
Ones I have only read about\ have a vague idea about
SOAP. How does this work?.. Ive read the W3Schools tutorial and I undertsand that there is a very specific form of XML that is standardized according to W3C standards that we use to pass the same kind of messages as we did in option 1. But how does this work in real life? Vendor sends me what? Do I generate classes? Do I serialize some objects and http post them over to an address? Or do the generated objects themselves have connection methods that will do them for me?
What about WSDL? When does a vendor send me WSDL and what do I do with it ? I guess I can generate classes from it. If yes, then what do I do with the generated classes ?
When do I need that axis jar to generate classes from something that the vendor sends ?
As you can see, I have some clear and other mostly vague ideas about the different kinds of web services available. would help if someone ould clarify and\or point to more real-world resources. I've looked a little bit into Java Web Services on the internet and the numerous four letter acronyms that get thrown at me make me dizzy.
Thanks
If a vendor gives me a specific format
of XML that I can send populated with
data to request and I make a simple
HTTP POST over the internet passing in
the XML String as the payload, is this
a web service call ? If so, is there a
specific name to it, this kind of web
service ?
This is still a web service, yes. It doesn't have an "official" name, I usually refer to it as XML-over-HTTP, mainly because I can't think of a better name.
SOAP. How does this work?.. Ive read
the W3Schools tutorial and I
undertsand that there is a very
specific form of XML that is
standardized according to W3C
standards that we use to pass the same
kind of messages as we did in option 1
SOAP provides a standard wrapper layer around the sort of messages you were sending in (1). This wrapper provides information such as an indication as to which operation you are invoking. It can also provide security services, transaction information, and so on. It's a pretty thin layer, usually.
What about WSDL? When does a vendor
send me WSDL and what do I do with it
? I guess I can generate classes from
it. If yes, then what do I do with the
generated classes ?
Again, WSDL is a pretty thin layer, this time around an XML Schema. It defines the operations that SOAP messages will invoke at runtime, as well as the Schema types of the requests and responses. Its a way of formalising the XML document exchange interface.
Say, for example, you had an XML Schema, and have a web service as you described
Using JAXB to generate java source from the schema
Send XML documents conforming to that schema over HTTP to the web service
With WSDL and SOAP, you would extend this a bit :
Write a thin WSDL wrapper around the XML Schema, formalising which operations are available.
Use a WSDL import tool to generate client/server stubs for that WSDL/Schema. In Java, this often incorporates JAXB.
Use a SOAP client/server to invoke the web service
As you can see, it's essentially the same process. The difference is that SOAP/WSDL provides additional information and context to the tools, allowing those tools to do more of the work for you. It's not hugely different, though.
If you get a WSDL document from somewhere, all you really need to know is that it defines a service interface. You run it through your favourite language's binding generator to make some code that you can use to call the service. Typically that means you'll be talking over the wire to the service using SOAP messages over HTTP. SOAP's just a wrapper round sending pretty arbitrary XML messages.
Axis is a library for doing this stuff in Java (both client and server side). I suspect that there are better implementations in other libraries.