You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Juergen Mayrbaeurl <ju...@hvb.sozvers.at> on 2006/04/26 17:06:04 UTC

NamespaceContext in XPath based content router

I'm trying to use the ContentBasedRouter from the ServiceMix EIP component. 

<eip:content-based-router 
	service="test:egovrouter" endpoint="endpoint">
  <eip:rules>
    <eip:routing-rule>
      <eip:predicate>
        <eip:xpath-predicate 
        	xpath="count(/BPKAbfrage) = 1" />
      </eip:predicate>
      <eip:target>
        <eip:exchange-target service="test:szrVerarbeitung" />
      </eip:target>
    </eip:routing-rule>
    <eip:routing-rule>
      <eip:predicate>
        <eip:xpath-predicate 
        	xpath="count(/Personenabfrage) = 1" />
      </eip:predicate>
      <eip:target>
        <eip:exchange-target service="test:zmrVerarbeitung" />
      </eip:target>
    </eip:routing-rule>
  </eip:rules>
</eip:content-based-router>

The input message looks like:

<?xml version="1.0" encoding="UTF-8"?>
<zmr:BPKAbfrage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xmlns:zmr="http://www.sozialversicherung.at/schema/egov/zmr/1_0">

  <zmr:Abfrageparameter>
    <zmr:Bearbeitung>
    	<zmr:Benutzer>
    		<zmr:Bearbeiter>99mustermann</zmr:Bearbeiter>
    		<zmr:Name>Mustermann Max</zmr:Name>
    		<zmr:GlobaleIdentifizierung>99mustermann</zmr:GlobaleIdentifizierung>
    	</zmr:Benutzer>
    	<zmr:Bearbeitungsgrund>ZPV Test</zmr:Bearbeitungsgrund>
    	<zmr:System>STP ZPV</zmr:System>
    </zmr:Bearbeitung>
    <zmr:PersonenSuchkriterien>
      <zmr:Familienname>Mayrbäurl</zmr:Familienname>
      <zmr:Vorname>Jürgen</zmr:Vorname>
      <zmr:Geburtsdatum>1966-01-05</zmr:Geburtsdatum>
    </zmr:PersonenSuchkriterien>
  </zmr:Abfrageparameter>
</zmr:BPKAbfrage>

The ContentBasedRouter tells me that it can't find a matching rule for the
exchange. Maybe the reason for this is the missing namespace in the xpath
expression. 

Any idea? And how can I specify the namespace in the xpath expression?

Greetings
Juergen

BTW: The message content will cause exceptions in the traceMessages() method
of the DeliveryChannelImpl, when tracing is on.
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4103093
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
I'll check it with a simple test. 

Cheers,
Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4111258
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
Take a look at http://servicemix.org/Using+Eclipse

Cheers,
Guillaume Nodet

On 4/28/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> Issue in JIRA has been raised. Includes testcase showing the problem and
> changed SourceTransformer class source file.
>
> Kind regards
> Juergen
>
> BTW: I'm still working on getting ServiceMix's source usable with Eclipse
> 3.x. SVN is set up, but not all Eclipse projects are yet configured. Any
> hints?
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4131309
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
Issue in JIRA has been raised. Includes testcase showing the problem and
changed SourceTransformer class source file.

Kind regards
Juergen

BTW: I'm still working on getting ServiceMix's source usable with Eclipse
3.x. SVN is set up, but not all Eclipse projects are yet configured. Any
hints?
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4131309
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
I have fixed this page, thx for reporting..

Guillaume

On 4/27/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> No. I have used the linked from http://www.servicemix.org/Contributing, which
> seems to be the wrong one, because it's referencing
> http://jira.activemq.org/jira/.
>
> Thanks
> Juergen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4122641
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
No. I have used the linked from http://www.servicemix.org/Contributing, which
seems to be the wrong one, because it's referencing
http://jira.activemq.org/jira/.

Thanks
Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4122641
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
Are you using http://issues.apache.org/activemq ?
The JIRA instance has been moved to Apache some time ago...

Guillaume

