Search in sources :

Example 1 with NullConduitSelector

use of org.apache.cxf.endpoint.NullConduitSelector in project cxf by apache.

the class SpringBeansTest method testClients.

@Test
public void testClients() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/jaxws/spring/clients.xml" });
    ClientHolderBean greeters = (ClientHolderBean) ctx.getBean("greeters");
    assertEquals(4, greeters.greeterCount());
    Object bean = ctx.getBean("client1.proxyFactory");
    assertNotNull(bean);
    Greeter greeter = (Greeter) ctx.getBean("client1");
    Greeter greeter2 = (Greeter) ctx.getBean("client1");
    assertNotNull(greeter);
    assertNotNull(greeter2);
    assertSame(greeter, greeter2);
    Client client = ClientProxy.getClient(greeter);
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
    List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : client.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    assertTrue(client.getEndpoint().getService().getDataBinding() instanceof SourceDataBinding);
    JaxWsProxyFactoryBean factory = (JaxWsProxyFactoryBean) ctx.getBean("wsdlLocation.proxyFactory");
    assertNotNull(factory);
    String wsdlLocation = factory.getWsdlLocation();
    assertEquals("We should get the right wsdl location", wsdlLocation, "wsdl/hello_world.wsdl");
    factory = (JaxWsProxyFactoryBean) ctx.getBean("inlineSoapBinding.proxyFactory");
    assertNotNull(factory);
    BindingConfiguration bc = factory.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    assertTrue("the soap configure should set isMtomEnabled to be true", sbc.isMtomEnabled());
    Greeter g1 = greeters.getGreet1();
    Greeter g2 = greeters.getGreet2();
    assertNotSame(g1, g2);
    ctx.close();
}
Also used : SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Soap12(org.apache.cxf.binding.soap.Soap12) Message(org.apache.cxf.message.Message) JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.hello_world_soap_http.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Example 2 with NullConduitSelector

use of org.apache.cxf.endpoint.NullConduitSelector in project cxf by apache.

the class ServiceImplTest method testServiceImpl.

@Test
public void testServiceImpl() throws Exception {
    SOAPService service = new SOAPService();
    Greeter proxy = service.getSoapPort();
    Client client = ClientProxy.getClient(proxy);
    assertEquals("bar", client.getEndpoint().get("foo"));
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
}
Also used : SOAPService(org.apache.hello_world_soap_http.SOAPService) Greeter(org.apache.hello_world_soap_http.Greeter) Client(org.apache.cxf.endpoint.Client) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) Test(org.junit.Test)

Example 3 with NullConduitSelector

