use of org.apache.cxf.ws.addressing.WSAddressingFeature in project cxf by apache.
the class EndpointImplTest method testAddWSAFeature.
@Test
public void testAddWSAFeature() throws Exception {
GreeterImpl greeter = new GreeterImpl();
JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
serviceFactory.setBus(getBus());
serviceFactory.setInvoker(new BeanInvoker(greeter));
serviceFactory.setServiceClass(GreeterImpl.class);
try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, new JaxWsServerFactoryBean(serviceFactory))) {
endpoint.getFeatures().add(new WSAddressingFeature());
try {
String address = "http://localhost:8080/test";
endpoint.publish(address);
} catch (IllegalArgumentException ex) {
assertTrue(ex.getCause() instanceof BusException);
assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException) ex.getCause()).getCode());
}
assertTrue(serviceFactory.getFeatures().size() == 1);
assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature);
}
}
use of org.apache.cxf.ws.addressing.WSAddressingFeature in project cxf by apache.
the class EndpointImplTest method testJaxWsaFeature.
@Test
public void testJaxWsaFeature() throws Exception {
HelloWsa greeter = new HelloWsa();
JaxWsServiceFactoryBean serviceFactory = new JaxWsServiceFactoryBean();
serviceFactory.setBus(getBus());
serviceFactory.setInvoker(new BeanInvoker(greeter));
serviceFactory.setServiceClass(HelloWsa.class);
try (EndpointImpl endpoint = new EndpointImpl(getBus(), greeter, new JaxWsServerFactoryBean(serviceFactory))) {
try {
String address = "http://localhost:8080/test";
endpoint.publish(address);
} catch (IllegalArgumentException ex) {
assertTrue(ex.getCause() instanceof BusException);
assertEquals("BINDING_INCOMPATIBLE_ADDRESS_EXC", ((BusException) ex.getCause()).getCode());
}
assertEquals(1, serviceFactory.getFeatures().size());
assertTrue(serviceFactory.getFeatures().get(0) instanceof WSAddressingFeature);
}
}
use of org.apache.cxf.ws.addressing.WSAddressingFeature in project cxf by apache.
the class DispatchImpl method calculateOpName.
@SuppressWarnings("unchecked")
private QName calculateOpName(Holder<T> holder, QName opName, boolean hasOpName) throws XMLStreamException {
boolean findDispatchOp = Boolean.TRUE.equals(getRequestContext().get("find.dispatch.operation"));
// if the addressing feature is enabled, set findDispatchOp to true
if (!findDispatchOp) {
// the feature list to be searched is the endpoint and the bus's lists
List<Feature> endpointFeatures = ((JaxWsClientEndpointImpl) client.getEndpoint()).getFeatures();
List<Feature> allFeatures;
if (client.getBus().getFeatures() != null) {
allFeatures = new ArrayList<>(endpointFeatures.size() + client.getBus().getFeatures().size());
allFeatures.addAll(endpointFeatures);
allFeatures.addAll(client.getBus().getFeatures());
} else {
allFeatures = endpointFeatures;
}
for (Feature feature : allFeatures) {
if (feature instanceof WSAddressingFeature) {
findDispatchOp = true;
}
}
}
Source createdSource = null;
Map<String, QName> payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
if (findDispatchOp && !payloadOPMap.isEmpty()) {
QName payloadElementName = null;
if (holder.value instanceof javax.xml.transform.Source) {
XMLStreamReader reader = null;
try {
reader = StaxUtils.createXMLStreamReader((javax.xml.transform.Source) holder.value);
Document document = StaxUtils.read(reader);
createdSource = new StaxSource(StaxUtils.createXMLStreamReader(document));
payloadElementName = getPayloadElementName(document.getDocumentElement());
} catch (Exception e) {
// ignore, we are trying to get the operation name
} finally {
StaxUtils.close(reader);
}
}
if (holder.value instanceof SOAPMessage) {
payloadElementName = getPayloadElementName((SOAPMessage) holder.value);
}
if (this.context != null) {
payloadElementName = getPayloadElementName(holder.value);
}
if (payloadElementName != null) {
if (hasOpName) {
// Verify the payload element against the given operation name.
// This allows graceful handling of non-standard WSDL definitions
// where different operations have the same payload element.
QName expectedElementName = payloadOPMap.get(opName.toString());
if (expectedElementName == null || !expectedElementName.toString().equals(payloadElementName.toString())) {
// Verification of the provided operation name failed.
// Resolve the operation name from the payload element.
hasOpName = false;
payloadOPMap = createPayloadEleOpNameMap(client.getEndpoint().getBinding().getBindingInfo(), hasOpName);
}
}
QName dispatchedOpName = null;
if (!hasOpName) {
dispatchedOpName = payloadOPMap.get(payloadElementName.toString());
}
if (null != dispatchedOpName) {
BindingOperationInfo dbop = client.getEndpoint().getBinding().getBindingInfo().getOperation(dispatchedOpName);
if (dbop != null) {
opName = dispatchedOpName;
}
}
}
}
if (createdSource != null) {
holder.value = (T) createdSource;
}
return opName;
}
use of org.apache.cxf.ws.addressing.WSAddressingFeature in project cxf by apache.
the class Proxy method createClient.
protected Client createClient(Bus bus, Endpoint endpoint, final ProtocolVariation protocol, Conduit conduit, final EndpointReferenceType address) {
ConduitSelector cs = new DeferredConduitSelector(conduit) {
@Override
public synchronized Conduit selectConduit(Message message) {
Conduit conduit = null;
EndpointInfo endpointInfo = getEndpoint().getEndpointInfo();
EndpointReferenceType original = endpointInfo.getTarget();
try {
if (null != address) {
endpointInfo.setAddress(address);
}
conduit = super.selectConduit(message);
} finally {
endpointInfo.setAddress(original);
}
return conduit;
}
};
RMClient client = new RMClient(bus, endpoint, cs);
// WS-RM requires ws-addressing
WSAddressingFeature wsa = new WSAddressingFeature();
wsa.setAddressingRequired(true);
wsa.initialize(client, bus);
Map<String, Object> context = client.getRequestContext();
context.put(MAPAggregator.ADDRESSING_NAMESPACE, protocol.getWSANamespace());
context.put(RMManager.WSRM_VERSION_PROPERTY, protocol.getWSRMNamespace());
context.put(RMManager.WSRM_WSA_VERSION_PROPERTY, protocol.getWSANamespace());
return client;
}
use of org.apache.cxf.ws.addressing.WSAddressingFeature in project cxf by apache.
the class ProxyTest method testRMClientConstruction.
@Test
public void testRMClientConstruction() {
Proxy proxy = new Proxy(rme);
Bus bus = control.createMock(Bus.class);
EasyMock.expect(bus.getExtension(WSAddressingFeatureApplier.class)).andReturn(new WSAddressingFeatureApplier() {
@Override
public void initializeProvider(WSAddressingFeature feature, InterceptorProvider provider, Bus bus) {
}
}).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
Conduit conduit = control.createMock(Conduit.class);
org.apache.cxf.ws.addressing.EndpointReferenceType address = control.createMock(org.apache.cxf.ws.addressing.EndpointReferenceType.class);
control.replay();
assertNotNull(proxy.createClient(bus, endpoint, ProtocolVariation.RM10WSA200408, conduit, address));
}
Aggregations