On 4/27/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> I'm having problems with JIRA. In the first step of "Create new issue" -
> selecting the project - there's no entry for ServiceMix. Only "ActiveMQ",
> "ActiveSOAP", "ActiveSpace", "Jencks" and "STOMP" can be selected.
>
> Juergen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4122474
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
I'm having problems with JIRA. In the first step of "Create new issue" -
selecting the project - there's no entry for ServiceMix. Only "ActiveMQ",
"ActiveSOAP", "ActiveSpace", "Jencks" and "STOMP" can be selected.

Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4122474
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
Yes please, and attach your patch (it helps to track things).
Btw, do you have a simple test case that would demonstrate the problem
/ solution ?

Cheers,
Guillaume Nodet

On 4/27/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> I think I've a solution for the second problem.
>
> In SourceTransformer.toDOMSourceFromStream():
>
>     public DOMSource toDOMSourceFromStream(StreamSource source) throws
> ParserConfigurationException, IOException,
>             SAXException {
>         DocumentBuilder builder = createDocumentBuilder();
>         String systemId = source.getSystemId();
>         Document document = null;
>         InputStream inputStream = source.getInputStream();
>         if (inputStream != null) {
>             document = builder.parse(inputStream, systemId);
>         }
>         else {
>             Reader reader = source.getReader();
>             if (reader != null) {
>                 document = builder.parse(new InputSource(reader));
>             }
>             else {
>                 throw new IOException("No input stream or reader
> available");
>             }
>         }
>         return new DOMSource(document, systemId);
>     }
>
> Change to:
>
>     public DOMSource toDOMSourceFromStream(StreamSource source) throws
> ParserConfigurationException, IOException,
>             SAXException {
>         DocumentBuilder builder = createDocumentBuilder();
>         String systemId = source.getSystemId();
>         Document document = null;
>         InputStream inputStream = source.getInputStream();
>         if (inputStream != null) {
>             InputSource inputsource = new InputSource(inputStream);
>             inputsource.setSystemId(systemId);
>             inputsource.setEncoding(Charset.defaultCharset().name());
>
>             document = builder.parse(inputsource);
>         }
>         else {
>             Reader reader = source.getReader();
>             if (reader != null) {
>                 document = builder.parse(new InputSource(reader));
>             }
>             else {
>                 throw new IOException("No input stream or reader
> available");
>             }
>         }
>         return new DOMSource(document, systemId);
>     }
>
> The block starting with "if (inputStream != null) {" was changed. It no
> longers calls the DocumentBuilder.parse() method with the inputstream but
> with an input source that has its encoding explicitly set to the default
> character set encoding.
>
> The code above only works with J2SE 5, because it's using the
> Charset.defaultCharset() method, which was introduced with J2SE 5. To make
> it usable with older J2SE versions, you should add a static member to the
> class SourceTransformer, which holds the name of the default character set
> encoding and is initialized at class loading. (from
> http://www.rgagnon.com/javadetails/java-0505.html):
>
> public class Hello {
>  public static void main(String args[]) throws Exception{
>   // not crossplateform safe
>   System.out.println(System.getProperty("file.encoding"));
>   // jdk1.4
>   System.out.println(
>      new java.io.OutputStreamWriter(
>         new java.io.ByteArrayOutputStream()).getEncoding()
>      );
>   // jdk1.5
>   System.out.println(java.nio.charset.Charset.defaultCharset().name());
>   }
> }
>
> This kind of calling a DocumentBuilder should be used overall in ServiceMix.
>
> BTW: What about the JIRA? Should I raise one?
>
> Kind regards
> Juergen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4121021
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
I think I've a solution for the second problem.

In SourceTransformer.toDOMSourceFromStream():

    public DOMSource toDOMSourceFromStream(StreamSource source) throws
ParserConfigurationException, IOException,
            SAXException {
        DocumentBuilder builder = createDocumentBuilder();
        String systemId = source.getSystemId();
        Document document = null;
        InputStream inputStream = source.getInputStream();
        if (inputStream != null) {
            document = builder.parse(inputStream, systemId);
        }
        else {
            Reader reader = source.getReader();
            if (reader != null) {
                document = builder.parse(new InputSource(reader));
            }
            else {
                throw new IOException("No input stream or reader
available");
            }
        }
        return new DOMSource(document, systemId);
    }

Change to:

    public DOMSource toDOMSourceFromStream(StreamSource source) throws
ParserConfigurationException, IOException,
            SAXException {
        DocumentBuilder builder = createDocumentBuilder();
        String systemId = source.getSystemId();
        Document document = null;
        InputStream inputStream = source.getInputStream();
        if (inputStream != null) {
            InputSource inputsource = new InputSource(inputStream);
            inputsource.setSystemId(systemId);
            inputsource.setEncoding(Charset.defaultCharset().name());
            
            document = builder.parse(inputsource);
        }
        else {
            Reader reader = source.getReader();
            if (reader != null) {
                document = builder.parse(new InputSource(reader));
            }
            else {
                throw new IOException("No input stream or reader
available");
            }
        }
        return new DOMSource(document, systemId);
    }

The block starting with "if (inputStream != null) {" was changed. It no
longers calls the DocumentBuilder.parse() method with the inputstream but
with an input source that has its encoding explicitly set to the default
character set encoding. 

The code above only works with J2SE 5, because it's using the
Charset.defaultCharset() method, which was introduced with J2SE 5. To make
it usable with older J2SE versions, you should add a static member to the
class SourceTransformer, which holds the name of the default character set
encoding and is initialized at class loading. (from
http://www.rgagnon.com/javadetails/java-0505.html):

public class Hello {
 public static void main(String args[]) throws Exception{
  // not crossplateform safe
  System.out.println(System.getProperty("file.encoding"));
  // jdk1.4
  System.out.println(
     new java.io.OutputStreamWriter(
        new java.io.ByteArrayOutputStream()).getEncoding()
     );
  // jdk1.5
  System.out.println(java.nio.charset.Charset.defaultCharset().name());
  }
}

This kind of calling a DocumentBuilder should be used overall in ServiceMix. 

BTW: What about the JIRA? Should I raise one?

Kind regards
Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4121021
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
I have fixed the JAXPXpathExpression so that the expression is not
compiled anymore in the constructor (but when the expression is first
evaluated, or when afterPropertiesSet is explicitely called).  Thanks
for diving in this issue.

For the other problems (non US charachters), could you please raise a
JIRA ? We need to find a way to deal with that ...

Cheers,
Guillaume Nodet

On 4/27/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> Testing is done. I've found the bug and a workaround.
>
> The XPath expression gets compiled in
> JAXPXPathExpression.afterPropertiesSet() as long as
> JAXPXPathExpression.xPathExpression is NULL. Since
> JAXPXPathExpression.afterPropertiesSet() gets called from the constructor
> JAXPXPathExpression(String xpath) any further calls to
> JAXPXPathExpression.set... don't change the compiled XPath expression. This
> is the case, if you call JAXPXPathExpression.setNamespaceContext() and Xalan
> won't know about the namespaces, when it evaluates the XPath expression.
> The workaround is: Don't use the constructor JAXPXPathExpression(String
> xpath). Use the default constructor and call the setter methods. Afterwards
> make sure, that JAXPXPathExpression.afterPropertiesSet() gets called (by
> Spring or by calling it directly). If you want to change any attribute, that
> is used in the XPath expression evaluation, of an instance of
> JAXPXPathExpression after construction, set the attribute
> JAXPXPathExpression.xPathExpression to NULL, set other attributes and
> finally call JAXPXPathExpression.afterPropertiesSet().
>
> With these changes the ContentBasedRouter works correctly, as long as you
> are not using non US-ASCII characters like 'ü' or 'ä'. That's the second
> problem and I'm afraid this is a major problem when you're using ServiceMix
> on non-english systems.
> The problems comes from the class
> org.apache.servicemix.jbi.jaxp.StringSource and its method
> StringSource.getInputStream() that's used very often in ServiceMix (e.g.
> JAXPXPathExpression):
>
>     public InputStream getInputStream() {
>         return new ByteArrayInputStream(text.getBytes());
>     }
>
> According to the JDK documentation, the method String.getBytes() uses the
> default character set of the system to transform/encode the characters of a
> string to a byte array. On my system the default character set is "cp1252".
> Every caller of StringSource.getInputStream(), that has to decode the bytes
> from the input stream back to a string, has to use the default character
> set. I'm quite sure, that there is a lot of code in ServiceMix (see
> SourceTransformer), that doesn't set the character encoding. Unfortunately
> I've no workaround for this problem. Avoid to use
> StringSource.getInputStream(). Use JDK's reader implementations.
>
> Kind regards
> Jürgen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4119455
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
Testing is done. I've found the bug and a workaround.

The XPath expression gets compiled in
JAXPXPathExpression.afterPropertiesSet() as long as
JAXPXPathExpression.xPathExpression is NULL. Since
JAXPXPathExpression.afterPropertiesSet() gets called from the constructor
JAXPXPathExpression(String xpath) any further calls to 
JAXPXPathExpression.set... don't change the compiled XPath expression. This
is the case, if you call JAXPXPathExpression.setNamespaceContext() and Xalan
won't know about the namespaces, when it evaluates the XPath expression. 
The workaround is: Don't use the constructor JAXPXPathExpression(String
xpath). Use the default constructor and call the setter methods. Afterwards
make sure, that JAXPXPathExpression.afterPropertiesSet() gets called (by
Spring or by calling it directly). If you want to change any attribute, that
is used in the XPath expression evaluation, of an instance of
JAXPXPathExpression after construction, set the attribute
JAXPXPathExpression.xPathExpression to NULL, set other attributes and
finally call JAXPXPathExpression.afterPropertiesSet().

With these changes the ContentBasedRouter works correctly, as long as you
are not using non US-ASCII characters like 'ü' or 'ä'. That's the second
problem and I'm afraid this is a major problem when you're using ServiceMix
on non-english systems.
The problems comes from the class
org.apache.servicemix.jbi.jaxp.StringSource and its method
StringSource.getInputStream() that's used very often in ServiceMix (e.g.
JAXPXPathExpression):

    public InputStream getInputStream() {
        return new ByteArrayInputStream(text.getBytes());
    }

According to the JDK documentation, the method String.getBytes() uses the
default character set of the system to transform/encode the characters of a
string to a byte array. On my system the default character set is "cp1252".
Every caller of StringSource.getInputStream(), that has to decode the bytes
from the input stream back to a string, has to use the default character
set. I'm quite sure, that there is a lot of code in ServiceMix (see
SourceTransformer), that doesn't set the character encoding. Unfortunately
I've no workaround for this problem. Avoid to use
StringSource.getInputStream(). Use JDK's reader implementations. 

