Search in sources :

Example 11 with DestinationFactory

use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.

the class MAPAggregatorTest method testGetReplyToUsingBaseAddress.

@Test
public void testGetReplyToUsingBaseAddress() throws Exception {
    Message message = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    message.setExchange(exchange);
    final String localReplyTo = "/SoapContext/decoupled";
    final String decoupledEndpointBase = "http://localhost:8181/cxf";
    final String replyTo = decoupledEndpointBase + localReplyTo;
    ServiceInfo s = new ServiceInfo();
    Service svc = new ServiceImpl(s);
    EndpointInfo ei = new EndpointInfo();
    InterfaceInfo ii = s.createInterface(new QName("FooInterface"));
    s.setInterface(ii);
    ii.addOperation(new QName("fooOp"));
    SoapBindingInfo b = new SoapBindingInfo(s, "http://schemas.xmlsoap.org/soap/", Soap11.getInstance());
    b.setTransportURI("http://schemas.xmlsoap.org/soap/http");
    ei.setBinding(b);
    ei.setAddress("http://nowhere.com/bar/foo");
    ei.setName(new QName("http://nowhere.com/port", "foo"));
    Bus bus = new ExtensionManagerBus();
    DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
    DestinationFactory df = control.createMock(DestinationFactory.class);
    Destination d = control.createMock(Destination.class);
    bus.setExtension(dfm, DestinationFactoryManager.class);
    EasyMock.expect(dfm.getDestinationFactoryForUri(localReplyTo)).andReturn(df);
    EasyMock.expect(df.getDestination(EasyMock.anyObject(EndpointInfo.class), EasyMock.anyObject(Bus.class))).andReturn(d);
    EasyMock.expect(d.getAddress()).andReturn(EndpointReferenceUtils.getEndpointReference(localReplyTo));
    Endpoint ep = new EndpointImpl(bus, svc, ei);
    exchange.put(Endpoint.class, ep);
    exchange.put(Bus.class, bus);
    exchange.setOutMessage(message);
    setUpMessageProperty(message, REQUESTOR_ROLE, Boolean.TRUE);
    message.getContextualProperty(WSAContextUtils.REPLYTO_PROPERTY);
    message.put(WSAContextUtils.REPLYTO_PROPERTY, localReplyTo);
    message.put(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY, decoupledEndpointBase);
    AddressingProperties maps = new AddressingProperties();
    AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
    maps.setMessageID(id);
    maps.setAction(ContextUtils.getAttributedURI(""));
    setUpMessageProperty(message, CLIENT_ADDRESSING_PROPERTIES, maps);
    control.replay();
    aggregator.mediate(message, false);
    AddressingProperties props = (AddressingProperties) message.get(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND);
    assertEquals(replyTo, props.getReplyTo().getAddress().getValue());
    control.verify();
}
Also used : Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ServiceImpl(org.apache.cxf.service.ServiceImpl) QName(javax.xml.namespace.QName) EndpointImpl(org.apache.cxf.endpoint.EndpointImpl) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) Service(org.apache.cxf.service.Service) Exchange(org.apache.cxf.message.Exchange) ServiceInfo(org.apache.cxf.service.model.ServiceInfo) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Endpoint(org.apache.cxf.endpoint.Endpoint) SoapBindingInfo(org.apache.cxf.binding.soap.model.SoapBindingInfo) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo) MessageImpl(org.apache.cxf.message.MessageImpl) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 12 with DestinationFactory

use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.

the class WSDLServiceBuilder method buildEndpoint.

