Consuming generic xml soap webservice in Java without wsimport - java

I'm searching for a way to consume soap webservices without using wsimport and tools like that. So far, everyting I found requires the wsdl artifacts generation and I want to avoid it because I don't know wich webservices will be used.
The idea is to give the user the possibility to add several WSDL's urls / methods and the program consume them and send it's response to another url.
I'm not looking for out of the box solutions/code or something like that.
What I need is to know if it is possible or not and how to aproach this problem, ideas and things like that.
Thanks!

SOAP mandates a contract between the Client and Server. The contract is that Client will give a request XML is XYZ format and Server will give response in ABC format. Without this, SOAP does not work. This is what is defined in WSDL. So we have to use WSDL.
Tools like wsimport, wsdl4j convert these WSDL files into an object hierarchy and prepares a JAXB wrapper for you, to make life easy!
Now if you do not want to use the tools which automatically convert WSDL to Java Beans or anything of that sort, note SOAP is based on nothing but an XML. If you know how to parse an XML in java, thats pretty much it. You can use a JAX Parser to achieve this and you can read everything that comes in a SOAP request and response.
The problem that you will face is, as the complexity of the SOAP XML grows, it will be difficult for you to parse the XML properly, identify the nodes, values and relations properly. And add to that the problem where in you cannot, without a proper object hierarchy , relate between nodes which are distance apart. Meaning, from line 100 you cannot go back and relate a line 10 node, unless you start maintaining your own objects, relations etc. (which is not what you want, i guess)
Using Java Beans the object hierarchy is maintained and because of that it is easy for you to relate them between different objects at different nodes easily. But JAXB is comparatively slower than JAX.

Related

Possible to generate Java class structure for SOAP request/response content

I'm currently building a web service client for an application that soon will be introduced in my company. I've never worked with SOAP before but I figured out that I could generate a WS consumer with JAX-WS using the wsdl file. Now I want to marshal/unmarshal my requests/responses content with JAXB. The content will be everything inside the SOAP:envelope. So I was wondering if there is a way where I can generate Java objects for all the requests/responses I want to use. There are a lot of similarities between the diferent requests/responses but also some differences. Is it possible to create a structure of classes where similarities get reused? Declaring it all by hand seemed like a lot of work. But if there's no way to generate it, I'm affraid I'll have to. Can anybody help me? Or is there another way I can work better with the WS client? Thanks in advance.

How to use Spring to sign a SOAP message as standalone application

I've got the need to be able to write a standalone application/function to be able to sign and verify SOAP based XML messages.
The catch is that this all needs to be done outside of any WebServices framework. I need to be able to pass my function my SOAP request as a string (XML format), and have my function produce an XML string response. The signature must sign several header elements (including custom elements) as well as the soap body.
Similarly, I need to be able to validate the signed response by passing it a string of XML and have it return a boolean.
Most of the documentation I've seen does one of two things.
Code everything by hand, manually altering XML elements (adding ids, namespaces, etc)
Rely on WS frameworks (AXF, JAX-WS, etc) to do the signing
I think that using a WS framework is significant overkill for my simple needs, but at the same time, I don't want to have to manually alter all the elements by hand.
Is there a fair compromise somewhere? Are there Spring libs that can help me find a middle ground?

HTTP + XML or SOAP for creating Web Services