Kind regards
Jürgen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4119455
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
The namespace context is set on the XPath object, not the
XPathExpression, and it has been reported to work...
I have no real idea though.
I'd recommend to mimic the xpath expression in a simple test and check
it against your xml ...

Cheers,
Guillaume Nodet

On 4/26/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> Some results from debugging:
>
> The implementation class XPathExpressionImpl of the interface
> JAXPXPathExpression.xPathExpression, which is doing the xpath expression
> evaluation, has a member with the name 'prefixResolver' (and none for the
> namespace context) which is null. This seems to be the problem.
>
> Juergen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4105142
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
Some results from debugging:

The implementation class XPathExpressionImpl of the interface
JAXPXPathExpression.xPathExpression, which is doing the xpath expression
evaluation, has a member with the name 'prefixResolver' (and none for the
namespace context) which is null. This seems to be the problem.

Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4105142
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
javanet.staxutils.SimpleNamespaceContext works. Spring can load the context.

But the next problems: Using the characters 'ü' in Jürgen and 'ä' in
Mayrbäurl in the IN message causes exception in
JAXPXPathExpression.evaluate() when getXMLNode() is called. We're using
german systems.

For testing purpose I've removed the 'ü's and 'ä's from the IN message. But
still the same exception from ContentBasedRouter (no difference between
specifying the namespace or not):

