Search in sources :

Example 21 with Destination

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

the class SoapBindingSelectionTest method testMultipleSoapBindings.

@Test
public void testMultipleSoapBindings() throws Exception {
    ServerFactoryBean svrBean1 = new ServerFactoryBean();
    svrBean1.setAddress("http://localhost/Hello");
    svrBean1.setServiceClass(HelloService.class);
    svrBean1.setServiceBean(new HelloServiceImpl());
    svrBean1.setBus(getBus());
    svrBean1.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {

        public void handleMessage(Message message) throws Fault {
            service1Invoked = true;
        }
    });
    svrBean1.create();
    ServerFactoryBean svrBean2 = new ServerFactoryBean();
    svrBean2.setAddress("http://localhost/Hello");
    svrBean2.setServiceClass(HelloService.class);
    svrBean2.setServiceBean(new HelloServiceImpl());
    svrBean2.setBus(getBus());
    svrBean2.getInInterceptors().add(new AbstractPhaseInterceptor<Message>(Phase.USER_LOGICAL) {

        public void handleMessage(Message message) throws Fault {
            service2Invoked = true;
        }
    });
    SoapBindingConfiguration config = new SoapBindingConfiguration();
    config.setVersion(Soap12.getInstance());
    svrBean2.setBindingConfig(config);
    ServerImpl server2 = (ServerImpl) svrBean2.create();
    Destination d = server2.getDestination();
    MessageObserver mo = d.getMessageObserver();
    assertTrue(mo instanceof MultipleEndpointObserver);
    MultipleEndpointObserver meo = (MultipleEndpointObserver) mo;
    assertEquals(2, meo.getEndpoints().size());
    Node nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap11.xml");
    assertEquals("http://schemas.xmlsoap.org/soap/envelope/", getNs(nd));
    assertTrue(service1Invoked);
    assertFalse(service2Invoked);
    service1Invoked = false;
    nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
    assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
    assertFalse(service1Invoked);
    assertTrue(service2Invoked);
    server2.stop();
    server2.start();
    nd = invoke("http://localhost/Hello", LocalTransportFactory.TRANSPORT_ID, "soap12.xml");
    assertEquals("http://www.w3.org/2003/05/soap-envelope", getNs(nd));
    assertFalse(service1Invoked);
    assertTrue(service2Invoked);
}
Also used : Destination(org.apache.cxf.transport.Destination) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) ServerImpl(org.apache.cxf.endpoint.ServerImpl) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) MultipleEndpointObserver(org.apache.cxf.transport.MultipleEndpointObserver) Node(org.w3c.dom.Node) ServerFactoryBean(org.apache.cxf.frontend.ServerFactoryBean) HelloServiceImpl(org.apache.cxf.service.factory.HelloServiceImpl) Fault(org.apache.cxf.interceptor.Fault) Test(org.junit.Test) AbstractSimpleFrontendTest(org.apache.cxf.service.factory.AbstractSimpleFrontendTest)

Example 22 with Destination

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

the class HttpUtils method getEndpointAddress.

public static String getEndpointAddress(Message m) {
    String address = null;
    Destination d = m.getExchange().getDestination();
    if (d != null) {
        if (d instanceof AbstractHTTPDestination) {
            EndpointInfo ei = ((AbstractHTTPDestination) d).getEndpointInfo();
            HttpServletRequest request = (HttpServletRequest) m.get(AbstractHTTPDestination.HTTP_REQUEST);
            Object property = request != null ? request.getAttribute("org.apache.cxf.transport.endpoint.address") : null;
            address = property != null ? property.toString() : ei.getAddress();
        } else {
            address = m.containsKey(Message.BASE_PATH) ? (String) m.get(Message.BASE_PATH) : d.getAddress().getAddress().getValue();
        }
    } else {
        address = (String) m.get(Message.ENDPOINT_ADDRESS);
    }
    if (address.startsWith("http") && address.endsWith("//")) {
        address = address.substring(0, address.length() - 1);
    }
    return address;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Destination(org.apache.cxf.transport.Destination) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination)

