Search in sources :

Example 6 with Service

use of org.apache.cxf.service.Service in project tesb-rt-se by Talend.

the class LocatorFeatureTest method initializeClient.

@Test
public void initializeClient() throws EndpointException {
    LocatorClientEnabler enabler = new LocatorClientEnabler();
    enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
    expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
    replayAll();
    EndpointInfo ei = new EndpointInfo();
    Service service = new org.apache.cxf.service.ServiceImpl();
    EndpointImpl endpoint = new EndpointImpl(busMock, service, ei);
    Map<String, String> locatorProps = new HashMap<String, String>();
    locatorProps.put("key1", "value1");
    locatorProps.put("key2", "value2");
    endpoint.put(LocatorFeature.LOCATOR_PROPERTIES, locatorProps);
    endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
    Client client = new ClientImpl(busMock, endpoint);
    LocatorTargetSelector selector = new LocatorTargetSelector();
    selector.setEndpoint(endpoint);
    client.setConduitSelector(selector);
    LocatorFeatureImpl lf = new LocatorFeatureImpl();
    lf.setLocatorRegistrar(locatorRegistrarMock);
    lf.setClientEnabler(enabler);
    lf.initialize(client, busMock);
    Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) HashMap(java.util.HashMap) Service(org.apache.cxf.service.Service) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Test(org.junit.Test)

Example 7 with Service

use of org.apache.cxf.service.Service in project tesb-rt-se by Talend.

the class LocatorFeatureTest method initializeInterceptorProvider.

@Test
public void initializeInterceptorProvider() throws EndpointException {
    LocatorClientEnabler enabler = new LocatorClientEnabler();
    enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
    enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
    ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
    expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
    replayAll();
    EndpointInfo ei = new EndpointInfo();
    Service service = new org.apache.cxf.service.ServiceImpl();
    Endpoint endpoint = new EndpointImpl(busMock, service, ei);
    endpoint.put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
    ClientConfiguration client = new ClientConfiguration();
    LocatorTargetSelector selector = new LocatorTargetSelector();
    selector.setEndpoint(endpoint);
    client.setConduitSelector(selector);
    LocatorFeatureImpl lf = new LocatorFeatureImpl();
    lf.setLocatorRegistrar(locatorRegistrarMock);
    lf.setClientEnabler(enabler);
    lf.initialize((InterceptorProvider) client, busMock);
    Assert.assertTrue(((LocatorTargetSelector) client.getConduitSelector()).getStrategy() instanceof RandomSelectionStrategy);
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) Service(org.apache.cxf.service.Service) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) ClientConfiguration(org.apache.cxf.jaxrs.client.ClientConfiguration) Test(org.junit.Test)

Example 8 with Service

use of org.apache.cxf.service.Service in project jbossws-cxf by jbossws.

the class JBossWSInvokerTest method getTestExchange.

// build up a fake exchange instance, the minimum required to let the flow proceed till the JBossWSInvoker
private Exchange getTestExchange() {
    Exchange exchange = new ExchangeImpl();
    Message message = new MessageImpl();
    message.setExchange(exchange);
    exchange.setInMessage(message);
    exchange.put(BindingOperationInfo.class, new BindingOperationInfo());
    Service service = new ServiceImpl();
    MethodDispatcher md = new MethodDispatcher() {

        @Override
        public Method getMethod(BindingOperationInfo op) {
            return this.getClass().getMethods()[0];
        }

        @Override
        public BindingOperationInfo getBindingOperation(Method m, Endpoint endpoint) {
            return null;
        }

        @Override
        public void bind(OperationInfo o, Method... methods) {
        }
    };
    service.put(MethodDispatcher.class.getName(), md);
    exchange.put(Service.class, service);
    return exchange;
}
Also used : Exchange(org.apache.cxf.message.Exchange) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Endpoint(org.apache.cxf.endpoint.Endpoint) ServiceImpl(org.apache.cxf.service.ServiceImpl) Service(org.apache.cxf.service.Service) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) Method(java.lang.reflect.Method) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 9 with Service

use of org.apache.cxf.service.Service in project tomee by apache.

the class PhaseInterceptorChain method getServiceInfo.

