Search in sources :

Example 11 with WSAddressingFeature

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);
    }
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) GreeterImpl(org.apache.hello_world_soap_http.GreeterImpl) BusException(org.apache.cxf.BusException) Test(org.junit.Test)

Example 12 with 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);
    }
}
Also used : JaxWsServiceFactoryBean(org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) BeanInvoker(org.apache.cxf.service.invoker.BeanInvoker) BusException(org.apache.cxf.BusException) Test(org.junit.Test)

Example 13 with 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;
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) XMLStreamReader(javax.xml.stream.XMLStreamReader) DepthXMLStreamReader(org.apache.cxf.staxutils.DepthXMLStreamReader) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) QName(javax.xml.namespace.QName) Document(org.w3c.dom.Document) Feature(org.apache.cxf.feature.Feature) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) SOAPMessage(javax.xml.soap.SOAPMessage) StaxSource(org.apache.cxf.staxutils.StaxSource) Source(javax.xml.transform.Source) DataSource(javax.activation.DataSource) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) XMLStreamException(javax.xml.stream.XMLStreamException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) StaxSource(org.apache.cxf.staxutils.StaxSource)

Example 14 with WSAddressingFeature

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;
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) ConduitSelector(org.apache.cxf.endpoint.ConduitSelector) DeferredConduitSelector(org.apache.cxf.endpoint.DeferredConduitSelector) DeferredConduitSelector(org.apache.cxf.endpoint.DeferredConduitSelector)

Example 15 with WSAddressingFeature

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));
}
Also used : Bus(org.apache.cxf.Bus) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) Endpoint(org.apache.cxf.endpoint.Endpoint) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) WSAddressingFeatureApplier(org.apache.cxf.ws.addressing.WSAddressingFeature.WSAddressingFeatureApplier) Conduit(org.apache.cxf.transport.Conduit) InterceptorProvider(org.apache.cxf.interceptor.InterceptorProvider) Test(org.junit.Test)

Aggregations

WSAddressingFeature (org.apache.cxf.ws.addressing.WSAddressingFeature)17 Test (org.junit.Test)8 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)3 IOException (java.io.IOException)2 QName (javax.xml.namespace.QName)2 BusException (org.apache.cxf.BusException)2 Client (org.apache.cxf.endpoint.Client)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Server (org.apache.cxf.endpoint.Server)2 JaxWsProxyFactoryBean (org.apache.cxf.jaxws.JaxWsProxyFactoryBean)2 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)2 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 AbstractCXFTest (org.apache.cxf.test.AbstractCXFTest)2 Conduit (org.apache.cxf.transport.Conduit)2 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)2 GreeterImpl (org.apache.hello_world_soap_http.GreeterImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1