How to call soap web service from camel rest java DEL - rest

I am trying to call soap web service from camel rest, from java DSL. but getting server error with 500 response code.
I will receive call from a rest with json data and i have to make call to a third party soap service also i need to process the soap response and send back the response in json formate.
here is my code
{
String getCustomerDetailsurl="http://<serverip>/webservice/Service.asmx?op=GetClientDetail&bridgeEndpoint=true";
rest("/customers")
.description("Aviva Mobile sales customer service")
.consumes("application/json")
.produces("application/json")
.post().type(ClientRequest.class) // incomming request data
.route()
.from("direct:start")
//.setHeader(Exchange.HTTP_METHOD, constant("POST"))
.process(new CustomerProcessor()).marshal().xstream()
.to(getCustomerDetailsurl);
Error
org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://<serverip>/webservice/Service.asmx?op=GetClientDetail with statusCode: 500
at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:239) ~[camel-http-2.17.5.jar:2.17.5]
at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:161) ~[camel-http-2.17.5.jar:2.17.5]
at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) ~[camel-core-2.17.5.jar:2.17.5]
at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:145) ~[camel-core-2.17.5.jar:2.17.5]
at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77) ~[camel-core-2.17.5.jar:2.17.5]
at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:468) ~[camel-core-2.17.5.jar:2.17.5]
}

You have to look at Server side for what actual error is.
You may use some tool like tcp monitor (tcpMon) to see exactly what you send and what you get back.
Actually, To use SOAP service it is much better to use SOAP client, rather than raw call through http. Take a look at Camel-CXF component. Then create a CXF endpoint and use it uri in your .to({cxfEndpointUri}). CXF will do all SOAP work for you. Maybe you will need to make a little work in its interceptors, like authorization if Server requires it.
P.S. In your code what kind of Exchange.body your CustomerProcessor produces? is it a valid for server SOAP Envelope? does it have all what server requires by its contract (WSDL)?

Related

Using JSON Search Queries with a GET request in JMeter

My org is trying to use JMeter as part of a test automation suite to test some back end REST APIs. Currently one of them supports using JSON queries as a way to get filtered results back from a GET request.
We are using the JMeter UI to create these tests and since all the other API calls work under the HttpClient3.1 HTTP Request implementation that is the implementation that I am currently using to get this to work. With this implementation I get the following when looking at the failure in the results tree (response data portion) I have made the error slightly more generic to protect some IP:
java.lang.IllegalArgumentException: Invalid uri 'https://server:port/restservice/v1/users?firstname_query={"in":["User1FirstName","User2FirstName"]}': Invalid query
at org.apache.commons.httpclient.HttpMethodBase.(HttpMethodBase.java:222)
at org.apache.commons.httpclient.methods.GetMethod.(GetMethod.java:89)
at org.apache.jmeter.protocol.http.sampler.HTTPHC3Impl.sample(HTTPHC3Impl.java:229)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy.sample(HTTPSamplerProxy.java:74)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1146)
at org.apache.jmeter.protocol.http.sampler.HTTPSamplerBase.sample(HTTPSamplerBase.java:1135)
at org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434)
at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261)
at java.lang.Thread.run(Unknown Source)
I have also tried the same request using the Java implementation and get a similar result.
If anyone has any ideas or if you need more information let me know and thank you again in advance for any help you may be able to provide.
Your HTTP Request configuration is a little bit incorrect. JSON entities contain braces {} which are not allowed in URLs so you need to encode them.
Configure your HTTP Request sampler like:
Make sure "Encode" box is ticked.
And this way you will be able to send JSON with HTTP GET Requests. You can use View Results Tree listener to inspect request and response details:
You might also need to add HTTP Header Manager to your Test Plan and configure it to send Content-Type header with the value of application/json. See Testing SOAP/REST Web Services Using JMeter article for more details on properly configuring JMeter for testing REST APIs.

RESTful services with AXL