private String getServiceInfo(Message message) {
    StringBuilder description = new StringBuilder();
    if (message.getExchange() != null) {
        Exchange exchange = message.getExchange();
        Service service = exchange.getService();
        if (service != null) {
            description.append('\'');
            description.append(service.getName());
            BindingOperationInfo boi = exchange.getBindingOperationInfo();
            OperationInfo opInfo = boi != null ? boi.getOperationInfo() : null;
            if (opInfo != null) {
                description.append('#').append(opInfo.getName());
            }
            description.append("\' ");
        }
    }
    return description.toString();
}
Also used : Exchange(org.apache.cxf.message.Exchange) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Service(org.apache.cxf.service.Service)

Example 10 with Service

use of org.apache.cxf.service.Service in project cxf by apache.

the class AbstractOutDatabindingInterceptor method writeParts.

protected void writeParts(Message message, Exchange exchange, BindingOperationInfo operation, MessageContentsList objs, List<MessagePartInfo> parts) {
    OutputStream out = message.getContent(OutputStream.class);
    XMLStreamWriter origXmlWriter = message.getContent(XMLStreamWriter.class);
    Service service = exchange.getService();
    XMLStreamWriter xmlWriter = origXmlWriter;
    CachingXmlEventWriter cache = null;
    // configure endpoint and operation level schema validation
    setOperationSchemaValidation(message);
    // need to cache the events in case validation fails or buffering is enabled
    if (shouldBuffer(message)) {
        if (!(xmlWriter instanceof CachingXmlEventWriter)) {
            cache = new CachingXmlEventWriter();
            try {
                cache.setNamespaceContext(origXmlWriter.getNamespaceContext());
            } catch (XMLStreamException e) {
            // ignorable, will just get extra namespace decls
            }
            xmlWriter = cache;
        }
        out = null;
    }
    if (out != null && writeToOutputStream(message, operation.getBinding(), service) && !MessageUtils.getContextualBoolean(message, DISABLE_OUTPUTSTREAM_OPTIMIZATION, false)) {
        if (xmlWriter != null) {
            try {
                xmlWriter.writeCharacters("");
                xmlWriter.flush();
            } catch (XMLStreamException e) {
                throw new Fault(e);
            }
        }
        DataWriter<OutputStream> osWriter = getDataWriter(message, service, OutputStream.class);
        for (MessagePartInfo part : parts) {
            if (objs.hasValue(part)) {
                Object o = objs.get(part);
                osWriter.write(o, part, out);
            }
        }
    } else {
        DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message, service, XMLStreamWriter.class);
        for (MessagePartInfo part : parts) {
            if (objs.hasValue(part)) {
                NamespaceContext c = null;
                if (!part.isElement() && xmlWriter instanceof CachingXmlEventWriter) {
                    try {
                        c = xmlWriter.getNamespaceContext();
                        xmlWriter.setNamespaceContext(new CachingXmlEventWriter.NSContext(null));
                    } catch (XMLStreamException e) {
                    // ignore
                    }
                }
                Object o = objs.get(part);
                dataWriter.write(o, part, xmlWriter);
                if (c != null) {
                    try {
                        xmlWriter.setNamespaceContext(c);
                    } catch (XMLStreamException e) {
                    // ignore
                    }
                }
            }
        }
    }
    if (cache != null) {
        try {
            for (XMLEvent event : cache.getEvents()) {
                StaxUtils.writeEvent(event, origXmlWriter);
            }
        } catch (XMLStreamException e) {
            throw new Fault(e);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) Service(org.apache.cxf.service.Service) MessagePartInfo(org.apache.cxf.service.model.MessagePartInfo) CachingXmlEventWriter(org.apache.cxf.staxutils.CachingXmlEventWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) NamespaceContext(javax.xml.namespace.NamespaceContext) XMLEvent(javax.xml.stream.events.XMLEvent)

Aggregations

Service (org.apache.cxf.service.Service)270 Test (org.junit.Test)167 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)138 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)138 Client (org.apache.cxf.endpoint.Client)128 HashMap (java.util.HashMap)100 WSSSecurityProperties (org.apache.wss4j.stax.ext.WSSSecurityProperties)89 ArrayList (java.util.ArrayList)81 QName (javax.xml.namespace.QName)69 Properties (java.util.Properties)65 Endpoint (org.apache.cxf.endpoint.Endpoint)45 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)44 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)37 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)33 Server (org.apache.cxf.endpoint.Server)27 OperationInfo (org.apache.cxf.service.model.OperationInfo)26 InterfaceInfo (org.apache.cxf.service.model.InterfaceInfo)23 Exchange (org.apache.cxf.message.Exchange)22 Bus (org.apache.cxf.Bus)21 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)21