Not able to get output from camel routing - rest

I have defined a camel context with a camel route and I am having below code.
from("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/camelRouter?matchOnUriPrefix=true").
to("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/getPersonData?bridgeEndpoint=true&throwExceptionOnFailure=false")
.to("jetty:http://localhost:9090/camelcxfdemo/rest/cxf/processPersonData?bridgeEndpoint=true&throwExceptionOnFailure=false")
.to("log:output");
All the three urls shown above are Rest services which takes some post xml and return xml response.
I want my camel router to start working when /camelRouter is called and its output should go to /getPersonData url and the output of /getPersonData go to /processPersonData. And to user I should finally display the output of /processPersonData.
So each url is dependent on it's previous urls output.
But the problem is when I invoke /camelRouter url, I always get /camelRouter response, not the final output. The output is not routing from one service to other.
So is there is any probelm in my code? Hoping for some help.
Thanks

It appears to me that the Jetty component can be used as either a producer or consumer but not both as you appear to be attempting to use it.

Related

Add common auth header to all camel restlet route

I have a big set of routes
from("restlet://api1").to("dest1-rest-url");
from("restlet://api2").to("dest2-rest-url");
from("restlet://api3").to("dest3-rest-url");
..
from("restlet://api100").to("dest100-rest-url");
All the routes are spread across different files.
Now, all the destination rest url require a AUTH header to be set. It would be tedious to set at each and every place.
Is there a way, I can set/configure a header , that is appended before calling any rest API.
IMHO a possible and elegant solution would be to play with Camel interceptors.
Using wildcards on "interceptSendToEndpoint", you should be able to intercept all calls to "restlet*" (or "http*" endpoints) in order to insert/add an "Authorization" http header before continuing the route.
More info here:
http://camel.apache.org/intercept.html
Adding an answer that solved part of my problem
interceptFrom("restlet*").process( e -> { e.getOut().setHeader("Authorization":"Basic <authkey>"); });
Note : You may have to set the other parameter such as Content Type, HTTP Method , Other header, body from Incoming exchange to out going exchange.

Play 2.6 using Logging Markers to carry request uuid similar to Java MDC

I'm trying to use Logging Markers to carry contextual information during the whole cycle of a request. Basically, I want to assign a uuid to a request and after that, all logging related to that HTTP request, should print that request uuid.
https://www.playframework.com/documentation/2.6.x/ScalaLogging#using-markers-and-marker-contexts
I see the example with logstash, but I don't use logstash.
I know it can be done with the MDC. Can/How can it be done with Logging Markers ?
You don't say what your logging configuration looks like. The examples from your link use the marker to annotate each log entry. If you go to the next link, SettingsLogger, you will see how to configure logback to print out your logs to a file. You will need to modify the layout encoder to add "%marker" to the pattern layout. For instance,
"%-5level (%marker)[%thread]: %message%n"
will print out your log item with the UUID just before the thread name.

How can I pass a parameter from XML Response tag in a new GET XML Request in Soap UI?

I have tried to find a solution in this community in different threads but yet to find one that I am looking for.
I am using SoapUI version 5.3.0 My Application have a couple of RESTful APIs. Initially I am sending json request to a WebService and getting back the following XML Response:
<StartDataExtractResult xmlns="http://schemas.datacontract.org/2004/07/AriaTechCore" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<StatusCode>1</StatusCode>
<StatusText>success</StatusText>
<RequestNumber>397</RequestNumber>
</StartDataExtractResult>
As soon as RequestNumber tag is generated. I have to access to 2 more XML EndPoints (where the value of RequestNumber is appended) to know the Status as below:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/396
B.
http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/396
As of now, I have created the 2 seperateTestSteps for the above mentioned XML Endpoints:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/
B. http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/
Now I need to append the value within tag in the GET Request to get back a response from the WebServices.
Update:
I have created a 'Property Transfer' at Testsuite level as "TSreqNum". This 'Property Transfer' is getting updated as per the initial Response. But I am not sure how would I append "TSreqNum" to construct the complete GET Request as:
http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/TSreqNum
Can anyone help me out please?
You can use the property within the URL of the GET request:
http://host:port/path/${#TestSuite#TSreqNum}
The URL gets updated with the property value.

