{ Community }
  • Academy
  • Docs
  • Developers
  • Resources
    • Community Articles
    • Apigee on GitHub
    • Code Samples
    • Videos & eBooks
    • Accelerator Methodology
  • Support
  • Ask a Question
  • Spaces
    • Product Announcements
    • General
    • Edge/API Management
    • Developer Portal (Drupal-based)
    • Developer Portal (Integrated)
    • API Design
    • APIM on Istio
    • Extensions
    • Business of APIs
    • Academy/Certification
    • Adapter for Envoy
    • Analytics
    • Events
    • Hybrid
    • Integration (AWS, PCF, Etc.)
    • Microgateway
    • Monetization
    • Private Cloud Deployment
    • 日本語コミュニティ
    • Insights
    • IoT Apigee Link
    • BaaS/Usergrid
    • BaaS Transition/Migration
    • Apigee-127
    • New Customers
    • Topics
    • Questions
    • Articles
    • Ideas
    • Leaderboard
    • Badges
  • Log in
  • Sign up

Get answers, ideas, and support from the Apigee Community

  • Home /
  • API Design /
avatar image
1
Question by Donald Collett · Jun 29, 2018 at 07:53 PM · 3k Views targetendpointtarget endpointtarget path url

Overriding target.basepath and target.url via Javascript worked previously, but now not

I was successfully using the following Javascript to override the target.basepath and/or target.url for certain operations that need to a different controller in the target application. This no longer works though as it seems the variables are now read only. Is there a way to get this working again? The javascript is in the target Endpoints Preflow. In the trace on this new release, the "targetUrl" now shows as N/A.

var proxyPathSuffix = context.getVariable("proxy.pathsuffix");
print("proxy.pathsuffix=" + proxyPathSuffix + " ");
var requestVerb = context.getVariable("request.verb");
print("requestVerb=" + requestVerb + " ");
if (!proxyPathSuffix.localeCompare("/special-operation") && !requestVerb.localeCompare("POST")) {
  var targetBasePath = context.getVariable("target.basepath");
  print("targetBasePath=" + targetBasePath + " ");
  if (targetBasePath && targetBasePath.localeCompare("")) {
    var newTargetBasePath = targetBasePath.replace("old-context-path", "new-context-path");
    context.setVariable("target.basepath", newTargetBasePath);
    targetBasePath = context.getVariable("target.basepath");
    print("targetBasePath=" + targetBasePath + " ");
  } else {
    print("ERROR: targetBasePath is null! ")
  }
}

Comment
Add comment
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Close

3 Answers

  • Sort: 
avatar image
1

Answer by Robin Martin   · Jul 02, 2018 at 02:42 PM

Hey @Donald Collett.

It doesn't look as if you are going to get any other answers, so here's comments and a workaround :-

1. Trace shows those variables with a "not-equal" sign (crossed-out equals) - I guess that means read-only, yes. (and I suspect can happen if the value is rejected for syntax or similar)

2. Same effect with Javascript or with AssignMessage

3. The workaround: Rewrite the full target.url ... protocol,hostname and basepath, e.g

 var host = context.getVariable("target.url");
 var suffix = context.getVariable("proxy.pathsuffix");
 var newURL = host.concat(suffix);
 context.setVariable("target.url",newURL);

HTH.

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dino-at-Google ♦♦   · Jul 02, 2018 at 05:39 PM 0
Link

Good answer @Robin Martin .

target.basepath is documented as being read-only.

I am not aware of any recent change, either in documentation or in behavior.

Setting target.url has always worked.

avatar image Donald Collett · Jul 02, 2018 at 07:31 PM 0
Link

It was working like your example previously but our Apigee portal was updated and it stopped working. In the Target Endpoint PreFlow, the target.url is now showing a value of " -NA-" like its been depreciated or something. So the attempt to modify the target.basepath.

Called the context.setVariable("target.url",newURL) but it no longer sets the target.url. I printed the newURL right before setting then called the context.getVariable("target.url") and it came back null.

avatar image
0

Answer by Harimohan Annareddy · Jul 10, 2018 at 05:50 PM

@Donald Collett

