camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marcin Cylke <...@touk.pl>
Subject Re: [ camel ] XML Namespace and Xpath injection
Date Mon, 12 Sep 2011 12:28:53 GMT
On 09/12/2011 02:21 PM, atouret.nospam@free.fr wrote:
> Hello,
> I'm trying to inject a value in bean trough an xpath injection as following :
>
>
> 	public void audit(@XPath("/Envelope/Body/getToken/username/text()") String id, @Body
String body) {
> 		logger.info("Id :"+id );
> 		logger.info("Body = "+body);
> 	}
>
> Unfortunately, all the elements are fully qualified by a namespace.

You can pass namespaces to @XPath annotation, or create your own 
annotation, with namespaces included:

@Retention(RetentionPolicy.RUNTIME)
@Target( { ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER })
@LanguageAnnotation(language = "xpath", factory = 
XpathExpressionAnnotationFactoryImproved.class)
public @interface StXpath {
	String value();

	// You can add the namespaces as the default value of the annotation
	NamespacePrefix[] namespaces() default { @NamespacePrefix(prefix = 
"st", uri = "http://example.pl/service/schemas") };

	Class<?> resultType() default String.class;
}



Mime
View raw message