How to produce both xml and json for a rest based service?

I am trying to produce both xml and json from my rest service.
#Produces({"application/xml", "application/json"})
However, when I try to use the service using curl/SOAPUI, I get back either xml or json depending on which is mentioned first. In simple words, only the first method is considered. Is there a workaround?
You should check this link out - oracle docs for #Produces
The spec says that it does indeed default to the first one if that is acceptable as specified by the media type on the request. You should check your soapUI tool and see what headers you are sending. If they are both being sent you will get a response with the first one listed in your #Produces annotation.

WSDL Cannot find dispatch method for

For a web service call using a WSDL, I'm getting the error Cannot find dispatch method for {http://ws.somecompany.com/services}ValidateUser, what does that mean exactly? Does it mean that it cannot find ValidateUser?
This typically means that the SOAP framework could not find the operation that should be invoked via this request. A SOAP framework typically inspects the message to find pointers about how to route the message to the operation. Reasons for this error are mostly configuration issues (different namespaces, different encodings (RPC vs. doc/lit), usage of WS-Addressing vs. plain SOAP etc.)
I had a similar problem and struggling, googling for 1 day. But it was a simple mistake that instead of:
{http://ws.somecompany.com/services}ValidateUser
It should be
{http://ws.somecompany.com/services/}ValidateUser
I had not checked my WSDL clearly.
In my case I solved by making sure that my config file either app.config or web.config depending on your client has correct endpoint. I had wrong address in my endpoint. I changed it and it worked fine.
I also lost a day to this issue, albeit with a different root cause.
In our case, two similar endpoint urls had got mixed up in the properties file. Both services were present and running, but the WSDLs didn't match up, so instead of a ConnectionException, we were getting this SOAPFaultException: "Cannot find dispatch method".
My fifty cent, I got same error message but my case was yet different from all above, so hopefuly it might help someone.
I had .wsdl file, which got outdated without my knowledge when colleagues on the other side of ws renamed some element. Unfortunately, change was not visible when I compared .wsdl with theirs because .wsdl file had .xsd import which actually contained renamed element. After I found change, I updated my .xsd file and tada! error is gone and it worked.
In my case, the following exception was throwing even I've supplied all the parameters
SoapFault exception: [S:Client] Cannot find dispatch method for {}parameters in
After banging my head few hours, just adding a \ while initializing SoapClient solved the problem.
From:
$client = new SoapClient($soapURL);
To:
$client = new \SoapClient($soapURL);
I had the same issue in my .NET Application, In my case setting url same as "http://x-xxx-xx-xx-01:8080//TestProject/testproject?wsdl" (dummy url) solved the problem in the below code.
Vb.Net
Dim rptGen as WSTestProject.testproject = Nothing
rptGen = New WSTestProject.testproject With {
.Url = "http://x-xxx-xx-xx-01:8080//TestProject/testproject?wsdl",
.Timeout = 1200000
}
Here, WSTestProject is the WebService NameSpace and testproject is the web method.
I am using a feign client for soap and I had the similar issue,Adding the correct namespace to the JAXB request and response object resolve the issue.
The issue was in my environment was the wsdl cache in php. The updated wsdl was not picked by the client and it was referring to the old wsdl.
You can do either one of the following options when you do the development of the web service and test, as the wsdl change during the update/implementation of the web service
Add WSDL_CACHE_NONE to soap client creation
$myServices_client = new SoapClient($myServices_wsdl_URL, array('cache_wsdl' => WSDL_CACHE_NONE) );
Set initialization parameter
ini_set("soap.wsdl_cache_enabled", 0);
Adding '/' will work for you.
Error: Cannot find dispatch method for {http://zzz.com}servicename
Not Working Request: xmlns:ser='http://zzz.com'>
Working Request: xmlns:ser='http://zzz.com/'>
I picked up an old Java project. I am not sure how it worked before, but I saw similar error and the reason was in wrong SOAP HTTP endpoint binding at server side.
Doesn't work:
Endpoint.create(HTTPBinding.HTTP_BINDING, servicePortType);
Works:
Endpoint.create(SOAPBinding.SOAP11HTTP_BINDING, servicePortType);