XML Binding via Web Service (or JAXB) - web-services

I have to maintain a Java EE 5 web app.
A part of this app is the exchange of messages through web services (with WSDL contract).
The wsdl is used to generate the Java classes through the Eclipse wsdl2Java (I think it uses Axis)
Now I have to implement a modification where the server that we call via Web Service must be able to respond in an async way.
In fact the server will not respond immediately with the SOAP message response but, after a while, call a web service exposed by the client (our web app)
passing the SOAP Message response of the first call as a field (parameter) of this second Web service invocation.
The client then will save the SOAP response (or XML) in a file.
Is there a way to populate the already generated Java classes using this XML or SOAP message file? I mean a way to simulate the direct response of the server (feeding the Axis binding Stub)
I have also tried to use JAXB (to bind XML to JAVA) but since the SOAP message response is complex, when I call JAXBContext I receive an error:
CodPrestazione does not have a no-arg default constructor
since this class is an enum class generated by the wsdl2Java.
Is there a way to bypass this error without annotating or modifying the java class (this class is generated so I will be forced to modify this class at every re-generation)?
What is the best way to consume a saved SOAP message file(or XML)? Alternatively, how can I deserialize SOAP using Axis 1.3?

Related

Oracle Service Bus multiple operations inside exposed SOAP service

Currently I am developing a ws with OSB using JDeveloper 11.
I have a simple web service, which calls an external SOAP service.
My composite.xml file:
Operations of my BPEL Soap service
Operations of remote SOAP Service
BPEL Component
I have few questions regarding the current development strategy. How shall I add new operations to my BPEL SOAP? I added a new method (getCompanyDetails()) by editing ApusBPELProcess.xsd (added new request and response types) and ApusBPELProcess.wsdl (added new operation, message and etc). Is this the correct way for adding new operations?
Now I can call only one method of the remote SOAP service by using an "Invoke" component from BPEL constructs.
My BPEL design:
How can I call bind a method from my BPEL SOap (1) to a method from remote service (2) ? For example: when client calls method process from my BPEL Soap (1), I want to do some validation on input parameters and then call getServiceCompanies from remote SOAP (2). And so when client calls another method from BPEL Soap (1) I want to call some other methods on remote SOAP (2).
Will be very thankful if someone can show me a diagram, with required components. Because I read about "Mediator" components, but I don't know how to use them in my current situation.
Thanks in advance.
One option is, You can use Pick activity that can have multiple onMessage branches for each operation exposed by your BPEL service.
Similarly, Invoke activity has an option to select the operation of the Remote SOAP service that you need to call.
So your composite would look like Pick activity with an OnMessage branch with BPELoperation1 selected, then logic to do validation and then invoke with remoteoperation1 selcted.And another onMEssage branch with BPELoperation2 selected, logic to do validations and invoke with remoteoperation2 selected.
I found a solution with Mediator component. Maybe it will help someone.
Ok, I added a Mediator component between my exposed service and remote service. Mediator component will do request routing and data transformation between these two services. For each method in my exposed service I added a BPEL process to the other endpoint of Mediator (I will do some method specific validation/other logic inside these BPEL processes).
My final composite.xml:
Methods of my exposed service
Mediator
The remote service what I call
Inside Mediator component I do routing and transformation. For each method of my exposed service (1) I have a routing rule in Mediator (2).
Mediator component rules:
4a, 4b - Methods of my exposed service
4c - button for adding new routing rule
4d - button for adding transformation rule (generally you will have a pair of transformation rules for a method - request/response)
Transformation files are .xsl files that do information convertion between two endpoints.
My .xsl files:
Content of a .xsl file:
Here I am doing iteration through the response data (for-each component).
And finally inside of each BPEL process I have an "Invoke" component (5) which calls the appropriate method on the remote service.
Hope it will someone. Good luck!

SoapUI: Create mock service with pass-through behavior for selected methods

