Apache Camel received Status 400 Bad Request from AWS VPC Endpont - java

I have a Java application which was built with Apache Camel. The application uses Apache Camel to construct an HTTP request to AWS VPC Endpoint.
When the Java application sends out an HTTP request, it receives HTTP Status Code 400 (Bad Request). The VPC Flow Log can be found with the traffic (correct source and destination IP addresses).
On the other hand, if we use curl command to send the same HTTP request, it turns back 200 OK.
What is a possible cause? Is there any configuration in Apache Camel to see what is the exact HTTP content or raw HTTP header/message sent out?

You could check if Content-Type and other mandatory request headers are available at Exchange.in.headers. Just log in.headers within camel-simple tag. I think 400 happening because improper content-type or bad payload.

It might be that you are sending headers that are not allowed by the API since Camel maps message headers automatically to HTTP headers.
Camel's camel-http4 component uses Apache HttpClient 4.x library and you can configure it to log raw http requests.
For instance with log4j you would add to properties:
log4j.logger.org.apache.http=DEBUG
Detailed logging options can be seen from here: https://hc.apache.org/httpcomponents-client-4.5.x/logging.html

Related

Apache Camel HTTP Timeout

I am using Apache Camel route for HTTP call. I wanted to add timeout if there is delay from host system.
I am using the following configuration but it is not working. The client request is getting timeout without waiting host system timeout. The client timeout is configured in CXF but the camel timeout is configured in camel route. It should timeout in 4 second and it should go to error processor and but it is not happening.
HTTP
<setHeader headerName="CamelHttpQuery">
<constant>httpclient.soTimeout=4000&bridgeEndpoint=true&throwExceptionOnFailure=false</constant>
<setHeader>
HTTP4
<setHeader headerName="CamelHttpQuery"><constant>httpclient.socketTimout=4000&bridgeEndpoint=true&throwExceptionOnFailure=false</constant>
<setHeader>
Thanks
Please be attentive for syntax. Correct spelling
httpClient.socketTimeout=4000&bridgeEndpoint=true&throwExceptionOnFailure=false
But even after correcting parameters it will not work. Instead of configuring http endpoint you send your parameters as query string of request to server. For set up endpoint just add your parameters to it and use CamelHttpQuery header for request parameters.

Camel Http4 using basic auth and proxy auth

I've been trying to use Apache Camel's Http4 component to connect to a HTTPS URL that needs Basic authentication. The connection needs to be done through an authenticated HTTP proxy.
So, according to the docs, I configure the Camel endpoint like this:
.toD("https4://target.host/resource?
bridgeEndpoint=true
&mapHttpMessageBody=false
&proxyAuthHost=my.proxy.host
&proxyAuthPort=myProxyPort
&proxyAuthUsername=proxyUser
&proxyAuthPassword=proxyPassword
&proxyAuthScheme=http4
&authenticationPreemptive=true
&authUsername=myUser
&authPassword=myPassword")
Which results in a 403 - Forbidden response from the target server. Looking through the org.apache.http.wire logs, it shows that the proxy credentials proxyUser / proxyPassword are forwarded to the target server instead of the intended myUser/myPassword in the Authorization header.
Debugging the source for CompositeHTTPConfigurer.configureHttpClient, ProxyHttpClientConfigurer.configureHttpClient and BasicAuthenticationHttpClientConfigurer.configureHttpClient, it seems that because both configurers are setting their credentials to the HttpClientBuilder by means of setDefaultCredentialsProvider, one of them is lost - gets overwritten - in the process.
Looks like it could be a bug in Camel's Http4 component? Or am I missing something?
This is Camel 2.18.2 with Spring Boot 1.5.1.RELEASE.
After raising this question on the Apache Camel Users list, it seems the bug is confirmed.
I solved it using camel-http instead of camel-http4. Endpoint parameters needed a slight tweaking:
.toD("https://target.host/resource?
bridgeEndpoint=true
&proxyHost=my.proxy.host
&proxyPort=myProxyPort
&proxyAuthUsername=proxyUser
&proxyAuthPassword=proxyPassword
&proxyAuthMethod=Basic
&authUsername=myUser
&authPassword=myPassword
&authMethod=Basic
&httpClient.authenticationPreemptive=true")

Test Soap webservice using jmeter with http request

i have a question for you guys, do you know a way how can i send http request with jmeter to my soap webservice(jax-ws library)?. I have a problem to point server name or ip(its localhost so should it be loopback?) and path. I'm using glassfish4 as my web server. I do not want to use option SOAP/XML RPC Request, because when i use it with my web service i can't see that any data have been sent(it's always 0 -in fact maybe you have idea why is that...it's also a solution to my problem because i need http request to see how much data i've sent)
!https://postimg.org/image/mpbai5n1v/
Thanks in advance
Regards!
Use:
Http Request and fill in:
Server Name or IP
IP if different from 443 or 80
Protocol if https
Add a Header Manager under it with :
Content-Type=text/xml; charset=utf-8
Note there is a template that lets you easily create this, see screenshot:
Finally I suggest you read this tutorial:
http://jmeter.apache.org/usermanual/build-ws-test-plan.html

Getting large response from Http Outbound Gateway in Spring Integration

I am trying to get response from Http Outbound Gateway. I have used expected-response-type="java.lang.String". I am able to get data, data is string representation of XML, but data is large so I am getting only part of it, I am not able to find a way to get full data.
In documentation they have given example to use Multipart with Http Inbound Gateway their is no reference how to use Multipart in Http Outbound Gateway.
I also came to know that http outbound uses RestTemplate to make calls but I was not able to figure out how can I inject my own RestTemplate in Http Outbound Gateway.
Is their any way in XML configuration where I can insert some configuration and I may get full response in Http Outbound Gateway.
just for refrence here is my Http Outbound Gateway:
<int-http:outbound-gateway request-channel="requestGatewayChannel"
url="${myurl}" http-method="GET" expected-response-type="java.lang.String"
</int-http:outbound-gateway>

JAX-WS + SOAP: How to parse HTTP Client Error

I'm using JAX-WS + SOAP to communicate to a webservice. I can handle the SOAP message (handleFault) but i cannot understand how to catch HTTP errors, because they occur under the HTTP Java client layer...
com.sun.xml.ws.client.ClientTransportException: The server sent HTTP status code 412: Precondition Failed
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:203)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:177)
at com.sun.xml.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:93)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:598)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:557)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:542)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:439)
at com.sun.xml.ws.client.Stub.process(Stub.java:222)
at com.sun.xml.ws.client.sei.SEIStub.doProcess(SEIStub.java:135)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:109)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:89)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:118)
I know the server should include an entity containing an explanation of the error situation (and, in fact, i've been told it's doing just that).
My question is: HOW to reach that "entity"?
Looks like web service is not implemented according to specification. According to W3C Note 08 May 2000 on SOAP 1.1 (same with SOAP 1.2):
In case of a SOAP error while processing the request, the SOAP HTTP server MUST issue an HTTP 500 "Internal Server Error" response and include a SOAP message in the response containing a SOAP Fault element (see section 4.4) indicating the SOAP processing error.
Even if there is some "entity" I don't think you should handle that in your application. It would be definitely a hack. If you need to learn what entity is it only once, just use some sniffer tool like Wireshark.
If you really want to ignore HTTP status code you can switch to CXF as a JAX-WS implementation. There you can disable checking HTTP code:
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(hw);
client.getRequestContext().put("org.apache.cxf.http.no_io_exceptions", "true");

Categories