javax.jbi.messaging.MessagingException: No matching rule found for exchange
	at
org.apache.servicemix.eip.patterns.ContentBasedRouter.getDestination(ContentBasedRouter.java:161)
	at
org.apache.servicemix.eip.patterns.ContentBasedRouter.process(ContentBasedRouter.java:92)
	at
org.apache.servicemix.common.BaseLifeCycle.processExchange(BaseLifeCycle.java:375)
	at org.apache.servicemix.common.BaseLifeCycle$2.run(BaseLifeCycle.java:241)
	at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:650)
	at
edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:675)
	at java.lang.Thread.run(Thread.java:534)

I debugged the calling sequence, but couldn't find the cause of the problem.

Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4104924
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
Try with javanet.staxutils.SimpleNamespaceContext instead then ...

Guillaume

On 4/26/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> Thanks for the hint. But it doesn't work, because
> org.jaxen.SimpleNamespaceContext doesn't implement the
> javax.xml.namespace.NamespaceContext interface.
>
> Spring complains with:
>
> org.springframework.beans.factory.BeanCreationException: Error creating bean
> with name 'org.apache.servicemix.eip.support.XPathPredicate' defined in
> class path resource [egovportal-servicemix.xml]: Error setting property
> values; nested exception is
> org.springframework.beans.PropertyAccessExceptionsException:
> PropertyAccessExceptionsException (1 errors); nested
> propertyAccessExceptions are:
> [org.springframework.beans.TypeMismatchException: Failed to convert property
> value of type [org.jaxen.SimpleNamespaceContext] to required type
> [javax.xml.namespace.NamespaceContext] for property 'namespaceContext']
> PropertyAccessExceptionsException (1 errors)
> org.springframework.beans.TypeMismatchException: Failed to convert property
> value of type [org.jaxen.SimpleNamespaceContext] to required type
> [javax.xml.namespace.NamespaceContext] for property 'namespaceContext'
>         at
> org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:839)
>         at
> org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
>         at
> org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:469)
>         at
> org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:626)
>         at
> org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:653)
>         at
> org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:642)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1023)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:706)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:706)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
>         at
> org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
>         at
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
>         at
> org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
>         at
> org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)
>         at
> org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
>         at
> org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
>         at
> org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:48)
>         at EGovPortalTest.createBeanFactory(EGovPortalTest.java:19)
>         at
> org.apache.servicemix.tck.SpringTestSupport.setUp(SpringTestSupport.java:57)
>         at org.apache.servicemix.tck.TestSupport.setUp(TestSupport.java:45)
>         at junit.framework.TestCase.runBare(TestCase.java:125)
>         at junit.framework.TestResult$1.protect(TestResult.java:106)
>         at junit.framework.TestResult.runProtected(TestResult.java:124)
>         at junit.framework.TestResult.run(TestResult.java:109)
>         at junit.framework.TestCase.run(TestCase.java:118)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
>         at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
>
> It looks like I'm needing a simple class that implements the interface
> javax.xml.namespace.NamespaceContext interface. Do I've to code it myself?
>
> Juergen
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4104346
> Sent from the ServiceMix - User forum at Nabble.com.
>
>

