apigee overwriting the target.url with a custom variable - variable-assignment

I have been trying to overwrite the target.url with a variable using the Assign Message Policy. Per other solutions, I have put this in the "Target EndPoint" Section. The issue is, unless I hard-code the root section of the URL, the substitution fails. I have tried all the commented VALUE stmts below with and then started adding the "REF"stmts to attempt to solve the issue - to no avail. You can see I have tried cutting the target into various snippets using Extract policies, but cannot get a solution that works.
Thanks for help.
For the purposes of the code snippet below
entireURL = "http://my.root.url/thestuff/morestuff"
AppServerURL = "my.root.url/thestuff/morestuff"
AppServerRoot = "my.root.url"
AppServerSfx = "thestuff/morestuff"
codee from Assign Message Policy
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Post-to-named-serverL">
<DisplayName>Post to named server</DisplayName>
<FaultRules/>
<Properties/>
<AssignVariable>
<Name>target.url</Name>
<Value>http://${AppServerRoot}/{AppServerSfx}</Value>
<Ref/>
<!--
<Value>http://my.root.url/{AppServerSfx}</Value> works but I need the root changed
<Value>http://{AppServerRoot}/{AppServerSfx}</Value>
<Value>http://${AppServerRoot}/{AppServerSfx}</Value>
<Value>http://{AppServerURL}</Value>
<Value>http://${AppServerURL}</Value>
<Value>entireURL</Value>
<Value>{entireURL}</Value> -- this was my first try
<Value>${entireURL}</Value>
<Ref>entireURL</Ref>
<Ref>{entireURL}</Ref>
<Ref>${entireURL}</Ref>
-->
</AssignVariable>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

You are correctly putting the target.url manipulation in the Target Request flow.
Using AssignMessage/AssignVariable can be limiting. The Value element doesn't allow you to do any variable substitutions.
The following worked for me:
<Ref>entireURL</Ref>
Ref also doesn't allow variable substitutions -- it just takes the name of the variable. Since you have to build the value of that variable ahead of time, using the Ref example above doesn't buy you much.
I usually accomplish target URL rewriting using a JavaScript callout with code similar to the following:
var appServerRoot = context.getVariable("AppServerRoot");
var appServerSfx = context.getVariable("AppServerSfx");
context.setVariable("target.url", "http://" + appServerRoot + "/" + appServerSuffix);

Related

Flask-Admin GeoAlchemy2 example doesn't show a map

I'm trying to run this example about how to use Flask-Admin displaying maps: https://github.com/flask-admin/flask-admin/tree/master/examples/geo_alchemy.
In README.rst, there's this instruction:
You will notice that the maps are not rendered. To see them, you will have to register for a free account at Mapbox and set the MAPBOX_MAP_ID and MAPBOX_ACCESS_TOKEN config variables accordingly.
I already have a valid MAPBOX_ACCESS_TOKEN, and I went to MapBox to look for a MAPBOX_MAP_ID. There I read that MAP_ID was deprecated, and now I'll have to obtain a tileset ID, and it's described as a label composed by <my_mapbox_user_name>.the_tileset_ID itself.
So I located the code as they described in the instructions (in my case, mapbox-streets-v8) and fulfilled the config.py parameters:
MAPBOX_MAP_ID = '<my_mapbox_user_name>.mapbox-streets-v8'
MAPBOX_ACCESS_TOKEN = 'pk.eyJ1...'
However, I couldn't see any map displayed or any error message.
How can I fix it?
I think there is a small bug in file Lib\site-packages\flask_admin\static\admin\js\form.js. The original URL generated to get a tile is:
https://api.mapbox.com/styles/v1/mapbox/<MAPBOX_MAP_ID parameter>/tiles/12/2258/2457?access_token=<MAPBOX_ACCESS_TOKEN parameter>
However, the correct one is:
https://api.mapbox.com/styles/v1/<MAPBOX_MAP_ID parameter>/tiles/12/2258/2457?access_token=<MAPBOX_ACCESS_TOKEN parameter>
That is, I had to remove the mapbox word from the URL.
To do that I made some changes in form.js file:
//var mapboxUrl = 'https://api.mapbox.com/styles/v1/mapbox/'+window.MAPBOX_MAP_ID+'/tiles/{z}/{x}/{y}?access_token='+window.MAPBOX_ACCESS_TOKEN
var mapboxUrl = 'https://api.mapbox.com/styles/v1/'+window.MAPBOX_MAP_ID+'/tiles/{z}/{x}/{y}?access_token='+window.MAPBOX_ACCESS_TOKEN
Then, it's working now:

Protractor Custom Locator: Not available in production, but working absolutely fine on localhost

I have added a custom locator in protractor, below is the code
const customLocaterFunc = function (locater: string, parentElement?: Element, rootSelector?: any) {
var using = parentElement || (rootSelector && document.querySelector(rootSelector)) || document;
return using.querySelector("[custom-locater='" + locater + "']");
}
by.addLocator('customLocater', customLocaterFunc);
And then, I have configured it inside protractor.conf.js file, in onPrepare method like this:
...
onPrepare() {
require('./path-to-above-file/');
...
}
...
When I run my tests on the localhost, using browser.get('http://localhost:4200/login'), the custom locator function works absolutely fine. But when I use browser.get('http://11.15.10.111/login'), the same code fails to locate the element.
Please note, that the test runs, the browser gets open, user input gets provided, the user gets logged-in successfully as well, but the element which is referred via this custom locator is not found.
FYI, 11.15.10.111 is the remote machine (a virtual machine) where the application is deployed. So, in short the custom locator works as expected on localhost, but fails on production.
Not an answer, but something you'll want to consider.
I remember adding this custom locator, and encounter some problems with it and realised it's just an attribute name... nothing fancy, so I thought it's actually much faster to write
let elem = $('[custom-locator="locator"]')
which is equivalent to
let elem = element(by.css('[custom-locator="locator"]'))
than
let elem = element(by.customLocator('locator'))
And I gave up on this idea. So maybe you'll want to go this way too
I was able to find a solution to this problem, I used data- prefix for the custom attribute in the HTML. Using which I can find that custom attribute on the production build as well.
This is an HTML5 principle to prepend data- for any custom attribute.
Apart from this, another mistake that I was doing, is with the selector's name. In my code, the selector name is in camelCase (loginBtn), but in the production build, it was replaced with loginbtn (all small case), that's why my custom locater was not able to find it on the production build.

Change name of generated Context file with EF PowerTools Reverse Engineer Code First

I have been attempting to figure out how to make the EF Power Tools - Reverse Engineer Code First use a different name for the generated Context-file, than what it uses now.
Example
I have a database called My_Awesome_Dev_Database. When I run Reverse-engineer against that, the file that is generated will be called:
My_Awesome_Dev_DatabaseContext.cs
What it would like to do is specify what the file is to be called, for instance:
MyAwesomeDatabaseContext.cs
Attempts so far
I have tried looking through the EF.Utilities.CS.ttinclude file, to figure out how the filename is generated - but I have been unsuccessful so far.
Does anyone know ?
Thanks in advance!
Currently the generated context file naming convention is hard-coded and non configurable.
All the logic is inside the ReverseEngineerCodeFirstHandler class (the source is on CodePlex).
It sets the context file name and path with
var contextFilePath = Path.Combine(modelsDirectory,
modelGenerator.EntityContainer.Name + contextHost.FileExtension);
var contextItem = project.AddNewFile(contextFilePath, contextContents);
So the file name is coming from modelGenerator.EntityContainer.Name which gets created upper in the method with:
var contextName =
connection.Database.Replace(" ", string.Empty)
.Replace(".", string.Empty) + "Context";
var modelGenerator =
new EntityModelSchemaGenerator(storeGenerator.EntityContainer,
"DefaultNamespace", contextName);
So as you can see the tool just takes the db name removes the spaces and dots and use it as the context name which will end up as the generated file name.
You can open an issue or - because Entity Framework is open source - take the code, add this configuration option, and send back a pull request.

Deferred binding not working after compilation

