evaluate method takes long time - PMML models using Jpmml - java

Today I am using Jpmml in order to load pmml models in my code. but the'evaluate' method takes long time.
Here is the working code today :
String modelPath = "....";
ModelEvaluatorFactory factory = ModelEvaluatorFactory.newInstance();
InputStream in = new ByteArrayInputStream(modelPath.getBytes("UTF-8"));
PMML pmmlModel = JAXBUtil.unmarshalPMML(new StreamSource(in));
ModelEvaluator<?> evaluator = factory.newModelManager(pmmlModel);
List<FieldName> activeFields = evaluator.getActiveFields();
Map<FieldName, FieldValue> defaultFeatures = new HashMap<>();
//after filling the 'defaultFeatures' the line below takes long time
Map<FieldName, ?> results = evaluator.evaluate(defaultFeatures);
PMML example :
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<PMML xmlns="http://www.dmg.org/PMML-4_2" version="4.2">
<Header>
<Application name="JPMML-SkLearn" version="1.0-SNAPSHOT"/>
<Timestamp>2017-01-22T14:18:05Z</Timestamp>
</Header>
<DataDictionary>
<DataField name="GENDER" optype="categorical" dataType="string">
<Value value="0"/>
<Value value="1"/>
</DataField>
<DataField name="1GA_" optype="continuous" dataType="double"/>
//67000 rows of datafield
</DataDictionary>
<TransformationDictionary>
<DefineFunction name="logit" optype="continuous" dataType="double">
<ParameterField name="value" optype="continuous" dataType="double"/>
<Apply function="/">
<Constant dataType="double">1</Constant>
<Apply function="+">
<Constant dataType="double">1</Constant>
<Apply function="exp">
<Apply function="*">
<Constant dataType="double">-1</Constant>
<FieldRef field="value"/>
</Apply>
</Apply>
</Apply>
</Apply>
</DefineFunction>
</TransformationDictionary>
<MiningModel functionName="classification">
<MiningSchema>
<MiningField name="GENDER" usageType="target"/>
<MiningField name="1GA_"/>
//67000 rows of MiningField
</MiningSchema>
<Output>
<OutputField name="probability_0" feature="probability" value="0"/>
<OutputField name="probability_1" feature="probability" value="1"/>
</Output>
<LocalTransformations>
<DerivedField name="x1" optype="continuous" dataType="double">
<FieldRef field="1GA_"/>
</DerivedField>
//100000 rows
</LocalTransformations>
<Segmentation multipleModelMethod="modelChain">
<Segment id="1">
<True/>
<RegressionModel functionName="regression">
<MiningSchema>
<MiningField name="1GA_"/>
</MiningSchema>
<Output>
<OutputField name="decisionFunction_1" feature="predictedValue"/>
<OutputField name="logitDecisionFunction_1" optype="continuous" dataType="double" feature="transformedValue">
<Apply function="logit">
<FieldRef field="decisionFunction_1"/>
</Apply>
</OutputField>
</Output>
<RegressionTable intercept="-5.303370169392045">
<NumericPredictor name="x1" coefficient="0.18476274186559316"/>
//100000 rows of NumericPredictor
</RegressionTable>
</RegressionModel>
</Segment>
<Segment id="2">
<True/>
<RegressionModel functionName="regression">
<MiningSchema>
<MiningField name="logitDecisionFunction_1"/>
</MiningSchema>
<Output>
<OutputField name="logitDecisionFunction_0"
feature="predictedValue"/>
</Output>
<RegressionTable intercept="1.0">
<NumericPredictor name="logitDecisionFunction_1"
coefficient="-1.0"/>
</RegressionTable>
</RegressionModel>
</Segment>
<Segment id="3">
<True/>
<RegressionModel functionName="classification">
<MiningSchema>
<MiningField name="GENDER" usageType="target"/>
<MiningField name="logitDecisionFunction_1"/>
<MiningField name="logitDecisionFunction_0"/>
</MiningSchema>
<RegressionTable intercept="0.0" targetCategory="1">
<NumericPredictor name="logitDecisionFunction_1"
coefficient="1.0"/>
</RegressionTable>
<RegressionTable intercept="0.0" targetCategory="0">
<NumericPredictor name="logitDecisionFunction_0"
coefficient="1.0"/>
</RegressionTable>
</RegressionModel>
</Segment>
</Segmentation>
</MiningModel>
</PMML>
There is a thought of trying to use MLlib instead of Jpmml.
Any ideas?
Thanks

