Search in sources :

Example 21 with Conduit

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

the class PolicyEngineTest method testEndpointPolicyWithEqualPolicies.

@Test
public void testEndpointPolicyWithEqualPolicies() throws Exception {
    engine = new PolicyEngineImpl();
    EndpointInfo ei = createMockEndpointInfo();
    ServiceInfo si = control.createMock(ServiceInfo.class);
    ei.setService(si);
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(null).times(2);
    EndpointPolicyImpl epi = control.createMock(EndpointPolicyImpl.class);
    control.replay();
    engine.setServerEndpointPolicy(ei, epi);
    engine.setClientEndpointPolicy(ei, epi);
    assertSame(epi, engine.getClientEndpointPolicy(ei, (Conduit) null, msg));
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
    control.reset();
    ei.setService(si);
    Policy p = new Policy();
    si.getExtensor(Policy.class);
    EasyMock.expectLastCall().andReturn(p).times(2);
    epi.getPolicy();
    EasyMock.expectLastCall().andReturn(p).times(2);
    control.replay();
    assertSame(epi, engine.getServerEndpointPolicy(ei, (Destination) null, msg));
}
Also used : ServiceInfo(org.apache.cxf.service.model.ServiceInfo) Policy(org.apache.neethi.Policy) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Example 22 with Conduit

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

the class JMSConfigFeature method initialize.

@Override
public void initialize(Client client, Bus bus) {
    checkJmsConfig();
    Conduit conduit = client.getConduit();
    if (!(conduit instanceof JMSConduit)) {
        throw new ConfigurationException(new Message("JMSCONFIGFEATURE_ONLY_JMS", LOG));
    }
    JMSConduit jmsConduit = (JMSConduit) conduit;
    jmsConduit.setJmsConfig(jmsConfig);
    super.initialize(client, bus);
}
Also used : Message(org.apache.cxf.common.i18n.Message) ConfigurationException(org.apache.cxf.configuration.ConfigurationException) Conduit(org.apache.cxf.transport.Conduit)

Example 23 with Conduit

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

the class JMSDestinationTest method testRoundTripDestination.

private Message testRoundTripDestination(boolean createSecurityContext) throws Exception {
    EndpointInfo ei = setupServiceInfo("HelloWorldService", "HelloWorldPort");
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    conduit.getJmsConfig().setCreateSecurityContext(createSecurityContext);
    final Message outMessage = new MessageImpl();
    setupMessageHeader(outMessage, null);
    final JMSDestination destination = setupJMSDestination(ei);
    // set up MessageObserver for handling the conduit message
    MessageObserver observer = new MessageObserver() {

        public void onMessage(Message m) {
            Exchange exchange = new ExchangeImpl();
            exchange.setInMessage(m);
            m.setExchange(exchange);
            verifyReceivedMessage(m);
            verifyHeaders(m, outMessage);
            // setup the message for
            Conduit backConduit;
            try {
                backConduit = destination.getBackChannel(m);
                // wait for the message to be got from the conduit
                Message replyMessage = new MessageImpl();
                sendOneWayMessage(backConduit, replyMessage);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    destination.setMessageObserver(observer);
    sendMessageSync(conduit, outMessage);
    // wait for the message to be got from the destination,
    // create the thread to handler the Destination incoming message
    waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    // wait for a while for the jms session recycling
    inMessage = null;
    // Send a second message to check for an issue
    // Where the session was closed the second time
    sendMessageSync(conduit, outMessage);
    waitForReceiveInMessage();
    verifyReceivedMessage(inMessage);
    // wait for a while for the jms session recycling
    Thread.sleep(1000);
    conduit.close();
    destination.shutdown();
    return inMessage;
}
Also used : Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) MessageObserver(org.apache.cxf.transport.MessageObserver) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) IOException(java.io.IOException) InvalidClientIDException(javax.jms.InvalidClientIDException) JMSException(javax.jms.JMSException)

Example 24 with Conduit

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

the class CXFAuthenticator method getPasswordAuthentication.

protected PasswordAuthentication getPasswordAuthentication() {
    PasswordAuthentication auth = null;
    Message m = PhaseInterceptorChain.getCurrentMessage();
    if (m != null) {
        Exchange exchange = m.getExchange();
        Conduit conduit = exchange.getConduit(m);
        if (conduit instanceof HTTPConduit) {
            HTTPConduit httpConduit = (HTTPConduit) conduit;
            if (getRequestorType() == RequestorType.PROXY && httpConduit.getProxyAuthorization() != null) {
                String un = httpConduit.getProxyAuthorization().getUserName();
                String pwd = httpConduit.getProxyAuthorization().getPassword();
                if (un != null && pwd != null) {
                    auth = new PasswordAuthentication(un, pwd.toCharArray());
                }
            } else if (getRequestorType() == RequestorType.SERVER && httpConduit.getAuthorization() != null) {
                if ("basic".equals(getRequestingScheme()) || "digest".equals(getRequestingScheme())) {
                    return null;
                }
                String un = httpConduit.getAuthorization().getUserName();
                String pwd = httpConduit.getAuthorization().getPassword();
                if (un != null && pwd != null) {
                    auth = new PasswordAuthentication(un, pwd.toCharArray());
                }
            }
        }
    }
    // this HTTP call has therefore not been generated by CXF
    return auth;
}
Also used : Exchange(org.apache.cxf.message.Exchange) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) PasswordAuthentication(java.net.PasswordAuthentication)

Example 25 with Conduit

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

the class UndertowHTTPDestinationTest method testGetAnonBackChannel.

@Test
public void testGetAnonBackChannel() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    destination.doService(request, response);
    setUpInMessage();
    Conduit backChannel = destination.getBackChannel(inMessage);
    assertNotNull("expected back channel", backChannel);
    assertEquals("unexpected target", EndpointReferenceUtils.ANONYMOUS_ADDRESS, backChannel.getTarget().getAddress().getValue());
}
Also used : Conduit(org.apache.cxf.transport.Conduit) Test(org.junit.Test)

Aggregations

Conduit (org.apache.cxf.transport.Conduit)83 Test (org.junit.Test)36 Message (org.apache.cxf.message.Message)35 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)30 Exchange (org.apache.cxf.message.Exchange)28 IOException (java.io.IOException)18 MessageImpl (org.apache.cxf.message.MessageImpl)17 Endpoint (org.apache.cxf.endpoint.Endpoint)16 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)13 MessageObserver (org.apache.cxf.transport.MessageObserver)12 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)12 OutputStream (java.io.OutputStream)11 Bus (org.apache.cxf.Bus)11 Destination (org.apache.cxf.transport.Destination)11 ConduitInitiator (org.apache.cxf.transport.ConduitInitiator)10 InputStream (java.io.InputStream)9 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)9 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6