How to add custom elements to Wsse Security / Username Token in Suds - soap

Default SOAP Username Token has the following elements:
<wsse:UsernameToken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password>PASSWORD</wsse:Password>
</wsse:UsernameToken>
For the same I would to like an additional tokens say Domain & Organization, the schema should look like this,
<wsse:UsernameToken>
<wsse:Username>USERNAME</wsse:Username>
<wsse:Password>PASSWORD</wsse:Password>
<Organization>ORGANIZATION</Organization>
<Domain>DOMAIN</Domain>
</wsse:UsernameToken>
So using Element tag, I appended the elements, here it goes.
wsse = ('wsse', 'http://schemas.xmlsoap.org/ws/2002/12/secext')
security = Element('Security', ns=wsse)
usernametoken = Element('UsernameToken', ns=wsse)
usernametoken.insert(Element('Username', ns=wsse).setText('USERNAME'))
usernametoken.insert(Element('Password', ns=wsse).setText('PASSWORD'))
usernametoken.insert(Element('Organization').setText('ORGANIZATION'))
usernametoken.insert(Element('Domain').setText('DEFAULT'))
security.insert(usernametoken)
Now when I try to set options for the same:
client.set_options(wsse=security)
Am getting the following error:
AttributeError: "wsse" must be: (<class suds.wsse.Security at 0xf552c0>,)
Looks like the type of token class is being changed... Am I missing something
Thanks

Figured it out.
client setting options should be soapheader instead of wsse, here the code goes
client.set_options(soapheaders=security)

Related

SMSA Tracking status [duplicate]