What do you mean by "load"? Is it "parse PMML document into an in-memory data structure" or "execute PMML document"?
Your code appears to be aim for the latter. But it will definitely fail, because the JAXBUtil#unmarshalPMML(Source) method is invoked with a byte array, which doesn't contain a valid PMML document (no XML parser will accept "....".getBytes("UTF-8")).
Also, what do you mean by "takes long time"? The JAXB framework has one-time initialization cost of around ~1 second. After that it can unmarshal ~200 to 500 MB (that's megabytes) of PMML content per second. How much more do you need?

Related

Java dom: getElementsByTagName()'s childNodes having null values

I am seeing a weird behaviour of w3c dom library for Java. For my XML which is formatted, I ran document.getElementsByTagName().getItem(0).getChildNodes() for fetching one of the tags' child nodes. Below is how my tag looks like:
<References>
<Reference Name="a" Value="1"/>
<Reference Name="b" Value="2"/>
<Reference Name="c" Value="3"/>
<Reference Name="d" Value="4"/>
<Reference Name="e" Value="5"/>
<Reference Name="f" Value="6"/>
<Reference Name="g" Value="7"/>
<Reference Name="h" Value="8"/>
<Reference Name="i" Value="9"/>
<Reference Name="j" Value="10"/>
<Reference Name="k" Value="11"/>
<Reference Name="l" Value="12"/>
</References>
Below is my code:
NodeList nodeList = document.getElementsByTagName("References").item(0).getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
NamedNodeMap currentItemAttributes = nodeList.item(i).getAttributes();
String currentItemName = currentItemAttributes.getNamedItem("Name").getNodeValue();
name=currentItemName;
}
Here, I get null value for every alternate node as explained below:
nodeList.item(0).getAttributes() returns null
nodeList.item(1).getAttributes().getNamedItem("Name").getNodeValue() returns a
nodeList.item(2).getAttributes() returns null
nodeList.item(3).getAttributes().getNamedItem("Name").getNodeValue() returns b
and so on.
Interestingly, if I minify my xml file to a single line and remove all the extra spaces, it works fine and I do not get alternate null values.
If anyone can give me a solution to this, it'd be a great help.
It's because the getChildNodes() is getting all the NODES.
Try
document.getElementsByTagName("References").item(0).getElementsByTagName("Reference");
Or you can check each node for type (Element) and name (Reference) and handle it then.

Consuming WCF service in Java does not generate an interface

