You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by TimT <TT...@rdfgroup.com> on 2006/05/26 16:25:30 UTC

XsltComponent routing problem

Using Servicemix 2.0.2

I am having a problem configuring the XsltComponent to do routing. I am
getting a "Premature end of file." error.

My configuration connects a org.servicemix.components.http.HttpConnector to
org.servicemix.components.xslt.XsltComponent, which then uses xslt and
jbi:forward to route the message to a webservice endpoint using a
SaajBinding component. An XML message is then posted into the HttpConnector
and an XML response is expected back.

When the HttpConnector is connect directly to SaajBinding, the everything
goes well, but when using the router I get this error. 

I have traced through and it seems that the HttpConnector creates a
StreamSource from the http request InputStream, and this is set into the
NormalizedMessages content. The xalan transformer used by the XsltCompoent
reads this InputStream and then closes it. Subsquently the onward
NormalisedMessage content is a StreamSource based on a closed stream, so no
further processing is possible and the "Premature End of File" error is
thrown.

I have included my activations specs and XSLT, can anyone advise as to how
to fix/resolve this problem?

Regards,

Tim Tennant

<sm:activationSpec componentName="httpReceiver" 	
  						   service="my:httpBinding"
  						   endpoint="httpReceiver"
  						   destinationService="my:router">
  		  <sm:component>
  		  	<bean xmlns="http://xbean.org/schemas/spring/1.0"
class="org.servicemix.components.http.HttpConnector">
  		  		<property name="host" value="localhost" />
  		  		<property name="port" value="8912" />
  		  	</bean>
  		  </sm:component>
 </sm:activationSpec>
 
 <sm:activationSpec componentName="router" service="my:router">
  			<sm:component>
  				<bean class="org.servicemix.components.xslt.XsltComponent">
  					<property name="xsltResource"
value="classpath:my/esb/components/xslt/router.xsl" />
  					<!-- disable automatic output of the result of the transform; only if
we perform
  						an invoke in the XSLT will we invoke another endpoint -->
  					<property name="disableOutput" value="true" />
  				</bean>
  			</sm:component>
  </sm:activationSpec>
  
  <sm:activationSpec componentName="search" 	
  						   service="my:search"
  						   endpoint="search">
  		 <sm:component>
  		    <bean xmlns="http://xbean.org/schemas/spring/1.0"
  		          class="my.esb.components.saaj.SaajBinding">
			<property name="soapEndpoint">
				<bean class="javax.xml.messaging.URLEndpoint">
					<constructor-arg value="http://localhost:6789/my.asmx"/>
				</bean>
			</property>
			<property name="soapAction"
value="http://www.mywebservice.com/MySearch"/>
  		    </bean>
  		  </sm:component>
 </sm:activationSpec>

XSLT

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:jbi="xalan://org.servicemix.components.xslt.XalanExtension"
  extension-element-prefixes="jbi"
  xmlns:my="http://my/esb/"
  version="1.0">
		 <xsl:template match="/*">
		 	<jbi:forward service="my:search" />
		 </xsl:template>
</xsl:stylesheet>
--
View this message in context: http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4577150
Sent from the ServiceMix - User forum at Nabble.com.


Re: XsltComponent routing problem

Posted by Guillaume Nodet <gn...@gmail.com>.
Thanks, I have just fixed the problems (in servicemix-eip).

Cheers,
Guillaume Nodet