use of org.apache.cxf.endpoint.NullConduitSelector 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);
            Exception exception = inMessage.getContent(Exception.class);
            // TODO:Look at how to refactor
            if (backChannel != null && !inMessage.getExchange().isOneWay() && ContextUtils.isFault(inMessage)) {
                // send the fault message to faultTo Endpoint
                exchange.setOutMessage(ContextUtils.createMessage(exchange));
                exchange.put(ConduitSelector.class, new NullConduitSelector());
                exchange.put("org.apache.cxf.http.no_io_exceptions", true);
                Destination destination = createDecoupledDestination(exchange, reference);
                exchange.setDestination(destination);
                if (ContextUtils.retrieveAsyncPostResponseDispatch(inMessage)) {
                    DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class);
                    if (in != null) {
                        in.cacheInput();
                    }
                    inMessage.getInterceptorChain().reset();
                    // cleanup pathinfo
                    if (inMessage.get(Message.PATH_INFO) != null) {
                        inMessage.remove(Message.PATH_INFO);
                    }
                    inMessage.getInterceptorChain().doIntercept(inMessage);
                }
                // send the partial response to requester
                partialResponse.put("forced.faultstring", "The server sent HTTP status code :" + inMessage.getExchange().get(Message.RESPONSE_CODE));
                partialResponse.setContent(Exception.class, exception);
                partialResponse.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, inMessage.get(Message.PROTOCOL_HEADERS));
                partialResponse.put(org.apache.cxf.message.Message.ENCODING, inMessage.get(Message.ENCODING));
                partialResponse.put(ContextUtils.ACTION, inMessage.get(ContextUtils.ACTION));
                partialResponse.put("javax.xml.ws.addressing.context.inbound", inMessage.get("javax.xml.ws.addressing.context.inbound"));
                partialResponse.put("javax.xml.ws.addressing.context.outbound", inMessage.get("javax.xml.ws.addressing.context.outbound"));
                exchange.setOutMessage(partialResponse);
                PhaseInterceptorChain newChian = ((PhaseInterceptorChain) inMessage.getInterceptorChain()).cloneChain();
                partialResponse.setInterceptorChain(newChian);
                exchange.setDestination(target);
                exchange.setOneWay(false);
                exchange.put(ConduitSelector.class, new PreexistingConduitSelector(backChannel, exchange.getEndpoint()));
                if (newChian != null && !newChian.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));
                }
                return;
            }
            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();
                    MessageObserver faultObserver = inMessage.getInterceptorChain().getFaultObserver();
                    if (null != inMessage.getContent(Exception.class) && null != faultObserver) {
                        // return the fault over the response fault channel
                        inMessage.getExchange().setOneWay(false);
                        faultObserver.onMessage(inMessage);
                        return;
                    }
                    // 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 (ContextUtils.retrieveAsyncPostResponseDispatch(inMessage) && !robust) {
                    // need to suck in all the data from the input stream as
                    // the transport might discard any data on the stream when this
                    // thread unwinds or when the empty response is sent back
                    DelegatingInputStream in = inMessage.getContent(DelegatingInputStream.class);
                    if (in != null) {
                        in.cacheInput();
                    }
                }
                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);
                if (ContextUtils.retrieveAsyncPostResponseDispatch(inMessage) && !robust) {
                    // cleanup pathinfo
                    if (inMessage.get(Message.PATH_INFO) != null) {
                        inMessage.remove(Message.PATH_INFO);
                    }
                    // pause dispatch on current thread ...
                    inMessage.getInterceptorChain().pause();
                    try {
                        // ... and resume on executor thread
                        getExecutor(inMessage).execute(new Runnable() {

                            public void run() {
                                inMessage.getInterceptorChain().resume();
                            }
                        });
                    } catch (RejectedExecutionException e) {
                        LOG.warning("Executor queue is full, use the caller thread." + "  Users can specify a larger executor queue to avoid this.");
                        // only block the thread if the prop is unset or set to false, otherwise let it go
                        if (!MessageUtils.getContextualBoolean(inMessage, "org.apache.cxf.oneway.rejected_execution_exception")) {
                            // the executor queue is full, so run the task in the caller thread
                            inMessage.getInterceptorChain().resume();
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.log(Level.WARNING, "SERVER_TRANSPORT_REBASE_FAILURE_MSG", e);
        }
    }
}
Also used : Destination(org.apache.cxf.transport.Destination) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Fault(org.apache.cxf.interceptor.Fault) WebFault(javax.xml.ws.WebFault) PreexistingConduitSelector(org.apache.cxf.endpoint.PreexistingConduitSelector) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) PhaseInterceptorChain(org.apache.cxf.phase.PhaseInterceptorChain) Conduit(org.apache.cxf.transport.Conduit) DelegatingInputStream(org.apache.cxf.io.DelegatingInputStream)

Example 4 with NullConduitSelector

use of org.apache.cxf.endpoint.NullConduitSelector 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)

Example 5 with NullConduitSelector

use of org.apache.cxf.endpoint.NullConduitSelector in project cxf by apache.

the class SpringBeansTest method testClients.