We have a pretty big WCF service that we use for quite some time, but up until now we've been connecting to it only via c#. Now we have a need to connect to it from Java.
I found out quickly that if I use Eclipse and go to new/other/Web Service Client I can put the WSDL link there to auto generate the code.
Doing that straight away did not produce much though. I obtained two files, one of which had empty body.
This is my first issue with this auto generation tool - it creates something, but I don't see any log of what it succeeded and what failed in creating.
I searched and found out that i had to change the bindings to basicHttpBinding, and make sure that httpGetEnabled is set to "true". After this change, auto generation in Java produces a lot of code, i get the data contract schemas and so on. And I get 4 files under the 'org.tempuri' namespace:
BasicHttpBinding_IMyServiceStub.java
IMyServiceProxy.java
MyService.java
MyServiceLocator.java
However looking at some tutorials, it seems I should get a fifth one, IMyService.java - which I did not get. And, I do have errors in the generated code pointing out that indeed IMyService cannot be resolved, as its being used in a few places, but its definition was not auto-generated.
Since I have no logs of what has failed during auto generation, I'm kind of lost what to look for as a culprit.
Does anyone have any experience on either:
a) locating logs for auto generation that would tell me what went
wrong
b) directly know what causes the Interface class not to be generated?
I'm suspecting i have to change something more in webconfig file on the server. A second guess is that perhaps we use some c# construct not recognised by java...or something.
Anyway, completly lost here, as there is no feedback of what went wrong.
Here is a webconfig file from the IIS server.
<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="XXX" connectionString="XXX" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation targetFramework="4.0"/>
<customErrors mode="Off"/>
<httpRuntime executionTimeout="5400" requestValidationMode="2.0"/>
<identity impersonate="false"/>
</system.web>
<system.serviceModel>
<bindings>
<customBinding>
<binding name="bindingNetTcp" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<binaryMessageEncoding maxSessionSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binaryMessageEncoding>
<tcpTransport maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
<binding name="bindingHttps" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binaryMessageEncoding>
<httpsTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" allowCookies="true" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="StreamedResponse" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/>
</binding>
<binding name="bindingHttp" closeTimeout="01:00:00" openTimeout="01:00:00" receiveTimeout="01:00:00" sendTimeout="01:00:00">
<binaryMessageEncoding maxReadPoolSize="2147483647" maxWritePoolSize="2147483647" maxSessionSize="2147483647">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
</binaryMessageEncoding>
<httpTransport manualAddressing="false" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" allowCookies="true" authenticationScheme="Anonymous" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" keepAliveEnabled="true" maxBufferSize="2147483647" proxyAuthenticationScheme="Anonymous" realm="" transferMode="StreamedResponse" unsafeConnectionNtlmAuthentication="false" useDefaultWebProxy="true"/>
</binding>
</customBinding>
<netTcpBinding>
<binding name="NetTcpBinding_IGodService" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Transport">
<transport clientCredentialType="Certificate" protectionLevel="EncryptAndSign"/>
<message clientCredentialType="Windows"/>
</security>
</binding>
<binding name="NetTcpBinding_IGodService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<security mode="Transport">
<transport clientCredentialType="Certificate" protectionLevel="EncryptAndSign"/>
<message clientCredentialType="Windows"/>
</security>
</binding>
<binding name="CustomBinding_IDQMServer">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="XXX.XXX" behaviorConfiguration="XXXBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://example.com:4502/xxx/xxx/"/>
<add baseAddress="http://example.com/xxx/xxx/"/>
</baseAddresses>
</host>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="" binding="customBinding" bindingConfiguration="bindingHttps" contract="xxx.Ixxx"/>
<endpoint address="" binding="basicHttpBinding" contract="xxx.Ixxx"/>
<endpoint address="" binding="customBinding" bindingConfiguration="bindingNetTcp" contract="xxx.Ixxx"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="xxxBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceThrottling maxConcurrentCalls="2500" maxConcurrentInstances="2147483647" maxConcurrentSessions="2147483647"/>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SrvBehavior">
<clientCredentials>
<clientCertificate findValue="xxx" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
<serviceCertificate>
<authentication certificateValidationMode="PeerTrust"/>
</serviceCertificate>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<defaultDocument>
<files>
<add value="xxx.svc"/>
</files>
</defaultDocument>
</system.webServer>
</configuration>
Please note that im using basicHttpBinding there, previously it was "bindingHttp" like the https one, but it didnt work at all.
EDIT: As pointed out in the comment section, we're using Lists in the service quite a lot, an example of the c# wcf interface:
public class ListResults<T>//our own custom return class
{
public List<T> Result { get; set; }
public long? ID { get; set; }
public int? Error { get; set; }
}
[SecurityOperationBehavior]
[OperationContract]
ListResults<SomeDataType> SomeListFunction(string param1, long? param2, bool? param3);

Duke deduplication engine : exact same record not matched