On 6/1/06, TimT <TT...@rdfgroup.com> wrote:
>
>
> Guillaume,
>
> I have attached the configuration below.
>
> The problem is cause becuase the underlying transformer used by eip that
> executes the xpath expression, reads the InputStream associated with the
> NormalizedMessage StreamSource content, and once read it closes that
> stream
> (this is normal input stream behaviour). This means that the next object
> that tries to read from that stream gets a reference to a closed
> InputStream, in this case it happens in the Saaj component when
> transforming
> to a soap message. You get the same problem if you use a SAXSource for
> anything because this is also based on an underlying InputStream.
> DOMSource
> is not base on InputStream does not, so it does not suffer from this
> problem.
>
> Regards,
>
> Tim
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://xbean.org/schemas/spring/1.0"
>         xmlns:spring="http://xbean.org/schemas/spring/1.0"
>         xmlns:sm="http://servicemix.apache.org/config/1.0"
>         xmlns:eip="http://servicemix.apache.org/eip/1.0"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="http://xbean.org/schemas/spring/1.0
> ../../conf/spring-beans.xsd http://servicemix.org/config/1.0
> ../../conf/servicemix.xsd"
>     xmlns:my="http://my.com/esb/">
>
>   <!-- the JBI container -->
>   <sm:container spring:id="jbi"
>                 useMBeanServer="false"
>                 createMBeanServer="false"
>                 dumpStats="true"
>                 statsInterval="10">
>
>         <sm:activationSpecs>
>                 <!-- ESB client activation specs -->
>
>                 <!-- Http based client recieve/send html request/response
> passes message
> to a router component-->
>                 <sm:activationSpec componentName="httpReceiver"
> service="my:httpBinding"
> endpoint="httpReceiver"
>                         destinationService="my:router">
>                         <sm:component>
>                                 <bean xmlns="
> http://xbean.org/schemas/spring/1.0"
> class="org.apache.servicemix.components.http.HttpConnector">
>                                         <property name="host"
> value="localhost" />
>                                         <property name="port" value="8912"
> />
>                                         <property name="marshaler">
>                                                 <bean class="
> com.my.esb.components.http.HttpMarshaler" />
>                                         </property>
>                                 </bean>
>                         </sm:component>
>                 </sm:activationSpec>
>                 <!-- End client activation specs -->
>
>                 <!-- Trace component - used for debugging -->
>                 <sm:activationSpec componentName="trace"
> service="my:trace">
>                         <sm:component>
>                                 <bean xmlns="
> http://xbean.org/schemas/spring/1.0"
> class="com.my.esb.components.util.TraceComponent"></bean>
>                         </sm:component>
>                 </sm:activationSpec>
>                 <!-- End trace component - used for debugging -->
>
>
>
>                 <!--  Enterprise Integration Patterns -->
>                 <sm:activationSpec>
>                   <sm:component>
>           <eip:component>
>                 <eip:endpoints>
>
>                         <!-- Router specs -->
>                         <eip:content-based-router service="my:router"
> endpoint="endpoint">
>                                 <eip:rules>
>                                         <eip:routing-rule>
>                                                 <eip:predicate>
>                                                         <eip:xpath-predicate
> xpath="count(/externalws:productSearch)
> = 1" namespaceContext="#nsexternalws" />
>                                                 </eip:predicate>
>                                                 <eip:target>
>                                                         <eip:exchange-target
> service="my:search" />
>                                                 </eip:target>
>                                         </eip:routing-rule>
>                                         <eip:routing-rule>
>                                                 <!--
>                                                         there is no
> predicate, so this is the default destination
>                                                 -->
>                                                 <eip:target>
>                                                         <eip:exchange-target
> service="my:trace" />
>                                                 </eip:target>
>                                         </eip:routing-rule>
>                                 </eip:rules>
>                         </eip:content-based-router>
>                         <!-- End router specs -->
>
>                 </eip:endpoints>
>           </eip:component>
>                   </sm:component>
>       </sm:activationSpec>
>                 <!--  End EIPs -->
>
>                 <!-- externalws webservice -->
>                 <sm:activationSpec componentName="search"
>                                                    service="my:search"
>                                                    endpoint="search">
>                  <sm:component>
>                     <bean xmlns="http://xbean.org/schemas/spring/1.0"
>                           class="
> org.apache.servicemix.components.saaj.SaajBinding">
>                         <property name="soapEndpoint"
> ref="externalwsUrl"/>
>                         <property name="soapAction"
> value="http://www.externalwswebservices.com/productSearch"/>
>                         <property name="marshaller" ref="saajMarshaller"/>
>                     </bean>
>                   </sm:component>
>                 </sm:activationSpec>
>
>                 <!-- End externalws webservice -->
>
>
>         </sm:activationSpecs>
>   </sm:container>
>
>         <!-- Bean definitions -->
>         <eip:namespace-context id="nsexternalws">
>                 <eip:namespaces>
>                         <eip:namespace
> prefix="externalws">http://www.externalwswebservices.com/</eip:namespace>
>                 </eip:namespaces>
>         </eip:namespace-context>
>
>         <bean id="externalwsUrl" class="javax.xml.messaging.URLEndpoint">
>                 <constructor-arg value="http://localhost:6789/search.asmx"
> />
>         </bean>
>
>         <bean id="saajMarshaller"
> class="com.my.esb.components.saaj.SaajMarshaller">
>                 <property name="excludedHeaderTypes">
>                         <list>
>                                 <value>cgi.headers</value>
>                                 <value>Host</value>
>                                 <value>User-Agent</value>
>                                 <value>Accept</value>
>                                 <value>Content-Type</value>
>                         </list>
>                 </property>
>         </bean>
>
> </beans>
>
> --
> View this message in context:
> http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4658167
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: XsltComponent routing problem