Example 23 with Destination

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

the class HolderTest method testClient.

@Test
public void testClient() throws Exception {
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress(address);
    Destination d = localTransport.getDestination(ei, bus);
    d.setMessageObserver(new MessageReplayObserver("/org/apache/cxf/jaxws/holder/echoResponse.xml"));
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.getClientFactoryBean().setServiceClass(HolderService.class);
    factory.getClientFactoryBean().setBus(getBus());
    factory.getClientFactoryBean().setAddress(address);
    HolderService h = (HolderService) factory.create();
    Holder<String> holder = new Holder<String>();
    assertEquals("one", h.echo("one", "two", holder));
    assertEquals("two", holder.value);
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) Holder(javax.xml.ws.Holder) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) MessageReplayObserver(org.apache.cxf.jaxws.MessageReplayObserver) Test(org.junit.Test) AbstractJaxWsTest(org.apache.cxf.jaxws.AbstractJaxWsTest)

Example 24 with Destination

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

the class NegotiationUtils method recalcEffectivePolicy.

static void recalcEffectivePolicy(SoapMessage message, String namespace, Policy policy, Invoker invoker, boolean secConv) {
    Exchange ex = message.getExchange();
    Bus bus = ex.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }
    Destination destination = ex.getDestination();
    try {
        Endpoint endpoint = message.getExchange().getEndpoint();
        TokenStore store = TokenStoreUtils.getTokenStore(message);
        if (secConv) {
            endpoint = STSUtils.createSCEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy);
        } else {
            endpoint = STSUtils.createSTSEndpoint(bus, namespace, endpoint.getEndpointInfo().getTransportId(), destination.getAddress().getAddress().getValue(), message.getVersion().getBindingId(), policy, null);
        }
        endpoint.getEndpointInfo().setProperty(TokenStore.class.getName(), store);
        message.getExchange().put(TokenStore.class.getName(), store);
        EndpointPolicy ep = pe.getServerEndpointPolicy(endpoint.getEndpointInfo(), destination, message);
        List<Interceptor<? extends Message>> interceptors = ep.getInterceptors(message);
        message.getInterceptorChain().add(interceptors);
        Collection<Assertion> assertions = ep.getVocabulary(message);
        if (null != assertions) {
            message.put(AssertionInfoMap.class, new AssertionInfoMap(assertions));
        }
        endpoint.getService().setInvoker(invoker);
        ex.put(Endpoint.class, endpoint);
        ex.put(Service.class, endpoint.getService());
        ex.put(org.apache.cxf.binding.Binding.class, endpoint.getBinding());
        ex.remove(BindingOperationInfo.class);
        message.put(MAPAggregator.ACTION_VERIFIED, Boolean.TRUE);
    } catch (Exception exc) {
        throw new Fault(exc);
    }
}
Also used : Bus(org.apache.cxf.Bus) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) PrimitiveAssertion(org.apache.cxf.ws.policy.builder.primitive.PrimitiveAssertion) Assertion(org.apache.neethi.Assertion) PolicyEngine(org.apache.cxf.ws.policy.PolicyEngine) Fault(org.apache.cxf.interceptor.Fault) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap) Exchange(org.apache.cxf.message.Exchange) EndpointPolicy(org.apache.cxf.ws.policy.EndpointPolicy) Endpoint(org.apache.cxf.endpoint.Endpoint) TokenStore(org.apache.cxf.ws.security.tokenstore.TokenStore) Interceptor(org.apache.cxf.interceptor.Interceptor)

Example 25 with Destination

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

the class InternalContextUtils method rebaseResponse.

/**
 * Rebase response on replyTo
 *
 * @param reference the replyTo reference
 * @param inMAPs the inbound MAPs
 * @param inMessage the current message
 */