I am attempting to use Duke to match records from one csv to another.First csv and second both has ID,Model,Price,CompanyName,Review,Url columns. I am trying to match to another csv to find duplicates records.
package no.priv.garshol.duke;
import no.priv.garshol.duke.matchers.PrintMatchListener;
public class RunDuke {
public static void main(String[] argv) throws Exception {
Configuration config =
ConfigLoader
.load("/home/kishore/Duke-master/doc/example-data/presonalCare.xml");
Processor proc = new Processor(config);
proc.addMatchListener(new PrintMatchListener(true, true, true, false, config.getProperties(),
true));
proc.link();
proc.close();
}
}
Here is an example of personalCare.xml:
<!-- language: xml -->
<!-- For more information, see https://github.com/larsga/Duke/wiki/ Improvements
needed: - some area numbers have spaces in them - not stripping accents from
names -->
<duke>
<schema>
<threshold>0.7</threshold>
<property type="id">
<name>ID</name>
</property>
<property>
<name>Model</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.4</low>
<high>0.8</high>
</property>
<property>
<name>Price</name>
<comparator>no.priv.garshol.duke.comparators.ExactComparator</comparator>
<low>0.04</low>
<high>0.73</high>
</property>
<property>
<name>CompanyName</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.4</low>
<high>0.8</high>
</property>
<property>
<name>Review</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.12</low>
<high>0.93</high>
</property>
<property>
<name>Url</name>
<comparator>no.priv.garshol.duke.comparators.Levenshtein</comparator>
<low>0.12</low>
<high>0.93</high>
</property>
</schema>
<database class="no.priv.garshol.duke.databases.InMemoryDatabase">
</database>
<group>
<csv>
<param name="input-file" value="personal_care_11.csv" />
<param name="header-line" value="false" />
<column name="1" property="ID" />
<column name="2" property="Model" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="3" property="Price" />
<column name="4" property="CompanyName" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="5" property="Review" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="6" property="Url" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
</csv>
</group>
<group>
<csv>
<param name="input-file" value="personal_care_11.csv" />
<param name="header-line" value="false" />
<column name="1" property="ID" />
<column name="2" property="Model" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="3" property="Price" />
<column name="4" property="CompanyName" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="5" property="Review" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
<column name="6" property="Url" cleaner="no.priv.garshol.duke.cleaners.LowerCaseNormalizeCleaner"/>
</csv>
</group>
</duke>
The above code is working fine but it does not match the exact record example
STHDRNFKAQ4AFYE8,Littmann 3M Classic II S.E Acoustic
Stethoscope,6297,Littmann,,http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=STHDRNFKAQFAFYE8&affid=3ba0de4902524e2b90e43b84b89ea0ef
which is in both csv files. I also want to know the work of low and high property value which is given in .xml file, how to decide the low and high value for column value.
You are doing record linkage (two data sets) and not deduplication (single data set), so take out the .deduplicate() call.
Also, please don't use the 'no.priv.garshol.duke' package name. You should never use domain names you don't own yourself.
Anyway, the reason you can't find any matches is that the two records have the same ID. Duke verifies that it's not reporting records as matching themselves, and so the match gets filtered out. If you make a copy of the csv file and use that for group 2, then make a change to the ID then Duke finds the duplicate.
Here's what happens when I try that:
[lars.garshol#laptop tmp]$ java -cp ~/cvs-co/duke/duke-core/target/duke-core-1.3-SNAPSHOT.jar:. no.priv.garshol.duke.Duke --showmatches presonalCare.xml
MATCH 0.9982630751840313
ID: 'SHDRNFKAQ4AFYE8', Model: 'littmann 3m classic ii s.e acoustic stethoscope', Price: '6297', CompanyName: 'littmann', Url: 'http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=sthdrnfkaqfafye8&affid=3ba0de4902524e2b90e43b84b89ea0ef',
ID: 'STHDRNFKAQ4AFYE8', Model: 'littmann 3m classic ii s.e acoustic stethoscope', Price: '6297', CompanyName: 'littmann', Url: 'http://dl.flipkart.com/dl/littmann-3m-classic-ii-s-e-acoustic-stethoscope/p/itme3uhzbqxhzfda?pid=sthdrnfkaqfafye8&affid=3ba0de4902524e2b90e43b84b89ea0ef',

Issue with XSLT Transformation using WSO2 ESB

I struggling with XSLT transformer mediator using XSLT mediator in wso2 esb 4.8.1.
The xslt is :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
xmlns:ns="http://ep.service.ims.com"
xmlns:ax21="http://ep.service.ims.com/xsd"
exclude-result-prefixes="ns fn">
<xsl:param name="amount"/>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//ns:getResponse" />
</xsl:template>
<xsl:template match="ns:getResponse" xmlns:ns="http://ep.service.ims.com">
<ep:credit xmlns:ep="http://ep.service.ims.com" xmlns:xsd="http://ep.service.ims.com/xsd">
<ep:info>
<xsd:amount>
<xsl:value-of select="$amount"/>
</xsd:amount>
<xsd:personInfo>
<xsd:address>
<xsl:value-of select="ns:return/ax21:address"/>
</xsd:address>
<xsd:id>
<xsl:value-of select="ns:return/ax21:id"/>
</xsd:id>
<xsd:name>
<xsl:value-of select="ns:return/ax21:name"/>
</xsd:name>
</xsd:personInfo>
</ep:info>
</ep:credit>
</xsl:template>
</xsl:stylesheet>
and the request XML is :
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getResponse xmlns:ns="http://ep.service.ims.com">
<ns:return xsi:type="ax23:PersonInfo" xmlns:ax23="http://ep.service.ims.com/xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ax23:address>IMS Heath, Omega C, India, bnag</ax23:address>
<ax23:id>100</ax23:id>
<ax23:name>WSO2</ax23:name>
</ns:return>
</ns:getResponse>
</soapenv:Body>
</soapenv:Envelope>
I tried the XSLT transformation in eclipse and some online tool like (http://xslt.online-toolz.com/tools/xslt-transformation.php ) and it is working fine. However when I am trying the same in WSO2 ESB, I am facing following exception.....
org.apache.synapse.mediators.transform.XSLTMediator} -
Fatal error occurred in stylesheet parsing :
net.sf.saxon.trans.XPathException:
The supplied file does not appear to be a stylesheet Value {name ='null', keyValue ='xslt1'}
{org.apache.synapse.mediators.transform.XSLTMediator}
javax.xml.transform.TransformerConfigurationException: Failed to compile stylesheet. 1 error detected.
at net.sf.saxon.PreparedStylesheet.prepare(PreparedStylesheet.java:220)
org.apache.synapse.core.axis2.SynapseCallbackReceiver.receive(SynapseCallbackReceiver.java:170)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:180)
at org.apache.synapse.transport.passthru.ClientWorker.run(ClientWorker.java:225)
TID: [0] [ESB] [2014-10-08 13:53:20,705] ERROR
{org.apache.synapse.mediators.transform.XSLTMediator} -
Unable to perform XSLT transformation using :
Value {name ='null', keyValue ='xslt1'} against source XPath : s11:Body/child::*[position()=1] | s12:Body/child::*[position()=1]
reason : Error creating XSLT transformer using : Value {name ='null', keyValue ='xslt1'}
{org.apache.synapse.mediators.transform.XSLTMediator}
org.apache.synapse.SynapseException: Error creating XSLT transformer using : Value {name ='null', keyValue ='xslt1'} at
org.apache.synapse.mediators.AbstractMediator.handleException(AbstractMediator.java:313)
Caused by: javax.xml.transform.TransformerConfigurationException:
Failed to compile stylesheet. 1 error detected.
The synapse proxy xml is:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="CreditProxy" transports="https http" startOnLoad="true" trace="disable">
<target>
<inSequence>
<log level="full">
<property name="sequence" value="inSequence - request for CreditProxy"/>
</log>
<property xmlns:pep="http://com.ims.proxy" name="ORG_ID" expression="//pep:credit/pep:id"/>
<property xmlns:pep="http://com.ims.proxy" name="ORG_AMOUNT" expression="//pep:credit/pep:amount"/>
<enrich>
<source type="inline" clone="true">
<pep:get xmlns:pep="http://ep.service.ims.com">
<pep:id>?</pep:id>
</pep:get>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" property="ORG_ID"/>
<target xmlns:pep="http://ep.service.ims.com" xpath="//pep:get/pep:id"/>
</enrich>
<log level="full">
<property name="sequence" value="inSequence - request for PersonInfoService"/>
</log>
<property name="STATE" value="PERSON_INFO_REQUEST"/>
<send>
<endpoint key="PersonInfoEpr"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('STATE')">
<case regex="PERSON_INFO_REQUEST">
<log level="full">
<property name="sequence" value="outSequence - STATE 01 - response from PersonInfoService"/>
</log>
<xslt key="xslt">
<property name="amount" expression="get-property('ORG_AMOUNT')"/>
</xslt>
<log level="full">
<property name="sequence" value="outSequence - STATE 01 - request for CreditService"/>
</log>
<property name="STATE" value="CREDIT_REQUEST"/>
<send>
<endpoint key="CreditEpr"/>
</send>
</case>
<case regex="CREDIT_REQUEST">
<log level="full">
<property name="sequence" value="outSequence - STATE 02 - response from CreditService"/>
</log>
<send/>
</case>
</switch>
</outSequence>
</target>
<publishWSDL uri="file:resources/CreditProxy.wsdl"/>
</proxy>
What may be the cause of the exception if the XSLT transformation is working fine in other tool ?
The key in the proxy is correct. I might have pasted the wrong XML proxy,
Here is the proxy:
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="CreditProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<log level="full">
<property name="sequence" value="inSequence - request for CreditProxy"/>
</log>
<property xmlns:pep="http://com.ims.proxy"
name="ORG_ID"
expression="//pep:credit/pep:id"/>
<property xmlns:pep="http://com.ims.proxy"
name="ORG_AMOUNT"
expression="//pep:credit/pep:amount"/>
<enrich>
<source type="inline" clone="true">
<pep:get xmlns:pep="http://ep.service.ims.com">
<pep:id>?</pep:id>
</pep:get>
</source>
<target type="body"/>
</enrich>
<enrich>
<source type="property" clone="true" property="ORG_ID"/>
<target xmlns:pep="http://ep.service.ims.com" xpath="//pep:get/pep:id"/>
</enrich>
<log level="full">
<property name="sequence" value="inSequence - request for PersonInfoService"/>
</log>
<property name="STATE" value="PERSON_INFO_REQUEST"/>
<send>
<endpoint key="PersonInfoEpr"/>
</send>
</inSequence>
<outSequence>
<switch source="get-property('STATE')">
<case regex="PERSON_INFO_REQUEST">
<log level="full">
<property name="sequence"
value="outSequence - STATE 01 - response from PersonInfoService"/>
</log>
<xslt key="xslt1">
<property name="amount" expression="get-property('ORG_AMOUNT')"/>
</xslt>
<log level="full">
<property name="sequence"
value="outSequence - STATE 01 - request for CreditService"/>
</log>
<property name="STATE" value="CREDIT_REQUEST"/>
<send>
<endpoint key="CreditEpr"/>
</send>
</case>
<case regex="CREDIT_REQUEST">
<log level="full">
<property name="sequence"
value="outSequence - STATE 02 - response from CreditService"/>
</log>
<send/>
</case>
</switch>
</outSequence>
</target>
<publishWSDL uri="file:resources/creditproxy/CreditProxy.wsdl"/>
<description/>
</proxy>
Local entry:
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="xslt1" src="file:resources/creditproxy/personToCredit.xslt"></localEntry>
There was a problem with the local entry. Finally, I was able to fix this issue by adding a local entry like this in the synapse config
<localEntry key="xslt99">
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ax21="http://ep.service.ims.com/xsd"
xmlns:ns="http://ep.service.ims.com"
xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
version="1.0"
exclude-result-prefixes="ns fn">
<xsl:param name="amount"/>
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates select="//ns:getResponse"/>
</xsl:template>
<xsl:template match="ns:getResponse">
<ep:credit xmlns:ep="http://ep.service.ims.com" xmlns:xsd="http://ep.service.ims.com/xsd">
<ep:info>
<xsd:amount>
<xsl:value-of select="$amount"/>
</xsd:amount>
<xsd:personInfo>
<xsd:address>
<xsl:value-of select="ns:return/ax21:address"/>
</xsd:address>
<xsd:id>
<xsl:value-of select="ns:return/ax21:id"/>
</xsd:id>
<xsd:name>
<xsl:value-of select="ns:return/ax21:name"/>
</xsd:name>
</xsd:personInfo>
</ep:info>
</ep:credit>
</xsl:template>
</xsl:stylesheet>
<description/>
</localEntry>
Initially I was trying to add the local entries like this
<localEntry xmlns="http://ws.apache.org/ns/synapse" key="xslt1" src="file:resources/creditproxy/personToCredit.xslt"></localEntry>
But still I don't know how to specify a xslt file in local entry.?

JAXB Parsing an XML file with variables (e.g. $(var1) )

I'm interested to parse an XML that contains variables (which are defined by me inside the XML).
Here's an example of the XML files:
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
<Parents>
<Parent id="$(parent-id)">
<Children>
<Child id="$(child-id)">
</Child>
</Children>
</Parent>
</Parents>
Is there a utility or some standard way to do so in Java? (using JAXB possibly)
Or should I implement this "mini" parsing mechanism by myself?
(A mechanism that identifies the variables and plants them inside the XML, and only later calls JAXB flows)
Thanks a lot in advance!
Use an XSLT transformation to convert your XML into an XSLT stylesheet and then execute the XSLT stylesheet. It's simple enough to convert
<parameters>
<parameter name="parent-id" value="1" />
<parameter name="child-id" value="1" />
</parameters>
into
<xsl:param name="parent-id" select="1" />
<xsl:param name="child-id" select="1" />
and
<Parent id="$(parent-id)">
into
<Parent id="{$parent-id}">
and to add a wrapper xsl:stylesheet and xsl:template element, and then you're done.

Categories

Resources