I have created a web-service which involves accepting certain parameters in URL, validation the and returning XML response to client using JAXB xml library. Recently I came across JAX-WS framework which uses SOAP over HTTP to transfer request/response to/from client. Am I losing something by using simple servlet + connection pooling and serving XML response over HTTP ? Client will be hitting the URL created via some systems which are not known yet.
Is there any advantage to use REST or SOAP protocol, when simple HTTP + XML or JSON can solve the problem.
Sounds like you do not have any constraints over what you serve which leaves you with loads of options. There are quite a few angles to approach this question from, I just list some of the most obvious practical considerations below and leave out any architectural discussion.
SOAP is generally (but not always) used for enterprise integration - but it has a lot of shortcomings - not least in its verbosity. My advice would be not to use SOAP unless you really have no choice in the matter.
XML or JSON ? would your clients prefer to consume JSON or XML? If you are just publishing the service and not consuming it then I would go with JSON since it is becoming a very popular message format now for web services.
If you are the only one consuming the response then you need to think about what your client technology/framework would likely prefer to parse and how big the message payload is likely to be. If it is rich (loads of nested objects and attributes) then an XML schema might suit, but if the messages are very large then consider that the JSON footprint is likely to be smaller than the XML one.
You are not missing anything in your approach. Go for the simplest option - which depends on what framework/libraries you are using and the skill-set of your developer(s). If a servlet appears to be the most straightforward to you, go with that. If your data is already in XML then that seems like the way to go, but if not, I would consider publishing JSON format first. If you're not sure how to do that, first have a look at Jackson.
Update:
If you are still not sure which way to go then just serve JSON.
Also, the format of the messages you consume/publish should not dictate how you implement your application design - I mean, the question to use a servlet or not does not really factor into what message format to use, unless you intend to use a framework which ties you to a particular approach eg. Play Framework will very easily allow you to serve JSON from a Controller (not Servlet) so if you were using this framework - for example - you would not want to use a servlet and you would use JSON since that is the easiest way to go because of the out-of-the box support the framework already provides.

SOAP Request / Response Comparison Tool

Typically an enterprise application consumes a number of webservices. It is likely that some of these webservices that are being consumed will be upgraded to a new version every month. Before consuming the new webservice , the consumer must do a thorough analysis of changes between old service and new service which will form the basis of impact assessment.
I have come across tools that compare the WSDL , however some of the services that the application consumes could be huge and the WSDL might have more than say 50 operations. The consuming application might be using say 10 operations. By using WSDL comparator , it could be a bit tedious to identify if a modified element is part of a any of the operations consumed. In order to do such an analysis, I usually generate the request and response using SOAP UI for each operation and use text comparison tools to identify the difference.
Is there a tool available for performing of operation-wise comparison when 2 WSDLs are provided as input?
WSDL is eventually an XML document. The XmlUnit can come very handy in this case. Its essentially a utility for unit testing the XML application which make heavy use of XML. In the most trivialized for, it has a Diff class which actually compares the XML as follows:
Diff myDiff = new Diff("</Original>", "</Modified>");
But as I said, this is very trivialized. Please explore this for more details.
Also there is XML diff utility from Oracle.
Not sure if you the operation-wise comparison is possible or not.
Service Registry
It sounds like you are describing service governance. Some of the functionality you are describing can be provided by a registry above the functions of finding and publishing services.
http://wso2.com/products/governance-registry/
http://www-03.ibm.com/software/products/us/en/wsrr/
Maybe you want to generate classes from wsdl files using Eclipse WSDL2Java plugin or Apache CXF instead of generating each operation request and response, in my idea it can facilitate your work. Then compare the new classes with old ones using Devart Code Compare. Am i right?

JAX-WS returning a complex object?

Im pretty new to Java Web Services, but I cant find a good explanation anywhere.
I have 2 Java web projects within NetBeans.
One as a web service and one as a client for that web service.
I have also created my own class called "Person", which has what you'd expect: name, dob, etc.
I would like to have a web service method called "ListPeople()" that would return an array of "Person" objects.
Do I need to have that class in both projects?
Should I be serializing the object first?
Should I be using JAXB, if so, where do I start?
Sorry for the n00b questions, but im confused.
What is the normal way of accomplishing this?
Thanks in advance
Do I need to have that class in both projects? Yes.
Should I be serializing the object first? No.
Should I be using JAXB, if so, where do I start? I would not. I prefer the javax.oxm interfaces, because I don't care for JAXB, but that's a personal opinion.
My personal preference is to use Spring web services. If you happen to be a Spring user, I think that's the best way to go. If not, perhaps the docs will still help to clarify.
You're experiencing the reason why I don't like your approach: both the service and client and dependent on the class and OXM code. You have to have it in both places, in perfect synchronization. Change one and you have to change both.
I try to minimize dependencies if I can.
And in this case you can if you send XML back and forth. Start with an XSD schema. Let the client and service deal with that instead of Java objects. Your service will be usable for clients that aren't Java that way.
If you take this approach, you only have to worry about OXM on the server side. You take in the XML request and marshal it into the Java object of your choice and pass it to your service layer (note: NOT web service layer) for processing. Turn the response object into XML response stream and Bob's your uncle. Let the client deal with that.

Categories

Resources