@Test
public void testClients() throws Exception {
    AbstractFactoryBeanDefinitionParser.setFactoriesAreAbstract(false);
    ctx = new ClassPathXmlApplicationContext(new String[] { "/org/apache/cxf/frontend/spring/clients.xml" });
    Object bean = ctx.getBean("client1.proxyFactory");
    assertNotNull(bean);
    ClientProxyFactoryBean cpfbean = (ClientProxyFactoryBean) bean;
    BindingConfiguration bc = cpfbean.getBindingConfig();
    assertTrue(bc instanceof SoapBindingConfiguration);
    SoapBindingConfiguration sbc = (SoapBindingConfiguration) bc;
    assertTrue(sbc.getVersion() instanceof Soap12);
    HelloService greeter = (HelloService) ctx.getBean("client1");
    assertNotNull(greeter);
    Client client = ClientProxy.getClient(greeter);
    assertNotNull("expected ConduitSelector", client.getConduitSelector());
    assertTrue("unexpected ConduitSelector", client.getConduitSelector() instanceof NullConduitSelector);
    List<Interceptor<? extends Message>> inInterceptors = client.getInInterceptors();
    boolean saaj = false;
    boolean logging = false;
    for (Interceptor<? extends Message> i : inInterceptors) {
        if (i instanceof SAAJInInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingInInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    saaj = false;
    logging = false;
    for (Interceptor<?> i : client.getOutInterceptors()) {
        if (i instanceof SAAJOutInterceptor) {
            saaj = true;
        } else if (i instanceof LoggingOutInterceptor) {
            logging = true;
        }
    }
    assertTrue(saaj);
    assertTrue(logging);
    ClientProxyFactoryBean clientProxyFactoryBean = (ClientProxyFactoryBean) ctx.getBean("client2.proxyFactory");
    assertNotNull(clientProxyFactoryBean);
    assertEquals("get the wrong transportId", clientProxyFactoryBean.getTransportId(), "http://cxf.apache.org/transports/local");
    assertEquals("get the wrong bindingId", clientProxyFactoryBean.getBindingId(), "http://cxf.apache.org/bindings/xformat");
    greeter = (HelloService) ctx.getBean("client2");
    assertNotNull(greeter);
    greeter = (HelloService) ctx.getBean("client3");
    assertNotNull(greeter);
    client = ClientProxy.getClient(greeter);
    EndpointInfo epi = client.getEndpoint().getEndpointInfo();
    AuthorizationPolicy ap = epi.getExtensor(AuthorizationPolicy.class);
    assertNotNull("The AuthorizationPolicy instance should not be null", ap);
    assertEquals("Get the wrong username", ap.getUserName(), "testUser");
    assertEquals("Get the wrong password", ap.getPassword(), "password");
}
Also used : Soap12(org.apache.cxf.binding.soap.Soap12) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) Message(org.apache.cxf.message.Message) HelloService(org.apache.cxf.service.factory.HelloService) NullConduitSelector(org.apache.cxf.endpoint.NullConduitSelector) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) Client(org.apache.cxf.endpoint.Client) SAAJOutInterceptor(org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor) SAAJInInterceptor(org.apache.cxf.binding.soap.saaj.SAAJInInterceptor) Interceptor(org.apache.cxf.interceptor.Interceptor) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) BindingConfiguration(org.apache.cxf.binding.BindingConfiguration) SoapBindingConfiguration(org.apache.cxf.binding.soap.SoapBindingConfiguration) Test(org.junit.Test)

Aggregations

NullConduitSelector (org.apache.cxf.endpoint.NullConduitSelector)5 Message (org.apache.cxf.message.Message)4 Client (org.apache.cxf.endpoint.Client)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 BindingConfiguration (org.apache.cxf.binding.BindingConfiguration)2 Soap12 (org.apache.cxf.binding.soap.Soap12)2 SoapBindingConfiguration (org.apache.cxf.binding.soap.SoapBindingConfiguration)2 SAAJInInterceptor (org.apache.cxf.binding.soap.saaj.SAAJInInterceptor)2 SAAJOutInterceptor (org.apache.cxf.binding.soap.saaj.SAAJOutInterceptor)2 PreexistingConduitSelector (org.apache.cxf.endpoint.PreexistingConduitSelector)2 LoggingInInterceptor (org.apache.cxf.ext.logging.LoggingInInterceptor)2 LoggingOutInterceptor (org.apache.cxf.ext.logging.LoggingOutInterceptor)2 Fault (org.apache.cxf.interceptor.Fault)2 Interceptor (org.apache.cxf.interceptor.Interceptor)2 InterceptorChain (org.apache.cxf.interceptor.InterceptorChain)2 Exchange (org.apache.cxf.message.Exchange)2 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)2 Conduit (org.apache.cxf.transport.Conduit)2 Destination (org.apache.cxf.transport.Destination)2