Re: NamespaceContext in XPath based content router

Posted by Juergen Mayrbaeurl <ju...@hvb.sozvers.at>.
Thanks for the hint. But it doesn't work, because
org.jaxen.SimpleNamespaceContext doesn't implement the
javax.xml.namespace.NamespaceContext interface.

Spring complains with:

org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'org.apache.servicemix.eip.support.XPathPredicate' defined in
class path resource [egovportal-servicemix.xml]: Error setting property
values; nested exception is
org.springframework.beans.PropertyAccessExceptionsException:
PropertyAccessExceptionsException (1 errors); nested
propertyAccessExceptions are:
[org.springframework.beans.TypeMismatchException: Failed to convert property
value of type [org.jaxen.SimpleNamespaceContext] to required type
[javax.xml.namespace.NamespaceContext] for property 'namespaceContext']
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property
value of type [org.jaxen.SimpleNamespaceContext] to required type
[javax.xml.namespace.NamespaceContext] for property 'namespaceContext'
	at
org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:839)
	at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:584)
	at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:469)
	at
org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:626)
	at
org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:653)
	at
org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:642)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1023)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:706)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveConstructorArguments(AbstractAutowireCapableBeanFactory.java:706)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:611)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:329)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:147)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:96)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:193)
	at
org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:109)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1013)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:824)
	at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
	at
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
	at
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)
	at
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:320)
	at
