Search in sources :

Example 26 with Feature

use of org.apache.cxf.feature.Feature in project cxf by apache.

the class BusDefinitionParserTest method testFeatures.

@Test
@SuppressWarnings("deprecation")
public void testFeatures() {
    String cfgFile = "org/apache/cxf/bus/spring/bus.xml";
    Bus bus = new SpringBusFactory().createBus(cfgFile, true);
    List<Interceptor<? extends Message>> in = bus.getInInterceptors();
    assertTrue("could not find logging interceptor.", in.stream().anyMatch(i -> i.getClass() == org.apache.cxf.interceptor.LoggingInInterceptor.class));
    Collection<Feature> features = bus.getFeatures();
    TestFeature tf = null;
    for (Feature f : features) {
        if (f instanceof TestFeature) {
            tf = (TestFeature) f;
            break;
        }
    }
    assertNotNull(tf);
    assertTrue("test feature  has not been initialised", tf.initialised);
    assertNotNull("test feature has not been injected", tf.testBean);
    assertTrue("bean injected into test feature has not been initialised", tf.testBean.initialised);
}
Also used : Bus(org.apache.cxf.Bus) BusLifeCycleListener(org.apache.cxf.buslifecycle.BusLifeCycleListener) Interceptor(org.apache.cxf.interceptor.Interceptor) Message(org.apache.cxf.message.Message) Assert.assertNotNull(org.junit.Assert.assertNotNull) Collection(java.util.Collection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Feature(org.apache.cxf.feature.Feature) BusLifeCycleManager(org.apache.cxf.buslifecycle.BusLifeCycleManager) List(java.util.List) AbstractFeature(org.apache.cxf.feature.AbstractFeature) PostConstruct(javax.annotation.PostConstruct) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Assert.assertEquals(org.junit.Assert.assertEquals) Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) Interceptor(org.apache.cxf.interceptor.Interceptor) Feature(org.apache.cxf.feature.Feature) AbstractFeature(org.apache.cxf.feature.AbstractFeature) Test(org.junit.Test)

Example 27 with Feature

use of org.apache.cxf.feature.Feature 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) IllegalEmptyResponseException(org.apache.cxf.endpoint.ClientImpl.IllegalEmptyResponseException) IOException(java.io.IOException) WebServiceException(javax.xml.ws.WebServiceException) WSAddressingFeature(org.apache.cxf.ws.addressing.WSAddressingFeature) StaxSource(org.apache.cxf.staxutils.StaxSource)

Example 28 with Feature

use of org.apache.cxf.feature.Feature in project cxf by apache.

the class ServiceImpl method createDispatch.

public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
    // using this instead of JaxWsClientFactoryBean so that handlers are configured
    JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
    // Initialize Features.
    configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
    final AbstractServiceFactoryBean sf;
    try {
        DataBinding db;
        if (context != null) {
            db = new JAXBDataBinding(context);
        } else {
            db = new SourceDataBinding(type);
        }
        sf = createDispatchService(db);
    } catch (ServiceConstructionException e) {
        throw new WebServiceException(e);
    }
    JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
    // if the client factory has properties specified, then set those into the endpoint
    if (clientFac.getProperties() != null) {
        endpoint.putAll(clientFac.getProperties());
    }
    // add all the client factory features onto the endpoint feature list
    endpoint.getFeatures().addAll(clientFac.getFeatures());
    // if the client factory has a bus specified (other than the thread default),
    // then use that for the client.  Otherwise use the bus from this service.
    Bus clientBus = getBus();
    if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
        clientBus = clientFac.getBus();
    }
    @SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
    // CXF-3956
    hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
    endpoint.getJaxwsBinding().setHandlerChain(hc);
    // create the client object, then initialize the endpoint features against it
    Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
    for (Feature af : endpoint.getFeatures()) {
        af.initialize(client, clientBus);
    }
    // CXF-2822
    initIntercepors(client, clientFac);
    if (executor != null) {
        client.getEndpoint().setExecutor(executor);
    }
    // then try to get it from the wsdl
    if (!StringUtils.isEmpty(clientFac.getAddress())) {
        client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
    } else {
        // Set the the EPR's address in EndpointInfo
        PortInfoImpl portInfo = portInfos.get(portName);
        if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
            client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
        }
    }
    Dispatch<T> disp = new DispatchImpl<>(client, mode, context, type);
    configureObject(disp);
    return disp;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Example 29 with Feature

use of org.apache.cxf.feature.Feature in project tesb-rt-se by Talend.

the class StsConfigurator method removeMessageLogging.