public EndpointInfo buildEndpoint(ServiceInfo service, BindingInfo bi, Port port) {
    List<?> elements = port.getExtensibilityElements();
    String ns = null;
    DestinationFactory factory = null;
    EndpointInfo ei = null;
    if (null != elements && !elements.isEmpty()) {
        for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
            ns = el.getElementType().getNamespaceURI();
            try {
                factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
            } catch (BusException e) {
            // do nothing
            }
            if (factory != null) {
                break;
            }
        }
        if (factory == null) {
            ns = ((ExtensibilityElement) elements.get(0)).getElementType().getNamespaceURI();
        }
    }
    if (factory == null) {
        // get the transport id from bindingInfo
        elements = port.getBinding().getExtensibilityElements();
        if (null != elements && !elements.isEmpty()) {
            for (ExtensibilityElement el : CastUtils.cast(elements, ExtensibilityElement.class)) {
                if (el instanceof SOAPBinding) {
                    ns = ((SOAPBinding) el).getTransportURI();
                    break;
                } else if (el instanceof SOAP12Binding) {
                    ns = ((SOAP12Binding) el).getTransportURI();
                    break;
                // TODO: this is really ugly, but how to link between
                // this binding and this transport ?
                }
            }
        }
        if (ns == null) {
            if (ignoreUnknownBindings) {
                return null;
            }
            org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("MISSING_DESTINATION_FACTORY", LOG, port.getName());
            throw new WSDLRuntimeException(msg);
        }
        try {
            factory = bus.getExtension(DestinationFactoryManager.class).getDestinationFactory(ns);
        } catch (BusException e) {
        // do nothing
        }
    }
    if (factory instanceof WSDLEndpointFactory) {
        WSDLEndpointFactory wFactory = (WSDLEndpointFactory) factory;
        ei = wFactory.createEndpointInfo(bus, service, bi, port.getExtensibilityElements());
    }
    if (ei == null) {
        ei = new EndpointInfo(service, ns);
    }
    copyDocumentation(ei, port);
    ei.setName(new QName(service.getName().getNamespaceURI(), port.getName()));
    ei.setBinding(bi);
    copyExtensors(ei, port.getExtensibilityElements());
    copyExtensionAttributes(ei, port);
    service.addEndpoint(ei);
    DescriptionInfo d = service.getDescription();
    if (null != d) {
        d.getDescribed().add(ei);
    }
    return ei;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) Message(javax.wsdl.Message) QName(javax.xml.namespace.QName) SOAPBinding(javax.wsdl.extensions.soap.SOAPBinding) ExtensibilityElement(javax.wsdl.extensions.ExtensibilityElement) JAXBExtensibilityElement(org.apache.cxf.wsdl.JAXBExtensibilityElement) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) SOAP12Binding(javax.wsdl.extensions.soap12.SOAP12Binding) DescriptionInfo(org.apache.cxf.service.model.DescriptionInfo) BusException(org.apache.cxf.BusException)

Example 13 with DestinationFactory

use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.

the class ServiceWSDLBuilderTest method setupWSDL.

private void setupWSDL(String wsdlPath, boolean doXsdImports) throws Exception {
    String wsdlUrl = getClass().getResource(wsdlPath).toString();
    LOG.info("the path of wsdl file is " + wsdlUrl);
    WSDLFactory wsdlFactory = WSDLFactory.newInstance();
    WSDLReader wsdlReader = wsdlFactory.newWSDLReader();
    wsdlReader.setFeature("javax.wsdl.verbose", false);
    def = wsdlReader.readWSDL(wsdlUrl);
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
    destinationFactory = control.createMock(DestinationFactory.class);
    wsdlServiceBuilder = new WSDLServiceBuilder(bus, false);
    for (Service serv : CastUtils.cast(def.getServices().values(), Service.class)) {
        if (serv != null) {
            service = serv;
            break;
        }
    }
    EasyMock.expect(bus.getExtension(WSDLManager.class)).andReturn(new WSDLManagerImpl()).anyTimes();
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager);
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager);
    EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory);
    control.replay();
    serviceInfo = wsdlServiceBuilder.buildServices(def, service).get(0);
    ServiceWSDLBuilder builder = new ServiceWSDLBuilder(bus, serviceInfo);
    builder.setUseSchemaImports(doXsdImports);
    builder.setBaseFileName("HelloWorld");
    newDef = builder.build(new HashMap<String, SchemaInfo>());
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HashMap(java.util.HashMap) Service(javax.wsdl.Service) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) WSDLFactory(javax.wsdl.factory.WSDLFactory) WSDLManager(org.apache.cxf.wsdl.WSDLManager) WSDLReader(javax.wsdl.xml.WSDLReader)

