Error while setting Dynamic url -refused to create tunnel

Not applicable

When i am trying to dynamically set the url in target request flow using Java Script for HTTPTargetConnection,

like: <URL>https://{myhost}/{mypath}</URL>

I am getting below error

{"Envelope":"{\"Body\":{\"Fault\":{\"detail\":{\"source\":{\"errorcode\":\"protocol.http.ProxyTunnelCreationFailed\"}},\"faultcode\":\"soap:Server\",\"faultstring\":\"Proxy refused to create tunnel with response status 400\",\"faultactor\":{}}},\"encodingStyle\":\"http:\\\/\\\/schemas.xmlsoap.org\\\/soap\\\/encoding\\\/\"}"}

PS: I required to set dynamic url as I need to enable TLSv1.2 at target endpoint.

Any insights will be helpfull

0 4 1,607
4 REPLIES 4

That error is a curious one!

It appears to be a SOAP Envelope which has been transformed into JSON .

Apigee Edge does not generate SOAP errors natively. This suggests that the error is being generated by a system external to Edge, possibly the backend system you are calling.

I suggest that you use the Apigee Edge Trace UI to determine when the error originally occurs in the API proxy. If the error is being returned from the backend, then... it suggests that the backend is experiencing a problem and relaying a message back to Edge. To solve that kind of problem, you need to investigate THERE - on the backend.

Hi @Dino

Thanks for your response.

I did some bit of investigation and found out that the targeturl is not setting up through JS.

Although the value is populated in myhost and mypath variable but its not assigning to targetconnection.

It remain as <URL>https://{myhost}/{mypath}</URL>

So the Error is basically generated from backend system as its fails to identify the target url.

Any clue why the values are not setting in <HTTPTargetConnection> at target endpoints.

PS: The same feature works properly for service call out policy,As its sets the url dynamically.

Yes - I think that is not going to work. The URL in the HTTPTargetConnection will not do variable replacement. I think we have a feature request on that, but today you cannot.

There's an easy workaround: use AssignMessage/AssignVariable, on the variable called "target.url". It looks like this:

<AssignMessage name='AM-TargetUrl'>
  <AssignTo createNew='false' type='request'/>
  <AssignVariable>
    <Name>target.url</Name>
    <Value>http://{myhost}/{mypath}</Value>
  </AssignVariable>
</AssignMessage><br>

You must attach such a policy in the Target Request flow. When dynamically assigning target URL, I often follow a pattern in which the URL in the HTTPTargetConnection is something like: http://this-will-be-assigned/see.the.above.policy

Just for documentation purposes.

BTW if you already have a JS policy that is assigning variables, then you can just as easily do something like this in JS:

context.setVariable('target.url', 
                    'http://' +  myhost + '/' + mypath );

This assumes that myhost and mypath are known variables in JS. If they are context variables then you need to first do this:

var myhost = context.getVariable('myhost');
var mypath = context.getVariable('mypath');

And, just as if you were using the AssignMessage option, you need to run that JS in the Target Request flow! If you put it in the Proxy Request flow, then the assignment will "work" but it will be overwritten when the target request flow initiates.

Hi @Dino

I am doing exactly the same you have mention

In JS policy 

var myhost1=xyz.com
var mypath1= abcd/v1/1234

context.setVariable('myhost',myhost1);
context.setVariable('mypath',mypath1);

Same thing reflecting in TargetEndpoint

<HTTPTargetConnection>
        
        <URL>https://{myhost}/{mypath}</URL>
        <Properties>
            <Property name="success.codes">2xx,3xx,4xx,5xx</Property>
        </Properties>
       <SSLInfo>
   	 <Enabled>true</Enabled>
        <Protocols>
            <Protocol>TLSv1.2</Protocol>
        </Protocols>
    </SSLInfo>
</HTTPTargetConnection>

But the problem is URL is not setting up.

I required HTTPTargetConnection because in need to set TLSv1.2.

Do there is any work around to set TLSv1.2 in JS.