I'm making my first attempt to connect to a SOAP server from PHP, and I'm not understanding how to log in and get the data I need. The service I'm trying to connect to is the Hawley USA service http://hawleyusa.com/thcServices/StoreServices.asmx). I've been looking at a few posts on how to connect, and I get the basics. I've verified that I have SOAP enabled in my PHP, and I'm just trying to get an inventory list. Here's the code I'm using:
<?php
ini_set("soap.wsdl_cache_enabled", "0"); // disabling WSDL cache
$wsdl_path = "http://hawleyusa.com/thcServices/StoreServices.asmx?WSDL";
$login_id = 'mylogin_id';
$password = 'mypassword';
$client = new SoapClient($wsdl_path);
try {
echo "<pre>\n";
print($client->InventoryList(array("LoginID" => $login_id, "Password" => $password)));
echo "\n";
}
catch (SoapFault $exception) {
echo $exception;
}
However, when I run this code, I get this error:
SoapFault exception: [soap:Server] Server was unable to process request. ---> Object reference not set to an instance of an object. in /Users/steve/Sites/mysite/hawley_client.php:12
When debugging, I can see the $client instance initiated, so I'm not sure why I'm getting this error.
Second question: Am I passing the user ID and password correctly?
Thanks.
Update: I threw in $client->__getLastRequest, and this is what I got:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://hawleyusa.com/thcServices/">
<SOAP-ENV:Body>
<ns1:InventoryList/>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So I can see that I'm missing my login ID and password. How do I add them to my InventoryList call?
You're close. Looking at the WSDL the InventoryList method takes an object called "request". Modify your call line slightly:
$client->InventoryList(array("request" => array("LoginId" => $login_id, "Password" => $password));
Probably it's not the same case but it also gives the same error if you don't specify empty strings in fields you don't need to use, taken from http://www.sitepoint.com/forums/showthread.php?755549-SOAP-XML-Object-reference-not-set-to-an-instance-of-an-object
I my case the problem was in typo:
In given docs the filed name was documentShipmentAddress (and I was using this)
but in wdsl (schema) was:
shipmentAddress
So that could be the problem with this error message.
I have changed the field name to shipmentAddress and it solved the problem.

How to invoke a formhandler using ATG REST Client

I'm trying to invoke ProfileFormHandler's create handle using ATG rest client as shown below.
mSession = RestSession.createSession(mHost, mPort,"kim#example.com","password");
mSession.setUseHttpsForLogin(false);
mSession.login();
Map<String,Object> params = new HashMap<String,Object>();
params.put("value.login", "buddha#oracle.com");
params.put("value.email", "buddha#oracle.com");
params.put("value.password", "password");
RestResult result = RestComponentHelper.executeMethod("/atg/userprofiling/ProfileFormHandler","create",null,params,mSession);
I'm getting form exceptions that says, I'm not passing Login and Password Fields.
["Missing value for the required property Password",
"Missing value for the required property Login name"]
I've tried all combinations of login and password fields like value.login, Login, login, value.Login etc., but nothing seemed to work. All combinations giving the same form exceptions.
How do I invoke an ATG form handler using ATG REST Client and pass parameters to it?
Definitely need more information but looking at your code I can see that you have a value.login which is not configured ootb and believe this is causing the NPE. Assuming you have not customized the ootb ATG RegistrationFormHandler and the required field in the repository the only values you need to pass to the form handler are:
value.email
value.password
value.confirmPassword
value.firstName
value.lastName
Also, the help is specific that the data-type of the value property needs to be java.util.Dictionary
Add the following to /atg/rest/security/restSecurityConfiguration.xml
<resource component="/atg/userprofiling/ProfileFormHandler" secure="false">
<method name="handleCreate" secure="false">
<acl value="EVERYONE:read,write,execute" />
</method>
<property name="value.login" secure="false" />
<property name="value.password" secure="false" />
</resource>

What is an InstallationID in Quickbooks QBMSXML

I have a qbmsxml that I'm sending that continues to get a response error 2000.
<qbmsxml>
<signonmsgsrq>
<signondesktoprq>
<clientdatetime>2014-04-03T09:37:23</clientdatetime>
<applicationlogin>my.application.login.id</applicationlogin>
<connectionticket>SDK-MY-Connection-Ticket</connectionticket>
<language>English</language>
<appid>9999999999</appid>
<appver>1.0</appver>
</signondesktoprq>
</signonmsgsrq>
<qbmsxmlmsgsrq>
<customercreditcardauthrq>
<transrequestid>140403937231</transrequestid>
<creditcardnumber>4111111111111111</creditcardnumber>
<expirationmonth>12</expirationmonth>
<expirationyear>2017</expirationyear>
<isecommerce>true</isecommerce>
<amount>0.01</amount>
<nameoncard>John Doe</nameoncard>
<creditcardaddress>1234 Main Street</creditcardaddress>
<creditcardpostalcode>12345</creditcardpostalcode>
</customercreditcardauthrq>
</qbmsxmlmsgsrq>
</qbmsxml>
As I've been reviewing the information on creating a request, I found an 'InstallationID' tag referenced. It goes in the element like so:
<signonmsgsrq>
<signondesktoprq>
<clientdatetime>2014-04-03T09:37:23</clientdatetime>
<applicationlogin>my.application.login.id</applicationlogin>
<connectionticket>SDK-MY-Connection-Ticket</connectionticket>
<installationid>IDTYPE</installationid>
<language>English</language>
<appid>9999999999</appid>
<appver>1.0</appver>
</signondesktoprq>
</signonmsgsrq>
My question is: What is the IDTYPE for InstallationID? Where can I get it? What options can I set it to?
I think the problem is not related to your InstallationID field at all. I think the problem is that your XML isn't conforming to what Intuit expects.
Specifically, everything in your XML request is lowercase, when Intuit expects it to be camel case. You're also missing a qbmsxml version header, and a xml version header.
Here's an example of a correctly formed request:
<?xml version="1.0" encoding="utf-8"?>
<?qbmsxml version="3.0"?>
<QBMSXML>
<SignonMsgsRq>
<SignonTicketRq>
<ClientDateTime>2009-10-09T13:14:16</ClientDateTime>
<SessionTicket>xxxxxxxxxxxxky4yL6eBtCULX1zgQ:106892184</SessionTicket>
</SignonTicketRq>
</SignonMsgsRq>
<QBMSXMLMsgsRq>
<CustomerCreditCardChargeRq>
<TransRequestID>35f9cf7cb20994e8a32e6b3e91e8e602</TransRequestID>
<CreditCardNumber>xxxxxxxxxxxx5100</CreditCardNumber>
<ExpirationMonth>10</ExpirationMonth>
<ExpirationYear>2009</ExpirationYear>
<Amount>295.00</Amount>
<NameOnCard>Keith Palmer</NameOnCard>
<CreditCardAddress>56 Cowles Road</CreditCardAddress>
<CreditCardPostalCode>06279</CreditCardPostalCode>
</CustomerCreditCardChargeRq>
</QBMSXMLMsgsRq>
</QBMSXML>
Where are you getting your syntax from? It seems very wrong... here are some good examples:
http://wiki.consolibyte.com/wiki/doku.php/quickbooks_qbms_integration

FlatRateShippingOptions not recognized when specifying CallbackURL for Paypal SetExpressCheckout

I'm using the PayPal Express Checkout SOAP API. I have a SetExpressCheckoutRequest that works until I add the CallbackURL element. It then gives me the following error:
Ack: Failure
ShortMessage: Flat-rate shipping options are missing.
LongMessage: Flat-rate shipping options are missing; you must specify flat-rate shipping options when you specify a callback URL.
ErrorCode: 11825
My request includes the following elements (child elements of <ebl:PaymentDetails>):
<ebl:FlatRateShippingOptions>
<ebl:ShippingOptionIsDefault>true</ebl:ShippingOptionIsDefault>
<ebl:ShippingOptionAmount currencyID=""USD"">4.00</ebl:ShippingOptionAmount>
<ebl:ShippingOptionName>Ground</ebl:ShippingOptionName>
</ebl:FlatRateShippingOptions>
The various SDKs for Soap don't seem to include these elements. After a great deal of searching, I have not been able to find an example of a working SetExpressCheckoutRequest that includes this option. I have tried many variations but nothing seems to work.
Does anyone have a sample SOAP API request that works with this option?
Thanks,
CJ
Here is the complete XML request file. It works without the CallbackURL line and the FlatRateShippingOptions section. I've tried it with and without the ShippingOptions element since the documentation seems inconsistent as to whether or not it is required.
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
<soapenv:Header>
<ns:RequesterCredentials>
<ebl:Credentials>
<ebl:Username>sdk-three_api1.sdk.com</ebl:Username>
<ebl:Password>QFZCWN5HZM8VBG7Q</ebl:Password>
<ebl:Signature>A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU</ebl:Signature>
</ebl:Credentials>
</ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<ns:SetExpressCheckoutReq>
<ns:SetExpressCheckoutRequest>
<ebl:Version>106.0</ebl:Version>
<ebl:SetExpressCheckoutRequestDetails>
<ebl:MaxAmount currencyID="USD">20.00</ebl:MaxAmount>
<ebl:ReturnURL>https://www.domain.com/final.asp</ebl:ReturnURL>
<ebl:CancelURL>https://www.domain.com/reviewcart.asp</ebl:CancelURL>
<ebl:NoShipping>2</ebl:NoShipping>
<ebl:AddressOverride>1</ebl:AddressOverride>
<ebl:LocaleCode>US</ebl:LocaleCode>
<ebl:SolutionType>Sole</ebl:SolutionType>
<ebl:BuyerEmail>platfo_1255077030_biz#gmail.com</ebl:BuyerEmail>
<ebl:CallbackURL>https://www.domain.com/paypalcallback.asp</ebl:CallbackURL>
<ebl:PaymentDetails>
<ebl:FlatRateShippingOptions>
<ebl:ShippingOptions>
<ebl:ShippingOptionIsDefault>true</ebl:ShippingOptionIsDefault>
<ebl:ShippingOptionAmount currencyID="USD">4.00</ebl:ShippingOptionAmount>
<ebl:ShippingOptionName>Ground</ebl:ShippingOptionName>
</ebl:ShippingOptions>
<ebl:ShippingOptions>
<ebl:ShippingOptionIsDefault>false</ebl:ShippingOptionIsDefault>
<ebl:ShippingOptionAmount currencyID="USD">20.00</ebl:ShippingOptionAmount>
<ebl:ShippingOptionName>NextDayAir</ebl:ShippingOptionName>
</ebl:ShippingOptions>
</ebl:FlatRateShippingOptions>
<ebl:OrderTotal currencyID="USD">20.00</ebl:OrderTotal>
<ebl:ItemTotal currencyID="USD">16.00</ebl:ItemTotal>
<ebl:ShippingTotal currencyID="USD">4.00</ebl:ShippingTotal>
<ebl:HandlingTotal currencyID="USD">0.00</ebl:HandlingTotal>
<ebl:TaxTotal currencyID="USD">0.00</ebl:TaxTotal>
<ebl:OrderDescription>Cart ID 123456</ebl:OrderDescription>
<ebl:ShipToAddress>
<ebl:Name>John Doe</ebl:Name>
<ebl:Street1>123 Main St</ebl:Street1>
<ebl:Street2>Apt 2</ebl:Street2>
<ebl:CityName>Chicago</ebl:CityName>
<ebl:StateOrProvince>IL</ebl:StateOrProvince>
<ebl:Country>US</ebl:Country>
<ebl:Phone>312-555-1234</ebl:Phone>
<ebl:PostalCode>60610</ebl:PostalCode>
</ebl:ShipToAddress>
<ebl:PaymentDetailsItem>
<ebl:Name>3001</ebl:Name>
<ebl:Quantity>2</ebl:Quantity>
<ebl:Tax currencyID="USD">0.00</ebl:Tax>
<ebl:Amount currencyID="USD">6.00</ebl:Amount>
<ebl:Description>test order</ebl:Description>
<ebl:ItemCategory>Physical</ebl:ItemCategory>
</ebl:PaymentDetailsItem>
<ebl:PaymentDetailsItem>
<ebl:Name>3002</ebl:Name>
<ebl:Quantity>4</ebl:Quantity>
<ebl:Tax currencyID="USD">0.00</ebl:Tax>
<ebl:Amount currencyID="USD">1.00</ebl:Amount>
<ebl:Description>test order</ebl:Description>
<ebl:ItemCategory>Physical</ebl:ItemCategory>
</ebl:PaymentDetailsItem>
<ebl:PaymentAction>Sale</ebl:PaymentAction>
</ebl:PaymentDetails>
<ebl:ChannelType>Merchant</ebl:ChannelType>
<ebl:CustomerServiceNumber>3125559876</ebl:CustomerServiceNumber>
<ebl:BuyerEmailOptinEnable>1</ebl:BuyerEmailOptinEnable>
<ebl:TotalType>EstimatedTotal</ebl:TotalType>
<ebl:NoteToBuyer>Sample note to buyer.</ebl:NoteToBuyer>
<ebl:PaymentReason>None</ebl:PaymentReason>
<ebl:BuyerEmailOptinEnable xmlns="">1</ebl:BuyerEmailOptinEnable>
</ebl:SetExpressCheckoutRequestDetails>
</ns:SetExpressCheckoutRequest>
</ns:SetExpressCheckoutReq>
</soapenv:Body>
</soapenv:Envelope>
I finally got it to work. I had to move the FlatRateShippingOptions section below the PaymentDetails section. Here is the complete working XML request:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="urn:ebay:api:PayPalAPI" xmlns:ebl="urn:ebay:apis:eBLBaseComponents" xmlns:cc="urn:ebay:apis:CoreComponentTypes" xmlns:ed="urn:ebay:apis:EnhancedDataTypes">
<soapenv:Header>
<ns:RequesterCredentials>
<ebl:Credentials>
<ebl:Username>sdk-three_api1.sdk.com</ebl:Username>
<ebl:Password>QFZCWN5HZM8VBG7Q</ebl:Password>
<ebl:Signature>A-IzJhZZjhg29XQ2qnhapuwxIDzyAZQ92FRP5dqBzVesOkzbdUONzmOU</ebl:Signature>
</ebl:Credentials>
</ns:RequesterCredentials>
</soapenv:Header>
<soapenv:Body>
<ns:SetExpressCheckoutReq>
<ns:SetExpressCheckoutRequest>
<ebl:Version>106.0</ebl:Version>
<ebl:SetExpressCheckoutRequestDetails>
<ebl:MaxAmount currencyID="USD">20.00</ebl:MaxAmount>
<ebl:ReturnURL>https://www.domain.com/final.asp</ebl:ReturnURL>
<ebl:CancelURL>https://www.domain.com/reviewcart.asp</ebl:CancelURL>
<ebl:NoShipping>2</ebl:NoShipping>
<ebl:AddressOverride>1</ebl:AddressOverride>
<ebl:LocaleCode>US</ebl:LocaleCode>
<ebl:SolutionType>Sole</ebl:SolutionType>
<ebl:BuyerEmail>platfo_1255077030_biz#gmail.com</ebl:BuyerEmail>
<ebl:CallbackURL>https://www.domain.com/paypalcallback.asp</ebl:CallbackURL>
<ebl:PaymentDetails>
<ebl:OrderTotal currencyID="USD">20.00</ebl:OrderTotal>
<ebl:ItemTotal currencyID="USD">16.00</ebl:ItemTotal>
<ebl:ShippingTotal currencyID="USD">4.00</ebl:ShippingTotal>
<ebl:HandlingTotal currencyID="USD">0.00</ebl:HandlingTotal>
<ebl:TaxTotal currencyID="USD">0.00</ebl:TaxTotal>
<ebl:OrderDescription>Cart ID 123456</ebl:OrderDescription>
<ebl:ShipToAddress>
<ebl:Name>John Doe</ebl:Name>
<ebl:Street1>123 Main St</ebl:Street1>
<ebl:Street2>Apt 2</ebl:Street2>
<ebl:CityName>Chicago</ebl:CityName>
<ebl:StateOrProvince>IL</ebl:StateOrProvince>
<ebl:Country>US</ebl:Country>
<ebl:Phone>312-555-1234</ebl:Phone>
<ebl:PostalCode>60610</ebl:PostalCode>
</ebl:ShipToAddress>
<ebl:PaymentDetailsItem>
<ebl:Name>3001</ebl:Name>
<ebl:Quantity>2</ebl:Quantity>
<ebl:Tax currencyID="USD">0.00</ebl:Tax>
<ebl:Amount currencyID="USD">6.00</ebl:Amount>
<ebl:Description>test order</ebl:Description>
<ebl:ItemCategory>Physical</ebl:ItemCategory>
</ebl:PaymentDetailsItem>
<ebl:PaymentDetailsItem>
<ebl:Name>3002</ebl:Name>
<ebl:Quantity>4</ebl:Quantity>
<ebl:Tax currencyID="USD">0.00</ebl:Tax>
<ebl:Amount currencyID="USD">1.00</ebl:Amount>
<ebl:Description>test order</ebl:Description>
<ebl:ItemCategory>Physical</ebl:ItemCategory>
</ebl:PaymentDetailsItem>
<ebl:PaymentAction>Sale</ebl:PaymentAction>
</ebl:PaymentDetails>
<ebl:FlatRateShippingOptions>
<ebl:ShippingOptionIsDefault>true</ebl:ShippingOptionIsDefault>
<ebl:ShippingOptionAmount currencyID="USD">4.00</ebl:ShippingOptionAmount>
<ebl:ShippingOptionName>Ground</ebl:ShippingOptionName>
</ebl:FlatRateShippingOptions>
<ebl:FlatRateShippingOptions>
<ebl:ShippingOptionIsDefault>false</ebl:ShippingOptionIsDefault>
<ebl:ShippingOptionAmount currencyID="USD">20.00</ebl:ShippingOptionAmount>
<ebl:ShippingOptionName>NextDayAir</ebl:ShippingOptionName>
</ebl:FlatRateShippingOptions>
<ebl:CallbackTimeout>6</ebl:CallbackTimeout>
<ebl:ChannelType>Merchant</ebl:ChannelType>
<ebl:CustomerServiceNumber>3125559876</ebl:CustomerServiceNumber>
<ebl:BuyerEmailOptinEnable>1</ebl:BuyerEmailOptinEnable>
<ebl:TotalType>EstimatedTotal</ebl:TotalType>
<ebl:NoteToBuyer>Sample note to buyer.</ebl:NoteToBuyer>
<ebl:PaymentReason>None</ebl:PaymentReason>
<ebl:BuyerEmailOptinEnable xmlns="">1</ebl:BuyerEmailOptinEnable>
</ebl:SetExpressCheckoutRequestDetails>
</ns:SetExpressCheckoutRequest>
</ns:SetExpressCheckoutReq>
</soapenv:Body>
</soapenv:Envelope>
Thanks for your help in resolving this!
Here's a working sample of SetExpressCheckout with callback included, but it's using NVP instead of SOAP.
If you want to post a sample of your entire XML request I'll see if I can reproduce the issue and figure out the problem.
I think your problem is that you've got the FlatRateShippingOptions as a child element within PaymentDetails. Looking at the PayPal SOAP documentation for SEC, it looks like FlatRateShippingOptions should be above that, on the same level as CallbackURL.
Try moving it out of PaymentDetails and see if that helps.

WSO2 Synapse: setting a URL parameter

I am trying to do something that seems straightforward but can't get it to work. Basically I want the WSO2 API manager to add a URL parameter to a REST call.
Setup and Problem
I have a WSO2 API manager installed. I also have a Tomcat running with a bogus servlet called someservlet that simply logs anything it receives and returns ok. I have added the servlet as an API in the manager, so I can either call the servlet directly or via WSO2 API mgr.
I can run
curl http://localhost:8080/someservlet/servlet/toto?blob=blib&secret=pass
and the servlet works fine, it tells me it's received the path /toto and parameters blob and secret.
I can run
curl -H "Authorization: Bearer [...]" --url "http://192.168.23.1:8280/someservlet/1.0/toto?blob=blib&secret=pass"
And it does exactly the same. So far, so good.
What I want is to run:
curl -H "Authorization: Bearer MqVQuHqLNphtPV3XF1CtXVmbyP8a" --url "http://192.168.23.1:8280/someservlet/1.0/toto?blob=blib"
(note that I've removed the secret parameter)
...and still get the same result.
So basically I want API manager to add the URL parameter secret=pass.
First thing I tried: property mediator
Use Synapse XML config with property REST_URL_POSTFIX.
I edited the API config file, and added
<property name="REST_URL_POSTFIX" value="/blob?toto=titi" scope="axis2" type="STRING"/>
Now if I run
curl -H "Authorization: Bearer [...]" --url "http://192.168.23.1:8280/someservlet/1.0/toti?blab=blib&secret=puss"
it's as if I ran someservlet/1.0/blob?toto=titi: all my path and parameters have disappeared and been repaced with the configured ones. Hey, that's how it's supposed to work, isn't it!
Problems:
this doesn't add something to the URL, it sets the URL postfix, meaning that existing parameters disappear (in the above example, blab=blib)
it has to start with a "/" to be a valid value, so I can't just add &secret=pass (of course, because of problem 1, this would be useless anyway)
So basically this doesn't enable me to append the final &secret=pass.
Second thing I tried: rewrite URL mediator
I found this mediator, and although it probably won't do the trick, it's a good lead: I can just call with secret=foo, and get the mediator to replace it with secret=pass.
I put this in the config file:
<rewrite>
<rewriterule>
<action type="replace" value="pass" fragment="query" regex="foo"/>
</rewriterule>
</rewrite>
This doesn't work. At first I thought I didn't have the action parameters right. But the error message is:
Malformed URL when processing /someservlet/1.0/toti?blab=blib&secret=foo
Malformed? There's more detail in the exception stack trace:
java.net.MalformedURLException: no protocol: /someservlet/1.0/toti?blab=blib&secret=foo
So what's happening is that the mediators (log or rewrite) receive a message whose "To:" field points to a URL with no protocol!
Of course I've been googling around, and there are some cases where I find other people have logMediator: To: /blabla, and other (most) cases where they have logMediator: To: http ://blabla. I don't really see what's causing the difference. :-(
So this is where I'm stuck!! :-(
Option to be tried
I'm aware that there's probably a sledgehammer solution that should work:
use property to store the full path and all parameters
implement my own mediator (e.g. in Java) to modify these parameters
use property REST_URL_POSTFIX to put the modified postfix on the call
However I feel that this problem should have a simpler solution.
I have a kind of hope that someone will point me to a simple resource (mediator, sample, syntax error, anything) that I haven't found and that does just what I want. Optimism... :-)
Thanks for reading. Any ideas?
As i understood, you are trying to append the secret=pass to your endpoint url.
When you invoke the API , i belive you are sending that parameter.
Same time you are sending "blab=blib" parameter also. But in the ESB you need to change that to "toto=titi"
The method you used is right.(ie: Using property REST_URL_POSTFIX) In that case it will replace all requets parameter.
But before using that, you can save the request parameter and using the "REST_URL_POSTFIX"
you can achive the final REST url you need. (yes, that is the final option you mentioned as "to be tried")
In the "TO" address, you will only have address after port number.
If you use "" POST_TO_URI" property yopu will see the full adress URL printed in the log, but we use that if there is any proxy server configured between BE service and ESB
I've solved my problem.
Here's what I do:
in the config file, get the URL postfix using REST_URL_POSTFIX and
put it in a property
edit the property in a Java mediator
use REST_URL_POSTFIX to set the new postfix in XML
For the 1rst step, I use this line:
<property name="querystrings" expression="get-property('axis2', 'REST_URL_POSTFIX')"/>
this took some time to corner, because there are many lines out there that don't work for me, it took the 2 parameters (axis2 and REST...) to get it straight.
For the second step, this is the config XML:
<class name="mypackage.AddUrlParamMediator">
<property name="paramName" value="mykey"/>
<property name="paramValue" value="mysecret"/>
</class>
this is the mediator class (without imports):
public class AddUrlParamMediator extends AbstractMediator {
private String paramName = "default";
private String paramValue = "default";
public void setParamName(String paramName) {
this.paramName = paramName;
}
public void setParamValue(String paramValue) {
this.paramValue = paramValue;
}
public boolean mediate(MessageContext synapseMsgContext) {
SynapseLog log = this.getLog(synapseMsgContext);
String urlNewParam = this.paramName + "=" + this.paramValue;
Object queryStringsPpty = synapseMsgContext.getProperty("querystrings");
if (queryStringsPpty == null) {
log.error("### queryStringPpty=null, exiting!");
return true;
}
String queryStrings = queryStringsPpty.toString();
queryStrings = (queryStrings.contains("?"))
? queryStrings + "&" + urlNewParam
: queryStrings + "?" + urlNewParam;
synapseMsgContext.setProperty("querystrings", queryStrings);
return true;
}
}
and of course here's the third step in the XML config:
<property name="REST_URL_POSTFIX" expression="get-property('querystrings')" scope="axis2" type="STRING"/>
So all this basically sets a parameter at the end of the URL.
Hope this helps others.
For anyone who may have the same issue, here's another solution, simpler and works.
Go to the carbon admin portal, to the list of APIs, find the relevant API and click on it.
This leads to the XML config of the API.
After the "address" field (and at the same level in the XML) add the field:
<property name="Authorization" value="stuff to add" scope="transport"/>
This adds the property "Authorization" with value "stuff".