Posted by TimT <TT...@rdfgroup.com>.
Guillaume,

I have attached the configuration below. 

The problem is cause becuase the underlying transformer used by eip that
executes the xpath expression, reads the InputStream associated with the
NormalizedMessage StreamSource content, and once read it closes that stream
(this is normal input stream behaviour). This means that the next object
that tries to read from that stream gets a reference to a closed
InputStream, in this case it happens in the Saaj component when transforming
to a soap message. You get the same problem if you use a SAXSource for
anything because this is also based on an underlying InputStream. DOMSource
is not base on InputStream does not, so it does not suffer from this
problem.

Regards, 

Tim

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xbean.org/schemas/spring/1.0"
	xmlns:spring="http://xbean.org/schemas/spring/1.0"
	xmlns:sm="http://servicemix.apache.org/config/1.0"
	xmlns:eip="http://servicemix.apache.org/eip/1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://xbean.org/schemas/spring/1.0
../../conf/spring-beans.xsd http://servicemix.org/config/1.0
../../conf/servicemix.xsd"
    xmlns:my="http://my.com/esb/">
    
  <!-- the JBI container -->
  <sm:container spring:id="jbi"
  		useMBeanServer="false"
  		createMBeanServer="false"
  		dumpStats="true"
  		statsInterval="10">
  		
  	<sm:activationSpecs>
  		<!-- ESB client activation specs -->
  	
		<!-- Http based client recieve/send html request/response passes message
to a router component-->
		<sm:activationSpec componentName="httpReceiver" service="my:httpBinding"
endpoint="httpReceiver"
			destinationService="my:router">
			<sm:component>
				<bean xmlns="http://xbean.org/schemas/spring/1.0"
class="org.apache.servicemix.components.http.HttpConnector">
					<property name="host" value="localhost" />
					<property name="port" value="8912" />
					<property name="marshaler">
						<bean class="com.my.esb.components.http.HttpMarshaler" />
					</property>
				</bean>
			</sm:component>
		</sm:activationSpec>
  		<!-- End client activation specs -->

		<!-- Trace component - used for debugging -->
  		<sm:activationSpec componentName="trace" service="my:trace">
  			<sm:component>
  				<bean xmlns="http://xbean.org/schemas/spring/1.0"
class="com.my.esb.components.util.TraceComponent"></bean>
  			</sm:component>
  		</sm:activationSpec>
  		<!-- End trace component - used for debugging -->
  		
  		
  		
  		<!--  Enterprise Integration Patterns -->
  		<sm:activationSpec>
  		  <sm:component>
          <eip:component>
          	<eip:endpoints>

          		<!-- Router specs -->
          		<eip:content-based-router service="my:router"
endpoint="endpoint">
          			<eip:rules>
          				<eip:routing-rule>
          					<eip:predicate>
          						<eip:xpath-predicate xpath="count(/externalws:productSearch)
= 1" namespaceContext="#nsexternalws" />
          					</eip:predicate>
          					<eip:target>
          						<eip:exchange-target service="my:search" />
          					</eip:target>
          				</eip:routing-rule>
          				<eip:routing-rule>
          					<!--
          						there is no predicate, so this is the default destination 	
          					-->
          					<eip:target>
          						<eip:exchange-target service="my:trace" />
          					</eip:target>
          				</eip:routing-rule>
          			</eip:rules>
          		</eip:content-based-router>
          		<!-- End router specs -->

          	</eip:endpoints>
          </eip:component>
  		  </sm:component>
      </sm:activationSpec>
  		<!--  End EIPs -->

  		<!-- externalws webservice -->
  		<sm:activationSpec componentName="search" 	
  						   service="my:search"
  						   endpoint="search">
  		 <sm:component>
  		    <bean xmlns="http://xbean.org/schemas/spring/1.0"
  		          class="org.apache.servicemix.components.saaj.SaajBinding">
			<property name="soapEndpoint" ref="externalwsUrl"/>
			<property name="soapAction"