I am also facing the same issue. Please let me know if you find any solution for this.

Comment
Add comment Show 2 · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Donald Collett · Jul 11, 2018 at 01:35 PM 0
Link

What I found is "target.url" is only usable if you use a <URL> in the <HTTPTargetConnection>. If you use <LoadBalancer>, then "target.url" becomes unusable.

In my case, the need for load balancing can be handled by setting the <URL> to a VIP provided by an F5 load balancer.

Ran into another limitation in that apparently variables such as {host} and {port} can't be used inside the <URL>. The functionality doesn't appear to be implemented. So that blocked us from making the URL dynamic from variables defined in Environment Configuration Key Value Maps using the Key Value Map Operations policy.

avatar image Dino-at-Google ♦♦ Donald Collett   · Jul 11, 2018 at 01:50 PM 0
Link

If you use <LoadBalancer>, then "target.url" becomes unusable.

True.

You can do something like this

  <HTTPTargetConnection> 
    <SSLInfo> 
      <Enabled>true</Enabled> 
    </SSLInfo> 
    <LoadBalancer> 
      <Server name="testserver"/> 
    </LoadBalancer> 
    <Path>{mypath}</Path> 
  </HTTPTargetConnection> 

...and then the Path element is treated as a Message template - the values of the variable (or variables, if you use more than one) are inserted into the string.

avatar image
0

Answer by Dino-at-Google   · Jul 11, 2018 at 03:29 PM

This can happen if you use an HTTPTargetConnection with a LoadBalancer element, like this:

  <HTTPTargetConnection> 
    <SSLInfo> 
      <Enabled>true</Enabled> 
    </SSLInfo> 
    <LoadBalancer> 
      <Server name="testserver"/> 
    </LoadBalancer> 
    <Path>/foo</Path> 
  </HTTPTargetConnection> 

In that case, setting target.url is ineffectual.

The good news is that the Path element is a Message Template. So you can do this:

  <HTTPTargetConnection> 
    <SSLInfo> 
      <Enabled>true</Enabled> 
    </SSLInfo> 
    <LoadBalancer> 
      <Server name="testserver"/> 
    </LoadBalancer> 
    <Path>{mypath}</Path> 
  </HTTPTargetConnection> 

...and the variable "mypath" will be used for the path.

Comment
Add comment · Link
10 |5000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by Apigeeks only
  • Viewable by the original poster
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

54 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Best Practice for API Proxy that exposes multiple resource paths and proxies to multiple endpoints 1 Answer

Getting responses from different targets - how is this possible? 1 Answer

Target End points 1 Answer

How to PUT elements of collection into BaaS via Apigee proxy 1 Answer

When should I put a policy in Proxy Endpoint versus Target Endpoint? 2 Answers

  • Products
    • Edge - APIs
    • Insights - Big Data
    • Plans
  • Developers
    • Overview
    • Documentation
  • Resources
    • Overview
    • Blog
    • Apigee Institute
    • Academy
    • Documentation
  • Company
    • Overview
    • Press
    • Customers
    • Partners
    • Team
    • Events
    • Careers
    • Contact Us
  • Support
    • Support Overview
    • Documentation
    • Status
    • Edge Support Portal
    • Privacy Policy
    • Terms & Conditions
© 2021 Apigee Corp. All rights reserved. - Apigee Community Terms of Use - Powered by AnswerHub
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Post an idea
  • Spaces
  • Product Announcements
  • General
  • Edge/API Management
  • Developer Portal (Drupal-based)
  • Developer Portal (Integrated)
  • API Design
  • APIM on Istio
  • Extensions
  • Business of APIs
  • Academy/Certification
  • Adapter for Envoy
  • Analytics
  • Events
  • Hybrid
  • Integration (AWS, PCF, Etc.)
  • Microgateway
  • Monetization
  • Private Cloud Deployment
  • 日本語コミュニティ
  • Insights
  • IoT Apigee Link
  • BaaS/Usergrid
  • BaaS Transition/Migration
  • Apigee-127
  • New Customers
  • Explore
  • Topics
  • Questions
  • Articles
  • Ideas
  • Badges