on 08-29-2016 10:17 PM
Hello,
I would like pass user credentials based on the system Id in xslt mapping.
May i know how to get PI system id during run time?
Thanks
Hi Bhavana,
Try this
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
so using SystemName from above you can setup you credentials for different environment as
<User ID>
<xsl:choose>
<xsl:when normalize-space($SystemName) = 'DEV'">
<xsl:value-of select="'XXXXXX'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = 'QA'">
<xsl:value-of select="'YYYYY'"></xsl:value-of>
</xsl:when>
<xsl:choose>
<User ID>
Regards
Kalyan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Have you already created this?
package com.utils;
public class PropertyUtil {
public static String getSystemProperty(String prop){
String retString = null;
retString = (String)System.getProperty(prop);
return retString;
}
public static String getSAPSystem(){
String retString = null;
retString = (String)System.getProperty("SAPSYSTEM");
return retString;
}
public static String getSAPSystemName(){
String retString = null;
retString = (String)System.getProperty("SAPSYSTEMNAME");
return retString;
}
}
Hello Kalyan,
I have question related to below statement to create .java & .class files.
Write the code, compile it; copy both the files(.java and .class) and paste it in folder according to the package created in the code.
Here, package is com.utils. So both the files (.java and .class) should go under folder Com/utils.
Once i have both the files where exactly i have to place these files? not sure where can i find out Com/utils folder.
Also do i need to deploy this in ESR?
Regards
I have both .java & .class files generated and zipped to import under Imported Archive.
So now my question is how to make modifications to below my existing xsl program so that i can make if else condition based user/password passing
My xslt code is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<TokenUser>User1</TokenUser>
<TokenPassword>pwd1</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Please help me how to pass user/password based on system ID whether it is QA or Prod.
I would suggest you go through the basics of XSLT in W3schools.com
You can place the code under <TokenUser></TokenUser> and <TokenPassword>pwd1</TokenPassword> as something like the following
<TokenUser>
<xsl:choose>
<xsl:when normalize-space($SystemName) = 'DEV'">
<xsl:value-of select="'User1'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = 'QA'">
<xsl:value-of select="'User2'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when normalize-space($SystemName) = 'DEV'">
<xsl:value-of select="'pwd1'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = 'QA'">
<xsl:value-of select="'pwd2'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenPassword>
Regards
Kalyan.
Hello Kalyan,
I am getting error while saving saying that file is not valid and cursor stopping at below place where marked in red.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:propertyUtil ="com.utils. PropertyUtil">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="srting (propertyUtil:getSAPSystemName())"/>
<TokenUser>
<xsl:choose>
<xsl:when normalize-space($SystemName) = "PID">
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = "PIQ">
<xsl:value-of select="'ABC'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when normalize-space($SystemName) = "PID">
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = "PIQ">
<xsl:value-of select="'789'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Regards
Hello Ram,
Good catch. Appreciated.
Even though i corrected it i am getting the same issue. Are you able to copy paste in your xmlspy and able to save it?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:propertyUtil ="com.utils.PropertyUtil">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<TokenUser>
<xsl:choose>
<xsl:when normalize-space($SystemName) = "PID">
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = "PIQ">
<xsl:value-of select="'ABC'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when normalize-space($SystemName) = "PID">
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when normalize-space($SystemName) = "PIQ">
<xsl:value-of select="'789'"></xsl:value-of>
</xsl:when>
<xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
use the below.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:propertyUtil ="com.utils.PropertyUtil">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<TokenUser>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'ABC'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'789'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Hello Ramkumar,
Excellent. Thank you very much for correcting the code.
I have .java & .class files created and with me. So can i just directly import these 2 file along with xslt.zip file under Imported Archive from my local desktop ? or should i place these .java & .class files somewhere like mentioned below? This folder(Com/utils) i could see we are maintaining on some server so If i need to place these 2 java files there then while import to ESR, how to access to this remote folder which is not a local in my machine.
Write the code, compile it; copy both the files(.java and .class) and paste it in folder according to the package created in the code.
Here, package is com.utils. So both the files (.java and .class) should go under folder Com/utils.
Thanks
Hi Bhavana!
If you develop your java classes in Eclipse-based IDE (NWDS, for example) you could use Export-JAR file option to create .JAR file with your class on local drive and then import it as Imported Archive to ESR.
XSL transformation can be simply zipped and imported to ESR as well.
Regards, Evgeniy.
Also it's worth mention that you don't need any user class to call native java class function such as java.lang.System.getProperty(), for example.
1. In case of using external XSLT processor like Saxon you just define namespace as:
xmlns:utils = "java:java.lang.System"
and call required function of that class in your XSL transformation:
<xsl:value-of select="utils:getProperty('os.name')"/>
2. In case of using built-in Xalan proccessor of your PI system you define namespaces like this:
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:utils="xalan://java.lang.System"
and perform the call:
<xsl:value-of select="utils:getProperty('SAPSYSTEMNAME')"/>
That's all. No user-defined classes required.
Regards, Evgeniy.
Hello,
Java developer created .java & .class files for the given java code and provided those files to me.
Imported xslt.zip and those 2 zipped java files under imported Archives.
So now when i execute operation mapping to test this, i am getting below error
Transformer Configuration Exception occurred when loading XSLT XYZ_SOAP_Header.xsl; details: Cannot find external method 'com.utils.PropertyUtil.getSAPSystemName' (must be public).
See error logs for details
To resolve this i have selected check box "Use SAP XML Toolkit" option in operation mapping. But now i am getting below error..
Call XSLT processor with stylsheet XYZ_SOAP_Header.xsl. |
Method fatalError called, terminate transformation, because of
javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class
at com.sap.engine.lib.jaxp.TransformerImpl.transform(TransformerImpl.java:250)
Thanks
Hello Ram,
Do i need to save these 2 java files(.JAVA & .class) to any specific folder other than my local directory to import into ESR ?
Because the error i am getting is trying to locate class "com.utils.PropertyUtil" and not found.
javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class
Thanks
Hi Bhavana!
1. Look at my post above - YOU DON'T NEED user class for your requirement.
2. If you don't use external XSLT transformer class - again, see my answer above. Try to define namespaces in your XSL transformation like this:
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:utils="xalan://com.utils.PropertyUtil"
...
<xsl:variable name="myvar" select="utils:getSAPSystemName()"/>
Regards, Evgeniy.
Hello,
I have defined namespaces like you mentioned and this is what my xslt code now. But still i am getting error like below. Please suggest if anything need to be changed.
javax.xml.transform.TransformerException: com.sap.engine.lib.xsl.xpath.XPathException: Could not load class: xalan://com.utils.PropertyUtil required for extension library. -> com.sap.aii.ib.server.mapping.execution.MappingClassNotFoundException: com/utils/PropertyUtil.class |
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan" xmlns:propertyUtil="xalan://com.utils.PropertyUtil">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<TokenUser>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'abc'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'asd'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIP"'>
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'6789'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIP"'>
<xsl:value-of select="'3456'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Hi Bhavana,
I have modified your XSLT.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:utils="xalan://java.lang.System" xmlns:xalan="http://xml.apache.org/xalan" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="utils:getProperty('SAPSYSTEMNAME')"/>
<TokenUser>
<xsl:choose>
<xsl:when test="normalize-space($SystemName)="POD"">
<xsl:value-of select="'abc'">
</xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space($SystemName)="POQ"">
<xsl:value-of select="'asd'">
</xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space($SystemName)="POP"">
<xsl:value-of select="'xyz'">
</xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when test="normalize-space($SystemName)="POD"">
<xsl:value-of select="'1234'">
</xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space($SystemName)="POQ"">
<xsl:value-of select="'6789'">
</xsl:value-of>
</xsl:when>
<xsl:when test="normalize-space($SystemName)="POP"">
<xsl:value-of select="'3456'">
</xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Test:
Regards,
Praveen.
Hi Bhavana!
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xalan="http://xml.apache.org/xalan"
xmlns:propertyUtil="xalan://java.lang.System">
<xsl:variable name="SystemName" select="normalize-space(propertyUtil:getProperty('SAPSYSTEMNAME'))"/>
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<TokenUser>
<xsl:choose>
<xsl:when test="$SystemName='PID'">
<xsl:value-of select="'abc'"></xsl:value-of>
</xsl:when>
<xsl:when test="$SystemName='PIQ'">
<xsl:value-of select="'asd'"></xsl:value-of>
</xsl:when>
<xsl:when test="$SystemName='PIP'">
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when test="$SystemName='PID'">
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when test="$SystemName='PIQ'">
<xsl:value-of select="'6789'"></xsl:value-of>
</xsl:when>
<xsl:when test="$SystemName='PIP'">
<xsl:value-of select="'3456'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
It's no need to call "normalize-space()" function in all of "when" branches. You can do it once when assigning value to your variable.
Regards, Evgeniy.
I am using this xslt code & java code to generate .class & .java. Please let me know if am missing anything.
XSLT code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:propertyUtil ="com.utils.PropertyUtil">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<xsl:variable name="SystemName" select="string(propertyUtil:getSAPSystemName())"/>
<TokenUser>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'abc'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'asd'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIP"'>
<xsl:value-of select="'xyz'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenUser>
<TokenPassword>
<xsl:choose>
<xsl:when test='normalize-space($SystemName)="PID"'>
<xsl:value-of select="'1234'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIQ"'>
<xsl:value-of select="'6789'"></xsl:value-of>
</xsl:when>
<xsl:when test='normalize-space($SystemName)="PIP"'>
<xsl:value-of select="'3456'"></xsl:value-of>
</xsl:when>
</xsl:choose>
</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
Java code to create .java & .class
package com.utils;
public class PropertyUtil {
public static String getSystemProperty(String prop){
String retString = null;
retString = (String)System.getProperty(prop);
return retString;
}
public static String getSAPSystem(){
String retString = null;
retString = (String)System.getProperty("SAPSYSTEM");
return retString;
}
public static String getSAPSystemName(){
String retString = null;
retString = (String)System.getProperty("SAPSYSTEMNAME");
return retString;
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bhavana!
As Ramkumar has already mentioned above you should use XSL with java extensions.
Create java class with static methods and call the required method within your xsl transformation.
Add namespace definition to your XSLT:
xmlns:myjava="com.company.xpi.mapping.xslt.XSLTUtils", where namespace name is the full qualified path to your java class including package name.
Call your java method:
<xsl:variable name="Var1" select="myjava:MyMethod()"/>, where "MyMethod()" is the required static method of your class.
By the way, the same approach is used to call lookups in XSL transformations.
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
My exact requirement here is I am using xslt mapping to add soap header(User/Password) during run time. I have to pass user/password credentials to soap header based on the system name based on QA or PROD.
My xslt code is:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ValidationSoapHeader xmlns="https://www.xyz.com/WebServices/WebMethods">
<TokenUser>User1</TokenUser>
<TokenPassword>pwd1</TokenPassword>
</ValidationSoapHeader>
</soap:Header>
<soap:Body>
<xsl:copy-of select="*"/>
</soap:Body>
</soap:Envelope>
</xsl:template>
</xsl:stylesheet>
So where exactly i have to introduce the xsl code in this to make a if else condition to pass user/password based on sap system id?
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.