value="http://www.externalwswebservices.com/productSearch"/>
			<property name="marshaller" ref="saajMarshaller"/>
  		    </bean>
  		  </sm:component>
  		</sm:activationSpec>
  		  		
  		<!-- End externalws webservice -->
  		

  	</sm:activationSpecs>
  </sm:container>

	<!-- Bean definitions -->
	<eip:namespace-context id="nsexternalws">
		<eip:namespaces>
			<eip:namespace
prefix="externalws">http://www.externalwswebservices.com/</eip:namespace>
		</eip:namespaces>
	</eip:namespace-context>

	<bean id="externalwsUrl" class="javax.xml.messaging.URLEndpoint">
		<constructor-arg value="http://localhost:6789/search.asmx" />
	</bean>

	<bean id="saajMarshaller"
class="com.my.esb.components.saaj.SaajMarshaller">
		<property name="excludedHeaderTypes">
			<list>
				<value>cgi.headers</value>
				<value>Host</value>
				<value>User-Agent</value>
				<value>Accept</value>
				<value>Content-Type</value>
			</list>
		</property>
	</bean>

</beans>

--
View this message in context: http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4658167
Sent from the ServiceMix - User forum at Nabble.com.


Re: XsltComponent routing problem

Posted by Guillaume Nodet <gn...@gmail.com>.
Could you send the 3.0 configuration file using the servicemix-eip component
that cause a problem with stream.  The servicemix-eip should be able to
gracefully
handle all streams, but this is not the case for all components.

Cheers,
Guillaume Nodet

On 5/31/06, TimT <TT...@rdfgroup.com> wrote:
>
>
> Guillaume,
>
> Thanks for the help, I now have routing working, deployed in Jboss using
> the
> EIP content-based-router.
>
> I did however initially run into the same problem as with servicemix 2,
> that
> is that the transformer that does the routing closed the input stream
> based
> StreamSource that is set as the NormalizedMessage content resulting in a
> "premature end of file". I fixed this by creating my own implementation of
> the HttpMarshaler, which I injected into the HttpConnector. In this
> implementation I have overwritten the toNMS(...) method so that it creates
> a
> DOMSource rather than a StreamSource.
>
> Is there some benefit to using StreamSource over DOMSource in the
> HttpMarshaler? It would be useful to make the choice between which sort of
> Source to use configurable.
>
> Regards,
>
> Tim Tennant
> --
> View this message in context:
> http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4644567
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: XsltComponent routing problem

Posted by TimT <TT...@rdfgroup.com>.
Guillaume,

Thanks for the help, I now have routing working, deployed in Jboss using the
EIP content-based-router.

I did however initially run into the same problem as with servicemix 2, that
is that the transformer that does the routing closed the input stream based
StreamSource that is set as the NormalizedMessage content resulting in a
"premature end of file". I fixed this by creating my own implementation of
the HttpMarshaler, which I injected into the HttpConnector. In this
implementation I have overwritten the toNMS(...) method so that it creates a
DOMSource rather than a StreamSource. 

Is there some benefit to using StreamSource over DOMSource in the
HttpMarshaler? It would be useful to make the choice between which sort of
Source to use configurable.

Regards,

Tim Tennant
--
View this message in context: http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4644567
Sent from the ServiceMix - User forum at Nabble.com.


Re: XsltComponent routing problem

Posted by Guillaume Nodet <gn...@gmail.com>.
The jboss deployer for ServiceMix 3.0 is available at
http://svn.codehaus.org/servicemix/trunk/.
It has been enhanced to allow deployment of JBI components and service
assemblies.
The other way is to deploy ServiceMix as a web application.

Cheers,
Guillaume Nodet

On 5/30/06, TimT <TT...@rdfgroup.com> wrote:
>
>
> Thanks for the reply, I guess this means I have to use version 3.0 of
> servicemix.
>
> I'm deploying servicemix to JBoss and was using the jboss-deployer, but
> this
> tooling project is not included in the source download for 3.0, is this
> code
> available somewhere for 3.0 or is there another prefered approach for
> deploying the JBIContainer into Jboss for servicemix 3.0?
>
> Regards,
>
> TimT
> --
> View this message in context:
> http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4624065
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: XsltComponent routing problem

