1

I just can't get this HTTP4 working. I'm trying to do a POST request to a site that is https. however, nothing seems to work. can someone tell me what the right way is to perform a HTTPS POST with HTTP4 ? thank you so much, really struggling. just need to know what I'm doing wrong... something simple always turns south.

I've tried.

http4://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token
https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io/oauth/token
http4://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io/oauth/token
https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token
http4:https://d1e5-95edc7a5cef2-uaa.run.aws-usw02-pr.ice.io:443/oauth/token

but nothing seems to work?

Astrid
  • 1,808
  • 12
  • 24
GLMills
  • 558
  • 1
  • 12
  • 37
  • First, I don't think `http4://` is what you want. I don't think it's a URL protocol designator. For https to work, you have to establish a secure connection. Try googling `establish https session` to get started. If you try and fail, post a more specific question on StackOverflow. See [How to post](https://stackoverflow.com/help/how-to-post), and post a [Minimal, Complete, Verifiable Example](https://stackoverflow.com/help/mcve). – Jeff Learman Apr 24 '18 at 23:14
  • Do you mean `https4://` (Notice the `s` in `https4://`)? See also the chapter **Setting up SSL for HTTP Client** in the [http4 Camel Docs](https://github.com/apache/camel/blob/master/components/camel-http4/src/main/docs/http4-component.adoc) – burki Apr 25 '18 at 06:16
  • thanks burki, no, I'm meaning http4. – GLMills Apr 25 '18 at 17:54

3 Answers3

1

Please use bridgeEndpoint=true so you can go outside the server

0

camel-http4 component is suitable for what I am trying to achieve. I only need to produce to an endpoint. I am not trying to expose a web service. But, thank you for your response.

camel-http4 vs camel-jetty

You can only produce to endpoints generated by the camel-http4 component. Therefore it should never be used as input into your Camel Routes. To bind/expose an HTTP endpoint via a HTTP server as input to a Camel route, use the Jetty Component instead.

I found that the proper way to define a HTTP4 endpoint is

http4:hostname[:port][/resourceUri][?options]

the issue I am having is with the dynamic toD route, and the substitution of the Exchange.HTTP_URI setting, this is not working as it should.

therefore, using a uri such as

http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.uaa.run.aws-us.ice.io:443/oauth/token

works. the mechanism, isn't working.

Exchange.HTTP_URI

The URI to call. The value of this option will override the existing URI that's set directly on the endpoint. It's not the same as the Camel endpoint URI, where you can configure endpoint options such as security etc. This header does not support that, it's only the URI of the HTTP server.

    <route 
        id="core.getToken.route"
        autoStartup="true" >
        <from id="getToken" ref="getToken" />
        <process ref="uAARequestTokenProcessor" />
<!--        <log message="Message after uAARequestTokenProcessor:  ${body}" loggingLevel="INFO"/>   -->
         <setHeader headerName="CamelHttpMethod">
            <constant>POST</constant>
         </setHeader>
<!--         <setHeader headerName="CamelHttpUri">
            <simple>${header.TOKENURL}</simple>
         </setHeader>  -->
        <log message="HTTP4 POST headers: ${headers}" loggingLevel="DEBUG"/>
        <log message="HTTP4 POST body: ${body}" loggingLevel="DEBUG"/> 
        <to uri="http4://d1e-uaa.run.aws-usw02-pr.ice.io:443/oauth/token?throwExceptionOnFailure=false" />
        <toD uri="${header.TOKENURL}?throwExceptionOnFailure=false" />
        <log message="After HTTP4 POST: ${body}" loggingLevel="INFO"/>
        <to uri="{{accessToken}}" />    
    </route>    

so for me right now, setting the Exchange.HTTP_URI isn't overriding the URI defined in the endpoint

where Exchange.HTTP_URI is defined as : TOKENURL=http4://d1e53858-2903-4c21-86c0-95edc7a5cef2.uaa.run.aws-usw02-pr.ice.io:443/oauth/token

this is what is not working. thanks.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
GLMills
  • 558
  • 1
  • 12
  • 37
  • I'm going to play around a little more, I'm thinking it is something to do with the way I define the URI in the Exchange.HTTP_URI. maybe it shouldn't include the http4 part IDK ??? – GLMills Apr 25 '18 at 00:38
0

ok, I hope this helps someone, the solution was 2 fold. first the proxy wasn't getting acknowledged, due to leading protocol def, http:// I used just the IP address and the cononical name with no http:// and I was able to receive a 504 Gateway timeout error. so the HTTP4 endpoint is working as it was set to look like

http4://myhost:443/path
http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token

I was able to get the request working by first making a hard endpoint

    <to uri="http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token?throwExceptionOnFailure=false" />

so the endpoint http4 override by setting

m.setHeader(Exchange.HTTP_URI, tokenUrl);

worked.

I then tried using the XML setting he override in the route.

<log message="HTTP4 POST headers: ${headers}" loggingLevel="DEBUG"/>
<setHeader headerName="CamelHttpUri">
    <simple>${header.TOKENURL}?throwExceptionOnFailure=false</simple>
</setHeader>
<to uri="http4://uaa-svc-prod.app-api.aws-usw02-pr.io:443/oauth/token?throwExceptionOnFailure=false" />

this worked also. :) however I was still getting the 504 gateway timeout error returned.

I tried using the https:// URI in for the override URI

https://uaa-svc-prod.app-api.aws-usw02-pr.io/oauth/token

and the http4:// endpoint was overridden with the https:// URI and now I am getting a CamelHttpResponseCode=401, CamelHttpResponseText=Unauthorized

so, it is working now, happy happy joy joy... in conclusion do not include the http:// protocol def in the proxy setting. Use either the IP or the cononical name.

   <camelContext     
      id="com.ge.digital.passthru.coreCamelContext"
      trace="true"
      xmlns="http://camel.apache.org/schema/blueprint"
      allowUseOriginalMessage="false"
      streamCache="true"
      errorHandlerRef="deadLetterErrorHandler" >
      <properties>
           <property key="http.proxyHost" value="PITC-Zscaler.proxy.corporate.america.com"/>
           <property key="http.proxyPort" value="80"/>
      </properties>

when defining the HTTP4:// endpoint use the syntax

http4:hostname[:port][/resourceUri][?options]

and the URI set by Exchange.HTTP_URI over riding the endpoint def contains the https://myhost/path where you are calling.

this is what worked for me, I hope this helps newbies like myself. thanks everyone.

GLMills
  • 558
  • 1
  • 12
  • 37