cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Maciej Kwiecien" <maciej.kwiec...@gmail.com>
Subject How to customize WS-Addressing using interceptor?
Date Wed, 30 Jul 2008 18:44:43 GMT
Hello,

I have following code that sets WS-Addressing headers in my client
application.

AddressingBuilder builder = AddressingBuilder.getAddressingBuilder();
AddressingProperties addressingProps = builder.newAddressingProperties();
((AddressingPropertiesImpl)addressingProps)
.exposeAs(VersionTransformer.Names200403.WSA_NAMESPACE_NAME);
AttributedURIType to = new AttributedURIType();
AttributedURIType replyTo = new AttributedURIType();
AttributedURIType faultTo = new AttributedURIType();
to.setValue("urn:ABC");
faultTo.setValue("http://example.com/demo.ashx");
replyTo.setValue("http://example.com/demo.ashx");

EndpointReferenceType toRef = new EndpointReferenceType();
EndpointReferenceType replyToRef = new EndpointReferenceType();
EndpointReferenceType faultToRef = new EndpointReferenceType();
toRef.setAddress(to);
replyToRef.setAddress(replyTo);
faultToRef.setAddress(faultTo);
addressingProps.setTo(toRef);
addressingProps.setReplyTo(replyToRef);
addressingProps.setFaultTo(faultToRef);
// associate MAPs with request context
Map<String, Object> requestContext =
((BindingProvider)port).getRequestContext();
requestContext.put(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES,
addressingProps)


Although it works fine(I get successful response from web service) I'd like
to set WS-Addressing via interceptor mechanism.

I tried sth like that:

public class CustomWSAddressingInterceptor extends AbstractSoapInterceptor {

private static final String TTL_URL = "
http://www.iwsg.testthetrainline.com/wslistener/Listener.ashx";
private static final String TO_TTL = "urn:IWSG";

public CustomWSAddressingInterceptor() {
super(Phase.PRE_PROTOCOL);
getAfter().add(WSAddressingFeature.class.getName());
}

@Override
public void handleMessage(final SoapMessage message) throws Fault {

AddressingProperties addressing = (AddressingProperties)message
.get(CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
addressing = convertTo200403(addressing);
message.put(CLIENT_ADDRESSING_PROPERTIES_OUTBOUND, addressing);

AttributedURIType msgId = addressing.getMessageID();
}

/**
* Converts to 2004/03 WS-Addressing version and sets TTL specific data
*
* @param defualtProps
*/
private AddressingProperties convertTo200403(AddressingProperties
defualtProps) {
AddressingBuilder builder = AddressingBuilder.getAddressingBuilder();
AddressingProperties addressingProps = builder.newAddressingProperties();

((AddressingPropertiesImpl)addressingProps)
.exposeAs(VersionTransformer.Names200403.WSA_NAMESPACE_NAME);

System.out.println(addressingProps.getNamespaceURI());
AttributedURIType to = new AttributedURIType();
AttributedURIType replyTo = new AttributedURIType();
AttributedURIType faultTo = new AttributedURIType();
to.setValue(TO_TTL);
faultTo.setValue(TTL_URL);
replyTo.setValue(TTL_URL);

EndpointReferenceType toRef = new EndpointReferenceType();
EndpointReferenceType replyToRef = new EndpointReferenceType();
EndpointReferenceType faultToRef = new EndpointReferenceType();

toRef.setAddress(to);
replyToRef.setAddress(replyTo);
faultToRef.setAddress(faultTo);
addressingProps.setTo(toRef);
addressingProps.setReplyTo(replyToRef);
addressingProps.setFaultTo(faultToRef);
return addressingProps;

}

}

Above code does not work - although everything looks fine on client side
 web service responds with HTTP 400...

What am I doing wrong? What phase should be set for my interceptop? When it
should be invoked in interceptor chain?

As always any help will be appreciated.

Regards,
Maciej

PS:According to Dan Kulp  suggestion I've added WS-Addressing 2004/03
support by implementing VersionTransformer...

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message