Posted by TimT <TT...@rdfgroup.com>.
Thanks for the reply, I guess this means I have to use version 3.0 of
servicemix.

I'm deploying servicemix to JBoss and was using the jboss-deployer, but this
tooling project is not included in the source download for 3.0, is this code
available somewhere for 3.0 or is there another prefered approach for
deploying the JBIContainer into Jboss for servicemix 3.0?

Regards,

TimT
--
View this message in context: http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4624065
Sent from the ServiceMix - User forum at Nabble.com.


Re: XsltComponent routing problem

Posted by Guillaume Nodet <gn...@gmail.com>.
Currently, the XSLT component does not handle InOut MEPs when routing
exchanges.
You should use the ContentBasedRouter EIP pattern (
http://servicemix.goopen.org/site/servicemix-eip.html)
and use the XSLT for transformation only.

Cheers,
Guillaume Nodet

On 5/26/06, TimT <TT...@rdfgroup.com> wrote:
>
>
> Using Servicemix 2.0.2
>
> I am having a problem configuring the XsltComponent to do routing. I am
> getting a "Premature end of file." error.
>
> My configuration connects a org.servicemix.components.http.HttpConnectorto
> org.servicemix.components.xslt.XsltComponent, which then uses xslt and
> jbi:forward to route the message to a webservice endpoint using a
> SaajBinding component. An XML message is then posted into the
> HttpConnector
> and an XML response is expected back.
>
> When the HttpConnector is connect directly to SaajBinding, the everything
> goes well, but when using the router I get this error.
>
> I have traced through and it seems that the HttpConnector creates a
> StreamSource from the http request InputStream, and this is set into the
> NormalizedMessages content. The xalan transformer used by the XsltCompoent
> reads this InputStream and then closes it. Subsquently the onward
> NormalisedMessage content is a StreamSource based on a closed stream, so
> no
> further processing is possible and the "Premature End of File" error is
> thrown.
>
> I have included my activations specs and XSLT, can anyone advise as to how
> to fix/resolve this problem?
>
> Regards,
>
> Tim Tennant
>
> <sm:activationSpec componentName="httpReceiver"
>
> service="my:httpBinding"
>                                                    endpoint="httpReceiver"
>
> destinationService="my:router">
>                   <sm:component>
>                         <bean xmlns="http://xbean.org/schemas/spring/1.0"
> class="org.servicemix.components.http.HttpConnector">
>                                 <property name="host" value="localhost" />
>                                 <property name="port" value="8912" />
>                         </bean>
>                   </sm:component>
> </sm:activationSpec>
>
> <sm:activationSpec componentName="router" service="my:router">
>                         <sm:component>
>                                 <bean class="
> org.servicemix.components.xslt.XsltComponent">
>                                         <property name="xsltResource"
> value="classpath:my/esb/components/xslt/router.xsl" />
>                                         <!-- disable automatic output of
> the result of the transform; only if
> we perform
>                                                 an invoke in the XSLT will
> we invoke another endpoint -->
>                                         <property name="disableOutput"
> value="true" />
>                                 </bean>
>                         </sm:component>
>   </sm:activationSpec>
>
>   <sm:activationSpec componentName="search"
>                                                    service="my:search"
>                                                    endpoint="search">
>                  <sm:component>
>                     <bean xmlns="http://xbean.org/schemas/spring/1.0"
>                           class="my.esb.components.saaj.SaajBinding">
>                         <property name="soapEndpoint">
>                                 <bean class="
> javax.xml.messaging.URLEndpoint">
>                                         <constructor-arg value="
> http://localhost:6789/my.asmx"/>
>                                 </bean>
>                         </property>
>                         <property name="soapAction"
> value="http://www.mywebservice.com/MySearch"/>
>                     </bean>
>                   </sm:component>
> </sm:activationSpec>
>
> XSLT
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   xmlns:jbi="xalan://org.servicemix.components.xslt.XalanExtension"
>   extension-element-prefixes="jbi"
>   xmlns:my="http://my/esb/"
>   version="1.0">
>                  <xsl:template match="/*">
>                         <jbi:forward service="my:search" />
>                  </xsl:template>
> </xsl:stylesheet>
> --
> View this message in context:
> http://www.nabble.com/XsltComponent+routing+problem-t1687094.html#a4577150
> Sent from the ServiceMix - User forum at Nabble.com.
>
>