private void removeMessageLogging(Bus bus) {
    Collection<Feature> features = bus.getFeatures();
    Feature logFeature = null;
    Interceptor inLogInterceptor = null;
    Interceptor outLogInterceptor = null;
    for (Feature feature : features) {
        if (feature instanceof LoggingFeature) {
            logFeature = feature;
            break;
        }
    }
    if (logFeature != null) {
        features.remove(logFeature);
    }
    for (Interceptor interceptor : bus.getInInterceptors()) {
        if (interceptor instanceof LoggingInInterceptor) {
            inLogInterceptor = interceptor;
            break;
        }
    }
    for (Interceptor interceptor : bus.getOutInterceptors()) {
        if (interceptor instanceof LoggingOutInterceptor) {
            outLogInterceptor = interceptor;
            break;
        }
    }
    if (inLogInterceptor != null) {
        bus.getInInterceptors().remove(inLogInterceptor);
    // System.out.println("\nRemove in Interceptor = " + inLogInterceptor.getClass().getName());
    }
    if (outLogInterceptor != null) {
        bus.getOutInterceptors().remove(outLogInterceptor);
    // System.out.println("\nRemove out Interceptor = " + inLogInterceptor.getClass().getName());
    }
}
Also used : LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingFeature(org.apache.cxf.feature.LoggingFeature) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) LoggingFeature(org.apache.cxf.feature.LoggingFeature) Feature(org.apache.cxf.feature.Feature) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor)

Example 30 with Feature

use of org.apache.cxf.feature.Feature in project tesb-rt-se by Talend.

the class StsConfiguratorTest method getBus.

private Bus getBus() {
    Collection<Feature> features = new ArrayList<Feature>();
    features.add(new LoggingFeature());
    List<Interceptor<? extends Message>> inInterceptors = new ArrayList<Interceptor<? extends Message>>();
    inInterceptors.add(new LoggingInInterceptor());
    List<Interceptor<? extends Message>> inFaultInterceptors = new ArrayList<Interceptor<? extends Message>>();
    inFaultInterceptors.add(new LoggingInInterceptor());
    List<Interceptor<? extends Message>> outInterceptors = new ArrayList<Interceptor<? extends Message>>();
    outInterceptors.add(new LoggingOutInterceptor());
    List<Interceptor<? extends Message>> outFaultInterceptors = new ArrayList<Interceptor<? extends Message>>();
    outFaultInterceptors.add(new LoggingOutInterceptor());
    Bus bus = createMock(Bus.class);
    expect(bus.getFeatures()).andReturn(features).anyTimes();
    expect(bus.getInInterceptors()).andReturn(inInterceptors).anyTimes();
    expect(bus.getOutInterceptors()).andReturn(outInterceptors).anyTimes();
    expect(bus.getInFaultInterceptors()).andReturn(inFaultInterceptors).anyTimes();
    expect(bus.getOutFaultInterceptors()).andReturn(outFaultInterceptors).anyTimes();
    replay(bus);
    return bus;
}
Also used : Bus(org.apache.cxf.Bus) Message(org.apache.cxf.message.Message) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingFeature(org.apache.cxf.feature.LoggingFeature) ArrayList(java.util.ArrayList) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor) Feature(org.apache.cxf.feature.Feature) LoggingFeature(org.apache.cxf.feature.LoggingFeature) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingOutInterceptor(org.apache.cxf.interceptor.LoggingOutInterceptor) LoggingInInterceptor(org.apache.cxf.interceptor.LoggingInInterceptor)

Aggregations

Feature (org.apache.cxf.feature.Feature)37 ArrayList (java.util.ArrayList)16 Bus (org.apache.cxf.Bus)8 Endpoint (org.apache.cxf.endpoint.Endpoint)7 EndpointImpl (org.apache.cxf.endpoint.EndpointImpl)7 List (java.util.List)6 Server (org.apache.cxf.endpoint.Server)6 AbstractFeature (org.apache.cxf.feature.AbstractFeature)6 LoggingFeature (org.apache.cxf.feature.LoggingFeature)6 IOException (java.io.IOException)5 QName (javax.xml.namespace.QName)5 Interceptor (org.apache.cxf.interceptor.Interceptor)5 Test (org.junit.Test)5 HashMap (java.util.HashMap)4 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)4 Message (org.apache.cxf.message.Message)4 AbstractServiceFactoryBean (org.apache.cxf.service.factory.AbstractServiceFactoryBean)4 SingletonResourceProvider (org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider)3 EndpointImpl (org.apache.cxf.jaxws.EndpointImpl)3 FactoryBeanListener (org.apache.cxf.service.factory.FactoryBeanListener)3