I have a weird problem with deferred binding. I have defined the following module:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Defines the usercategory property and its provider function. -->
<module>
<define-property name="usercategory" values="c00,c01,c02" />
<collapse-property name="usercategory" values="*" />
<property-provider name="usercategory"><![CDATA[
// Look for the usercategory cookie
var cs = document.cookie.split(';');
for (var i = 0; i < cs.length; i++) {
var name = cs[i].substr(0, cs[i].indexOf("="));
var value = cs[i].substr(cs[i].indexOf("=") + 1);
name = name.replace(/^\s+|\s+$/g,"");
if (name == "usercategory") {
return unescape(value);
}
}
return "c00";
]]></property-provider>
</module>
which sets the property usercategory by looking at the value of a cookie named usercategory.
I use this property application.gwt.xml to defer binding of some classes, for example:
<inherits name="com.example.UserCategory"/>
<replace-with class="com.example.client.ui.menu.MainMenuView01">
<when-type-is class="com.example.client.ui.menu.MainMenuView"/>
<when-property-is name="usercategory" value="c01"/>
</replace-with>
This works like a charm when I'm in development mode (i.e. when running my app from within Eclipse). However, if I compile the app and deploy it (in Jetty, but I don't this this is the problem), then deferred binding does not seem to work, and the expected classes are not loaded. I've checked and the cookie is set up properly with the correct value c01, but class com.example.client.ui.menu.MainMenuView01 is not loaded.
Am I missing something? Am I doing something wrong?
Thank you in advance!
There are two possibilities. You are doing something wrong, or there is another bug in GWT compiler. I've tried to implement a case like your and it was working when compiled without any problems. So most likely there can be some error on your side. So what i recommend to do is to compile app with -style PRETTY and see how it was compiled. find function named com_example_client_ui_menu_MainMenuView(), and see if it able to create MainMenuView01, try to debug it and etc. Anyway this kind of stuff should be working without any problems.
Also try to debug your property provider (and use vars $doc and $wnd in property provider instead of window)
Another possible case is that the cookie might be not readable from JS
I figured out what the problem was, and I'm writing it here in case others might be interested.
The module that I defined (see code in my question) defines a property whose value is taken from a cookie, that is generated after the user logs in the application.
Originally I had a GWT Place for the login, and when the user successfully authenticated the application moved to another Place. In this case when the user enter the application, and the GWT Javascript is downloaded to the browser, the cookie is not set yet (because the user has not performed login yet). Therefore the deferred binding does not work, and the expected classes (like com.example.client.ui.menu.MainMenuView01) are not loaded.
I have no idea why this works correctly when run in development mode. Anyway. the solution that I implemented is to move the login phase outside of the GWT application, and when the login is successful, I add the cookie and the redirect the user to the actual GWT application.

XML file reading error

help me please i'm having the following issue:
I'm trying to read a XML file that looks like this:
<service />
<parameters>
<parametro nombreParametro="payment" valorParametro="<?xml version="1.0" encoding="utf-16"?>" tipoParametro="string" />
</parameters>
The xml file is well formed, but as you can see, i have an < < and > > characters as attribute on some elements and the problem is that when i tried to read the file like this:
xmlDoc.LoadXml(stringWithXmlFileContent);
It gives me the following error:
Additional information: '<', hexadecimal value 0x3C, is not a valid character or attribute. Line XX, position XX.
What should i do to avoid this error, i don't want to make a Replace cause i'm building a generic method.
Thanks in advance.
I can't reproduce this, assuming that what you posted was only a portion of the XML file. (If it was the whole file, then the problem is it doesn't have a single root element, as Rubens said in his answer). Here's a short but complete program showing the same attribute value not having a problem:
using System;
using System.Xml;
public class Test
{
public static void Main(String[] args)
{
string xml = "<element attr=\"<?xml version="1.0""
+ " encoding="utf-16"?>\" />";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
Console.WriteLine(doc.OuterXml);
}
}
Can you edit your question to include a similar program which does show the problem?
Seems your XML file isnt well-formed, as you must have a single root element.
Can you tell us how are your building this file?