I am trying to create a few restful webservices that will add a bit functionality to the company cisco phones. The basic idea is simple, the users get a small client on which they need to enter login and password. When they have done so, their phone/phones are 'registered' to my restful service and they get added functions on their phone. When they log out, they get unregistered. To provide the extra functions (like adjusted caller information etc etc) I need the Cisco AXL API. This is a SOAP based API. I have generated the java classes using the wsdl already. When I make a testclient using the generated classes, all works fine.
But here comes the problem: When I try to run a soap request while my application is deployed on my Tomcat 7 container, it doesn't work anymore.
The problem seems to be the AXLAPIService, which hangs when executing the following piece of code:
#WebEndpoint(name = "AXLPort")
public AXLPort getAXLPort() {
return super.getPort(new QName("http://www.cisco.com/AXLAPIService/", "AXLPort"), AXLPort.class);
}
In other words, i am not getting a port for the soap request and it makes the tomcat crash i f you wait long enough.
I went googling. Somebody on some forum once had a problem because of an out of date stax version. I adjusted the stax version in my POM and tried again, to no help.
I also read somewhere that the underlaying javax.xml.ws.Service actually has an enumeration of ports, and when you do getPort(), you will get the most appropiate port. I then looked up the default port for SOAP and that would be 80, just like the port used for RESTful services. Could it be that the soap service would be wanting port 80, but that it can't have it because it is already in use?
So, to summarize my question:
can it be that my restful services consume the same port that my soap
request would want to use?
if not, what could be the problem then and how should I fix it?
As additional information, this is how the axl wsdl defines the service:
<service name="AXLAPIService">
<port binding="s0:AXLAPIBinding" name="AXLPort">
<soap:address location="https://CCMSERVERNAME:8443/axl/"/>
</port>
I was thinking about changing the soap port myself. Some googling tells me I should do that in the wsdl but I wouldn't really know how. There is post already here but I fail to see how binding another portname could help me out....
As with so many things involving Cisco Telephony and their Administrative XmL (AXL), I found a workaround instead of an actual answer. Since a problem never really leaves my mind, I spent the rest of yesterday trying to find a solution for getting information out of that AXL thing.
Any actual answers to the above questions are still welcome though.
The workaround I found is this: Since SOAP can be seen as a special http POST request, it should be possible to do a SOAP call using a REST framework such as Jersey. You just need some extra code to make it work. I used the 'SoapProvider' from the link and for those who are also wrestling with this, I'll add my code:
public void doSoapRequest() throws SOAPException, JAXBException{
ClientConfig config = new DefaultClientConfig();
config.getClasses().add(SoapProvider.class);
Client c = Client.create(config);
c.addFilter(new LoggingFilter());
c.addFilter(new HTTPBasicAuthFilter("user", "password"));
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage message = messageFactory.createMessage();
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope envelope = soapPart.getEnvelope();
SOAPBody body = envelope.getBody();
SOAPElement bodyElement = body.addChildElement(envelope.createName("getCCMVersion", "", "http://www.cisco.com/AXL/API/8.5"));
message.saveChanges();
WebResource service = c.resource("https://youraxlmachine:8443/axl/");
// POST the request
ClientResponse cr = service.type(MediaType.TEXT_XML).header("SOAPAction", "\"https://youraxlmachine:8443/axl/getCCMVersion\"").post(ClientResponse.class, message);
message = cr.getEntity(SOAPMessage.class);
JAXBContext ctx = JAXBContext.newInstance(GetCCMVersionRes.class);
Unmarshaller um = ctx.createUnmarshaller();
GetCCMVersionRes response = (um.unmarshal(message.getSOAPPart().getEnvelope().getBody().extractContentAsDocument(), GetCCMVersionRes.class)).getValue();
System.out.println("HERE COMES THE VERSION!");
System.out.println(response.getReturn().getComponentVersion().getVersion());
}
I have left as many things unchanged as I could, except for the company specific details. This code works for getting the CCM version.
WARNING: Depending on how you perform the request, you might get a different result for the same request. I'll explain:
I have implemented other AXL methods as well, such as getUser. Before I even coding the Jersey soap service, I tried everything with SOAPUI. So I setup the SOAPUI so I could do RESTful requests to the AXL server. Using my restful setup in SOAPUI, I get the same results as I when would do the standard SOAP calls using both SOAPUI and my first implementation of a soapclient in java.
But when I use the jersey client to do the same getUser request, some important fields are missing from the result. I have no clue what could have caused this. For the request getPhone, I dont even get a valid response. So be warned.

Create WSDL message from SOAP Response

I have a WSDL that contains a different response then the actual responds with. I want to update the WSDL with the format of the API response but am having trouble. Is there a tool to generate a WSDL response from SOAP XML?
I should mention that they gave me the WSDL as a file, no public WSDL is visible.
The response contains this unknown anonymous xml element, s-gensym3. It should be userid.
If it's a .NET web service you can browse to [serviceurl]?WSDL to get the WSDL.
There's surely service endpoint you communicate with. You shall be able to invoke this endpoint in the browser and add to the end:
?wsdl
i.e. http://service:8123/operationName?wsdl
This will print you entire WSDL. Just make sure you have the same and you're done.

Adding More parameters to REST HTTP GET

I am trying to access a REST web service using HTTP GET request.
For a example following URI provides Rest web service that return all the available parts for the given category.
http://localhost:8080/mycompany/parts/category
I want to authenticate/authorize users who are accessing above REST request in each time and I want to pass User authentication details (User Name and Token) with the HTTP Get Request.
Is there a possibility to cater to the above requirement in REST HTTP GET request (using HTTP header or query parameters)?
or
Is it better to use HTTP POST instead of HTTP GET?
Since you are getting information, you should use "Get". Here's the code that I use (it is Restlet based) for adding the oauth_token to the request...
import org.restlet.data.Reference;
import org.restlet.ext.oauth.OAuthUser;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
Reference commitsRef = new Reference(Consts.RESOURCE_BASE + "commitments/");
OAuthUser u = (OAuthUser) request.getClientInfo().getUser();
String token = u.getAccessToken();
ref.addQueryParameter("oauth_token", token);
ClientResource commitsResource = new ClientResource(getContext(), commitsRef);
Representation commitsRep = commitsResource.get();
As mentioned, this is Restlet based, but there is probably something similar in the framework you are using. (And if you are not using a framework, Restlet can make this easier).
if you are using restlet than good because restlet have rich api for rest framework
but without this if you want to authenticate than
you can do same thing with GET or POST
but send your credential data trough cookie
and read same cookie using #CookieParam from server side
in this way you can easily authenticate user.

Add Request SOAP-Header to Response

I am working on an bottom up web service for axis2 deployed on tomcat.
The processing is all working, but for tracking purposes I would like to include some meta data using the Soap Header. Do you know how to make axis2 include the header received into the response? E.g. I would like to pass an id with the header and receive it with the response.
The way to handle these scenarios in Axis2 is to use a handler. You can engage your handler to the out flow and do the header adding part is there. This article[1] describes about the axis2 architecture and how to add new handlers using modules.
[1] http://wso2.org/library/articles/extending-axis2