While developing a web application I have the following use case:
a 3rd party Web Service with quite a lot of methods is deployed on a test server A (with a single endpoint, e.g. http://3rdPartyServer/3rdPartySvc?WSDL)
a new method is about to be implemented in the near future, but I need to use it now
the rest of the methods are used throughout my code extensively
So I would like to do the following:
Create a mock service in SoapUI locally, based on the new WSDL which includes the new WS method (i.e. a superset of the WS methods currently on server A)
point my local application server to use the SoapUI mock service endpoint
mock only the response of the new WS method (create a dummy response for it in SoapUI)
let the other WS method calls to reach server A and return whatever it returns normally (i.e. use SoapUI as a proxy for these calls)
I've gone through the SoapUI documentation regarding service mocking and have used it numerous times, but could not find an option for such "pass-through" behavior.
When you read in your WSDL, the endpoint will point to your server.
Open your service, and select the service endpoint.
Add a second endpoint, to point to your mock. SoapUI has little bit of documentation showing this here. Only step "2. Getting Started" applies, not step 3!
In each of your tests, where you are using the mocked method, you will need to select the mock endpoint. Further discussion is here.

How to handle SOAP service within persistent Perl web application with cookies?

Due to the fall of SOAP::WSDL which had generated me real Perl modules I have to look for something other in order to handle a SOAP service. The generated modules won't work starting from Perl v5.18.
I have the following situation with my web application.
I have a PSGI compatible, Dancer2 driven, persistent web application.
The web application handles multiple concurrent customers.
The web application is between the customer and an external SOAP service.
The SOAP service uses customer sessions via cookies which have to be integrated on the web application internally for the customer.
The web application holds an WSDL file copy of the SOAP service.
I'm looking for a module that creates an interface out of the WSDL file and handles parameter/schema validation and communication with the SOAP service. I would like to call a method (SOAP call) with parameters (SOAP call parameters) and receive a cleaned data or object structure of the response.
The problem is that the web application needs to handle multiple concurrent customer cookie sessions. So I need a module which offers the possibility to override the cookie jar for that particular request and extract the cookies after the request without causing interference with other concurrent requests.
I found XML::Compile which I can initialize as a singleton at web application start up. But with this solution I ran into problems with interfering other customer requests. So the requests are not separated. Initializing XML::Compile for every request is not the solution either because it will parse the WSDL and generate handlers over and over again for every request the customer sends to the web application.
Is there any solution/module that fits my needs or do I miss something with XML::Compile and it's possible with it?
Are you using Catalyst?
I've been happy using Catalyst::Controller::SOAP and its companion Catalyst::Model::SOAP to build SOAP/WSDL servers and consumers, being able to integrate Perl Applications even with Microsoft Document Literal-Wrapped thing.
Even if not using Catalyst you may probably learn from its code. It uses XML::Compile::WSDL11.

Apache CXF Request/Response

I am working on an application that I want to use to catch a SOAP request when it goes into the CXFServlet. There is some processing I need to do to the SOAP envelope on the server side, before the CXFServlet processes it.
I have been presuming that the SOAP envelope, once it reaches the server side, is one of the parameters in the HTTPServletRequest object. But looking at what comes in (using a debugger, of course), I cannot find it.
Can someone tell me where the SOAP request goes when a client sends it to the server? I know that the client is sending the request using an HTTP POST, and I know that the server is using information in the request in order to access the appropriate web service method, then placing any return values from the method into a SOAP response and returning it to the client. What I need to know is where where does the CXFServlet (or one of its filters) look in order to get the SOAP information? Is it somewhere in the parameters? In the servlet context? Does a filter process the SOAP information before it gets to the CXFServlet? How can I get that envelope and do things to it before the web service method is called?
Someone please advise...
Do you want to access the original request ? If yes the actual request or response object itself can be accessed using the WebServiceContext object.
First, declare a private field for the WebServiceContext in your service implementation, and annotate it as a resource
#Resource
private WebServiceContext context;
Then, within your implementing methods, you can access the MessageContext, HttpServletRequest, and HttpServletResponse as follows:
MessageContext ctx = context.getMessageContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(AbstractHTTPDestination.HTTP_REQUEST);
For more info about WebServiceContext see the following url :
http://docs.oracle.com/javase/6/docs/api/javax/xml/ws/WebServiceContext.html
If you need to intercept the request before it is ever processed by the CXFServlet, you should look at developing a Servlet Filter.
If you just want to process the SOAP message before CXF does, you can likely use a CXF Interceptor. The phases noted in the documentation indicate the points you can intercept the message. Depending on what you want to do/change, you may need to play around with the phases.
The source for CXF's SoapHeaderInterceptor or SoapActionInInterceptor would be good places to start looking at how to work with the SOAP message.

Client Generation in web service(jax)

I made a web service endpoint and exposed a method now i wanna add more parameter to my method
so each time i change in my method i have to regenerate my client. Is there any way so that i
dont have to generate my client again and again.
No, there is no way. If you change the method then the WSDL file is changed also. Web services communicates through SOAP between client and server. When you deploy your web service application and it has been changed, so how then client supposed to know if there is a new method or a new parameters added if the classes was generated from the old WSDL file. Client will send a SOAP request according to the old WSDL and the server won't be able to understand the SOAP message received from the client if there was any changes made to WSDL part related to the received message.
You could design a better webservice/endpoint that accepts a standalone xml document as argument so that the operation signature stays the same, even when you add more parameters.
More generally, it's bad form for a web service to expose it operations as literal method signatures.