You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2006/10/15 22:30:15 UTC
svn commit: r464271 - in /incubator/servicemix/trunk/servicemix-saxon/src:
main/java/org/apache/servicemix/saxon/
test/java/org/apache/servicemix/saxon/ test/resources/
Author: gnodet
Date: Sun Oct 15 13:30:14 2006
New Revision: 464271
URL: http://svn.apache.org/viewvc?view=rev&rev=464271
Log:
SM-705: Static Parameter map injected into XsltComponent
Added:
incubator/servicemix/trunk/servicemix-saxon/src/test/resources/parameter-test.xsl
Modified:
incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
incubator/servicemix/trunk/servicemix-saxon/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
incubator/servicemix/trunk/servicemix-saxon/src/test/resources/spring.xml
Modified: incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java?view=diff&rev=464271&r1=464270&r2=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/SaxonEndpoint.java Sun Oct 15 13:30:14 2006
@@ -5,6 +5,7 @@
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
+import java.util.Map;
import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
@@ -36,6 +37,7 @@
private Expression expression;
private Resource wsdlResource;
private SourceTransformer sourceTransformer = new SourceTransformer();
+ private Map parameters;
/**
* @param sourceTransformer the sourceTransformer to set
@@ -161,6 +163,20 @@
*/
public void setCopySubject(boolean copySubject) {
this.copySubject = copySubject;
+ }
+
+ /**
+ * @return the parameters
+ */
+ public Map getParameters() {
+ return parameters;
+ }
+
+ /**
+ * @param parameters the parameters to set
+ */
+ public void setParameters(Map parameters) {
+ this.parameters = parameters;
}
// Interface methods
Modified: incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java?view=diff&rev=464271&r1=464270&r2=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XQueryEndpoint.java Sun Oct 15 13:30:14 2006
@@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
+import java.util.Map;
import java.util.Properties;
import javax.jbi.management.DeploymentException;
@@ -136,6 +137,14 @@
String name = (String) iter.next();
Object value = in.getProperty(name);
dynamicEnv.setParameter(name, value);
+ }
+ Map parameters = getParameters();
+ if (parameters != null) {
+ for (Iterator iter = parameters.keySet().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = parameters.get(name);
+ dynamicEnv.setParameter(name, value);
+ }
}
dynamicEnv.setParameter("exchange", exchange);
dynamicEnv.setParameter("in", in);
Modified: incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java?view=diff&rev=464271&r1=464270&r2=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java (original)
+++ incubator/servicemix/trunk/servicemix-saxon/src/main/java/org/apache/servicemix/saxon/XsltEndpoint.java Sun Oct 15 13:30:14 2006
@@ -19,6 +19,7 @@
import java.io.ByteArrayOutputStream;
import java.io.StringWriter;
import java.util.Iterator;
+import java.util.Map;
import javax.jbi.management.DeploymentException;
import javax.jbi.messaging.MessageExchange;
@@ -165,6 +166,14 @@
String name = (String) iter.next();
Object value = in.getProperty(name);
transformer.setParameter(name, value);
+ }
+ Map parameters = getParameters();
+ if (parameters != null) {
+ for (Iterator iter = parameters.keySet().iterator(); iter.hasNext();) {
+ String name = (String) iter.next();
+ Object value = parameters.get(name);
+ transformer.setParameter(name, value);
+ }
}
transformer.setParameter("exchange", exchange);
transformer.setParameter("in", in);
Modified: incubator/servicemix/trunk/servicemix-saxon/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java?view=diff&rev=464271&r1=464270&r2=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java (original)
+++ incubator/servicemix/trunk/servicemix-saxon/src/test/java/org/apache/servicemix/saxon/SaxonComponentTest.java Sun Oct 15 13:30:14 2006
@@ -16,6 +16,8 @@
*/
package org.apache.servicemix.saxon;
+import java.util.Date;
+
import javax.jbi.messaging.ExchangeStatus;
import javax.jbi.messaging.InOut;
import javax.xml.namespace.QName;
@@ -24,6 +26,7 @@
import org.apache.servicemix.client.DefaultServiceMixClient;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.util.DOMUtil;
import org.apache.servicemix.tck.SpringTestSupport;
import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
@@ -31,8 +34,6 @@
import org.w3c.dom.Element;
public class SaxonComponentTest extends SpringTestSupport {
-
-
public void testXslt() throws Exception {
DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
@@ -101,6 +102,27 @@
assertEquals("2005", textValueOfXPath(el, "/transformed/book/year"));
client.done(me);
}
+
+ public void testXsltWithParam() throws Exception {
+ DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
+ InOut me = client.createInOutExchange();
+ me.setService(new QName("urn:test", "xslt-params"));
+ me.getInMessage().setContent(new StringSource("<sample id='777888' sent='" + new Date() + "'>hello world!</sample>"));
+ client.sendSync(me);
+ if (me.getStatus() == ExchangeStatus.ERROR) {
+ if (me.getError() != null) {
+ throw me.getError();
+ } else {
+ fail("Received ERROR status");
+ }
+ } else if (me.getFault() != null) {
+ fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
+ }
+ System.err.println(transformer.toString(me.getOutMessage().getContent()));
+ Element el = transformer.toDOMElement(me.getOutMessage());
+ assertEquals("cheeseyCheese", textValueOfXPath(el, "//param"));
+ assertEquals("4002", textValueOfXPath(el, "//integer"));
+ }
public void testXQuery() throws Exception {
DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
Added: incubator/servicemix/trunk/servicemix-saxon/src/test/resources/parameter-test.xsl
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/test/resources/parameter-test.xsl?view=auto&rev=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/test/resources/parameter-test.xsl (added)
+++ incubator/servicemix/trunk/servicemix-saxon/src/test/resources/parameter-test.xsl Sun Oct 15 13:30:14 2006
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-->
+<xsl:stylesheet
+ xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+ version='1.0'>
+
+ <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
+
+ <xsl:param name="stringParam"/>
+ <xsl:param name="integerParam"/>
+
+ <xsl:template match="*">
+ <rootNode>
+ <param><xsl:value-of select="$stringParam"/></param>
+ <integer><xsl:value-of select="$integerParam"/></integer>
+ </rootNode>
+ </xsl:template>
+
+</xsl:stylesheet>
Modified: incubator/servicemix/trunk/servicemix-saxon/src/test/resources/spring.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-saxon/src/test/resources/spring.xml?view=diff&rev=464271&r1=464270&r2=464271
==============================================================================
--- incubator/servicemix/trunk/servicemix-saxon/src/test/resources/spring.xml (original)
+++ incubator/servicemix/trunk/servicemix-saxon/src/test/resources/spring.xml Sun Oct 15 13:30:14 2006
@@ -30,10 +30,26 @@
<saxon:component>
<saxon:endpoints>
- <!-- START SNIPPET: xslt -->
+ <!-- START SNIPPET: xslt -->
<saxon:xslt service="test:xslt" endpoint="endpoint"
- resource="classpath:transform.xsl" />
+ resource="classpath:transform.xsl" />
<!-- END SNIPPET: xslt -->
+
+ <!-- START SNIPPET: xslt-params -->
+ <saxon:xslt service="test:xslt-params" endpoint="endpoint"
+ resource="classpath:parameter-test.xsl">
+ <property name="parameters">
+ <map>
+ <entry key="stringParam" value="cheeseyCheese"/>
+ <entry key="integerParam">
+ <bean class="java.lang.Integer">
+ <constructor-arg index="0" value="4002"/>
+ </bean>
+ </entry>
+ </map>
+ </property>
+ </saxon:xslt>
+ <!-- END SNIPPET: xslt-params -->
<!-- START SNIPPET: xslt-dynamic -->
<saxon:xslt service="test:xslt-dynamic" endpoint="endpoint">