Example 14 with DestinationFactory

use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.

the class WSDLServiceBuilderTest method buildService.

private void buildService(QName endpointName) throws Exception {
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    destinationFactoryManager = control.createMock(DestinationFactoryManager.class);
    DestinationFactory destinationFactory = control.createMock(DestinationFactory.class);
    WSDLServiceBuilder wsdlServiceBuilder = new WSDLServiceBuilder(bus);
    EasyMock.expect(bus.getExtension(BindingFactoryManager.class)).andReturn(bindingFactoryManager).anyTimes();
    EasyMock.expect(bus.getExtension(DestinationFactoryManager.class)).andReturn(destinationFactoryManager).atLeastOnce();
    EasyMock.expect(destinationFactoryManager.getDestinationFactory("http://schemas.xmlsoap.org/wsdl/soap/")).andReturn(destinationFactory).anyTimes();
    control.replay();
    serviceInfos = wsdlServiceBuilder.buildServices(def, service, endpointName);
    if (!serviceInfos.isEmpty()) {
        serviceInfo = serviceInfos.get(0);
    } else {
        serviceInfo = null;
    }
}
Also used : Bus(org.apache.cxf.Bus) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager)

Example 15 with DestinationFactory

use of org.apache.cxf.transport.DestinationFactory in project cxf by apache.

the class AbstractJAXRSFactoryBean method createEndpointInfo.

/*
     * EndpointInfo contains information form WSDL's physical part such as
     * endpoint address, binding, transport etc. For JAX-RS based EndpointInfo,
     * as there is no WSDL, these information are set manually, eg, default
     * transport is http, binding is JAX-RS binding, endpoint address is from
     * server mainline.
     */
protected EndpointInfo createEndpointInfo(Service service) throws BusException {
    String transportId = getTransportId();
    if (transportId == null && getAddress() != null) {
        DestinationFactory df = getDestinationFactory();
        if (df == null) {
            DestinationFactoryManager dfm = getBus().getExtension(DestinationFactoryManager.class);
            df = dfm.getDestinationFactoryForUri(getAddress());
            super.setDestinationFactory(df);
        }
        if (df != null) {
            transportId = df.getTransportIds().get(0);
        }
    }
    // default to http transport
    if (transportId == null) {
        transportId = "http://cxf.apache.org/transports/http";
    }
    setTransportId(transportId);
    EndpointInfo ei = new EndpointInfo();
    ei.setTransportId(transportId);
    ei.setName(serviceFactory.getService().getName());
    ei.setAddress(getAddress());
    BindingInfo bindingInfo = createBindingInfo();
    ei.setBinding(bindingInfo);
    if (!StringUtils.isEmpty(publishedEndpointUrl)) {
        ei.setProperty("publishedEndpointUrl", publishedEndpointUrl);
    }
    ei.setName(service.getName());
    serviceFactory.sendEvent(FactoryBeanListener.Event.ENDPOINTINFO_CREATED, ei);
    return ei;
}
Also used : DestinationFactory(org.apache.cxf.transport.DestinationFactory) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) BindingInfo(org.apache.cxf.service.model.BindingInfo)

Aggregations

DestinationFactory (org.apache.cxf.transport.DestinationFactory)19 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)18 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)10 Bus (org.apache.cxf.Bus)9 Destination (org.apache.cxf.transport.Destination)7 QName (javax.xml.namespace.QName)6 BusException (org.apache.cxf.BusException)4 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)4 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)4 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)4 Test (org.junit.Test)4 ConfigurerImpl (org.apache.cxf.configuration.spring.ConfigurerImpl)3 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)3 IOException (java.io.IOException)2 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 Message (org.apache.cxf.message.Message)2 MessageImpl (org.apache.cxf.message.MessageImpl)2 BindingInfo (org.apache.cxf.service.model.BindingInfo)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1