org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:158)
	at
org.apache.xbean.spring.context.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:48)
	at EGovPortalTest.createBeanFactory(EGovPortalTest.java:19)
	at
org.apache.servicemix.tck.SpringTestSupport.setUp(SpringTestSupport.java:57)
	at org.apache.servicemix.tck.TestSupport.setUp(TestSupport.java:45)
	at junit.framework.TestCase.runBare(TestCase.java:125)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)

It looks like I'm needing a simple class that implements the interface
javax.xml.namespace.NamespaceContext interface. Do I've to code it myself? 

Juergen
--
View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4104346
Sent from the ServiceMix - User forum at Nabble.com.


Re: NamespaceContext in XPath based content router

Posted by Guillaume Nodet <gn...@gmail.com>.
Try something like:

<eip:xpath-predicate xpath="count(/zmr:BPKAbfrage) = 1">
   <eip:namespaceContext>
<bean class="org.jaxen.SimpleNamespaceContext">
     <constructor-arg>
       <map>
         <entry>
           <key><value>zmr</value></key>
           <value>http://www.sozialversicherung.at/schema/egov/zmr/1_0</value>
         </entry>
       </map>
     </constructor-arg>
</bean>
   </eip:namespaceContext>
</eip:predicate>

Cheers,
Guillaume Nodet

On 4/26/06, Juergen Mayrbaeurl <ju...@hvb.sozvers.at> wrote:
>
> I'm trying to use the ContentBasedRouter from the ServiceMix EIP component.
>
> <eip:content-based-router
>         service="test:egovrouter" endpoint="endpoint">
>   <eip:rules>
>     <eip:routing-rule>
>       <eip:predicate>
>         <eip:xpath-predicate
>                 xpath="count(/BPKAbfrage) = 1" />
>       </eip:predicate>
>       <eip:target>
>         <eip:exchange-target service="test:szrVerarbeitung" />
>       </eip:target>
>     </eip:routing-rule>
>     <eip:routing-rule>
>       <eip:predicate>
>         <eip:xpath-predicate
>                 xpath="count(/Personenabfrage) = 1" />
>       </eip:predicate>
>       <eip:target>
>         <eip:exchange-target service="test:zmrVerarbeitung" />
>       </eip:target>
>     </eip:routing-rule>
>   </eip:rules>
> </eip:content-based-router>
>
> The input message looks like:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <zmr:BPKAbfrage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xmlns:zmr="http://www.sozialversicherung.at/schema/egov/zmr/1_0">
>
>   <zmr:Abfrageparameter>
>     <zmr:Bearbeitung>
>         <zmr:Benutzer>
>                 <zmr:Bearbeiter>99mustermann</zmr:Bearbeiter>
>                 <zmr:Name>Mustermann Max</zmr:Name>
>                 <zmr:GlobaleIdentifizierung>99mustermann</zmr:GlobaleIdentifizierung>
>         </zmr:Benutzer>
>         <zmr:Bearbeitungsgrund>ZPV Test</zmr:Bearbeitungsgrund>
>         <zmr:System>STP ZPV</zmr:System>
>     </zmr:Bearbeitung>
>     <zmr:PersonenSuchkriterien>
>       <zmr:Familienname>Mayrbäurl</zmr:Familienname>
>       <zmr:Vorname>Jürgen</zmr:Vorname>
>       <zmr:Geburtsdatum>1966-01-05</zmr:Geburtsdatum>
>     </zmr:PersonenSuchkriterien>
>   </zmr:Abfrageparameter>
> </zmr:BPKAbfrage>
>
> The ContentBasedRouter tells me that it can't find a matching rule for the
> exchange. Maybe the reason for this is the missing namespace in the xpath
> expression.
>
> Any idea? And how can I specify the namespace in the xpath expression?
>
> Greetings
> Juergen
>
> BTW: The message content will cause exceptions in the traceMessages() method
> of the DeliveryChannelImpl, when tracing is on.
> --
> View this message in context: http://www.nabble.com/NamespaceContext-in-XPath-based-content-router-t1512305.html#a4103093
> Sent from the ServiceMix - User forum at Nabble.com.
>
>