// CHECKSTYLE:OFF Max executable statement count limitation
public static void rebaseResponse(EndpointReferenceType reference, AddressingProperties inMAPs, final Message inMessage) {
    String namespaceURI = inMAPs.getNamespaceURI();
    if (!ContextUtils.retrievePartialResponseSent(inMessage)) {
        ContextUtils.storePartialResponseSent(inMessage);
        Exchange exchange = inMessage.getExchange();
        Message fullResponse = exchange.getOutMessage();
        Message partialResponse = ContextUtils.createMessage(exchange);
        ensurePartialResponseMAPs(partialResponse, namespaceURI);
        // ensure the inbound MAPs are available in the partial response
        // message (used to determine relatesTo etc.)
        ContextUtils.propogateReceivedMAPs(inMAPs, partialResponse);
        Destination target = inMessage.getDestination();
        if (target == null) {
            return;
        }
        try {
            if (reference == null) {
                reference = ContextUtils.getNoneEndpointReference();
            }
            Conduit backChannel = target.getBackChannel(inMessage);
            if (backChannel != null) {
                partialResponse.put(Message.PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                partialResponse.put(Message.EMPTY_PARTIAL_RESPONSE_MESSAGE, Boolean.TRUE);
                boolean robust = MessageUtils.getContextualBoolean(inMessage, Message.ROBUST_ONEWAY, false);
                if (robust) {
                    BindingOperationInfo boi = exchange.getBindingOperationInfo();
                    // insert the executor in the exchange to fool the OneWayProcessorInterceptor
                    exchange.put(Executor.class, getExecutor(inMessage));
                    // pause dispatch on current thread and resume...
                    inMessage.getInterceptorChain().pause();
                    inMessage.getInterceptorChain().resume();
                    // restore the BOI for the partial response handling
                    exchange.put(BindingOperationInfo.class, boi);
                }
                // set up interceptor chains and send message
                InterceptorChain chain = fullResponse != null ? fullResponse.getInterceptorChain() : OutgoingChainInterceptor.getOutInterceptorChain(exchange);
                exchange.setOutMessage(partialResponse);
                partialResponse.setInterceptorChain(chain);
                exchange.put(ConduitSelector.class, new PreexistingConduitSelector(backChannel, exchange.getEndpoint()));
                if (chain != null && !chain.doIntercept(partialResponse) && partialResponse.getContent(Exception.class) != null) {
                    if (partialResponse.getContent(Exception.class) instanceof Fault) {
                        throw (Fault) partialResponse.getContent(Exception.class);
                    }
                    throw new Fault(partialResponse.getContent(Exception.class));
                }
                if (chain != null) {
                    chain.reset();
                }
                exchange.put(ConduitSelector.class, new NullConduitSelector());
                if (fullResponse == null) {
                    fullResponse = ContextUtils.createMessage(exchange);
                }
                exchange.setOutMessage(fullResponse);
                Destination destination = createDecoupledDestination(exchange, reference);
                exchange.setDestination(destination);
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Destination(org.apache.cxf.transport.Destination) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) Fault(org.apache.cxf.interceptor.Fault) PreexistingConduitSelector(org.apache.cxf.endpoint.PreexistingConduitSelector) IOException(java.io.IOException) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector)

Aggregations

Destination (org.apache.cxf.transport.Destination)41 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)25 Test (org.junit.Test)14 Message (org.apache.cxf.message.Message)13 QName (javax.xml.namespace.QName)12 Bus (org.apache.cxf.Bus)12 Exchange (org.apache.cxf.message.Exchange)12 Conduit (org.apache.cxf.transport.Conduit)11 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)8 AbstractHTTPDestination (org.apache.cxf.transport.http.AbstractHTTPDestination)8 Endpoint (org.apache.cxf.endpoint.Endpoint)7 DestinationFactory (org.apache.cxf.transport.DestinationFactory)7 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)7 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)6 HTTPTransportFactory (org.apache.cxf.transport.http.HTTPTransportFactory)6 MessageObserver (org.apache.cxf.transport.MessageObserver)5 IOException (java.io.IOException)4 Fault (org.apache.cxf.interceptor.Fault)4 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)4 Policy (org.apache.neethi.Policy)4