Search in sources :

Example 71 with Conduit

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

the class Proxy method invoke.

Object invoke(OperationInfo oi, ProtocolVariation protocol, Object[] params, Map<String, Object> context, Exchange exchange, Level exceptionLevel) throws RMException {
    if (LOG.isLoggable(Level.INFO)) {
        LOG.log(Level.INFO, "Sending out-of-band RM protocol message {0}.", oi == null ? null : oi.getName());
    }
    RMManager manager = reliableEndpoint.getManager();
    Bus bus = manager.getBus();
    Endpoint endpoint = reliableEndpoint.getEndpoint(protocol);
    BindingInfo bi = reliableEndpoint.getBindingInfo(protocol);
    Conduit c = reliableEndpoint.getConduit();
    Client client = null;
    if (params.length > 0 && params[0] instanceof DestinationSequence) {
        EndpointReferenceType acksTo = ((DestinationSequence) params[0]).getAcksTo();
        String acksAddress = acksTo.getAddress().getValue();
        AttributedURIType attrURIType = new AttributedURIType();
        attrURIType.setValue(acksAddress);
        EndpointReferenceType acks = new EndpointReferenceType();
        acks.setAddress(attrURIType);
        client = createClient(bus, endpoint, protocol, c, acks);
        params = new Object[] {};
    } else {
        EndpointReferenceType replyTo = reliableEndpoint.getReplyTo();
        client = createClient(bus, endpoint, protocol, c, replyTo);
    }
    BindingOperationInfo boi = bi.getOperation(oi);
    try {
        if (context != null) {
            client.getRequestContext().putAll(context);
        }
        Object[] result = client.invoke(boi, params, context, exchange);
        if (result != null && result.length > 0) {
            return result[0];
        }
    } catch (Exception ex) {
        org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("SEND_PROTOCOL_MSG_FAILED_EXC", LOG, oi == null ? null : oi.getName());
        LOG.log(exceptionLevel, msg.toString(), ex);
        throw new RMException(msg, ex);
    }
    return null;
}
Also used : Bus(org.apache.cxf.Bus) BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.message.Message) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) IOException(java.io.IOException) Endpoint(org.apache.cxf.endpoint.Endpoint) Conduit(org.apache.cxf.transport.Conduit) BindingInfo(org.apache.cxf.service.model.BindingInfo) Client(org.apache.cxf.endpoint.Client)

Example 72 with Conduit

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

the class LocalDestinationTest method testStatusCodeSetAfterClose.

/**
 * Tests if the status code is available after closing the destination so that it can be logged.
 * Note that this test verifies the current approach of setting the status code if it is not set earlier.
 *
 * @throws Exception
 */
@Test
public void testStatusCodeSetAfterClose() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    LocalTransportFactory factory = new LocalTransportFactory();
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress("http://localhost/test");
    LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
    MessageImpl m = new MessageImpl();
    Conduit conduit = factory.getConduit(ei, bus);
    m.put(LocalConduit.IN_CONDUIT, conduit);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    m.setExchange(ex);
    Integer code = (Integer) m.get(Message.RESPONSE_CODE);
    assertNull(code);
    Conduit backChannel = d.getBackChannel(m);
    backChannel.close(m);
    code = (Integer) m.get(Message.RESPONSE_CODE);
    assertNotNull(code);
    assertEquals(200, code.intValue());
}
Also used : Exchange(org.apache.cxf.message.Exchange) Bus(org.apache.cxf.Bus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Test(org.junit.Test)

Example 73 with Conduit

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

the class LocalTransportFactoryTest method testInvocation.

private void testInvocation(boolean isDirectDispatch) throws Exception {
    // Need to create a DefaultBus
    Bus bus = BusFactory.getDefaultBus();
    LocalTransportFactory factory = new LocalTransportFactory();
    EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
    ei.setAddress("http://localhost/test");
    LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
    d.setMessageObserver(new EchoObserver());
    // Set up a listener for the response
    Conduit conduit = factory.getConduit(ei, bus);
    TestMessageObserver obs = new TestMessageObserver();
    conduit.setMessageObserver(obs);
    MessageImpl m = new MessageImpl();
    if (isDirectDispatch) {
        m.put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
    }
    m.setDestination(d);
    Exchange ex = new ExchangeImpl();
    ex.put(Bus.class, bus);
    m.setExchange(ex);
    conduit.prepare(m);
    OutputStream out = m.getContent(OutputStream.class);
    StringBuilder builder = new StringBuilder();
    for (int x = 0; x < 1000; x++) {
        builder.append("hello");
    }
    out.write(builder.toString().getBytes());
    out.close();
    conduit.close(m);
    assertEquals(builder.toString(), obs.getResponseStream().toString());
}
Also used : Bus(org.apache.cxf.Bus) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Conduit(org.apache.cxf.transport.Conduit) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Example 74 with Conduit

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

the class MAPAggregatorImpl method addRoleSpecific.

/**
 * Add MAPs which are specific to the requestor or responder role.
 *
 * @param maps the MAPs being assembled
 * @param message the current message
 * @param isRequestor true iff the current messaging role is that of
 * requestor
 * @param isFault true if a fault is being mediated
 */
private void addRoleSpecific(AddressingProperties maps, Message message, boolean isRequestor, boolean isFault) {
    if (isRequestor) {
        Exchange exchange = message.getExchange();
        // add request-specific MAPs
        boolean isOneway = exchange.isOneWay();
        boolean isOutbound = ContextUtils.isOutbound(message);
        // To
        if (maps.getTo() == null) {
            Conduit conduit = null;
            if (isOutbound) {
                conduit = ContextUtils.getConduit(null, message);
            }
            String s = (String) message.get(Message.ENDPOINT_ADDRESS);
            EndpointReferenceType reference = conduit != null ? conduit.getTarget() : ContextUtils.getNoneEndpointReference();
            if (conduit != null && !StringUtils.isEmpty(s) && !reference.getAddress().getValue().equals(s)) {
                EndpointReferenceType ref = new EndpointReferenceType();
                AttributedURIType tp = new AttributedURIType();
                tp.setValue(s);
                ref.setAddress(tp);
                ref.setMetadata(reference.getMetadata());
                ref.setReferenceParameters(reference.getReferenceParameters());
                ref.getOtherAttributes().putAll(reference.getOtherAttributes());
                reference = ref;
            }
            maps.setTo(reference);
        }
        // ReplyTo, set if null in MAPs or if set to a generic address
        // (anonymous or none) that may not be appropriate for the
        // current invocation
        EndpointReferenceType replyTo = maps.getReplyTo();
        if (ContextUtils.isGenericAddress(replyTo)) {
            replyTo = getReplyTo(message, replyTo);
            if (replyTo == null || (isOneway && (replyTo == null || replyTo.getAddress() == null || !Names.WSA_NONE_ADDRESS.equals(replyTo.getAddress().getValue())))) {
                AttributedURIType address = ContextUtils.getAttributedURI(isOneway ? Names.WSA_NONE_ADDRESS : Names.WSA_ANONYMOUS_ADDRESS);
                replyTo = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
                replyTo.setAddress(address);
            }
            maps.setReplyTo(replyTo);
        }
        // FaultTo
        if (maps.getFaultTo() == null) {
            maps.setFaultTo(maps.getReplyTo());
        } else if (maps.getFaultTo().getAddress() == null) {
            maps.setFaultTo(null);
        }
    } else {
        // add response-specific MAPs
        AddressingProperties inMAPs = getMAPs(message, false, false);
        maps.exposeAs(inMAPs.getNamespaceURI());
        // on the fault status of the response)
        if (isFault && inMAPs.getFaultTo() != null) {
            maps.setTo(inMAPs.getFaultTo());
        } else if (maps.getTo() == null && inMAPs.getReplyTo() != null) {
            maps.setTo(inMAPs.getReplyTo());
        }
        // RelatesTo taken from MessageID in incoming MAPs
        if (inMAPs.getMessageID() != null && !Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
            String inMessageID = inMAPs.getMessageID().getValue();
            maps.setRelatesTo(ContextUtils.getRelatesTo(inMessageID));
        } else {
            maps.setRelatesTo(ContextUtils.getRelatesTo(Names.WSA_UNSPECIFIED_RELATIONSHIP));
        }
        // fallback fault action
        if (isFault && maps.getAction() == null) {
            maps.setAction(ContextUtils.getAttributedURI(Names.WSA_DEFAULT_FAULT_ACTION));
        }
        if (isFault && !ContextUtils.isGenericAddress(inMAPs.getFaultTo())) {
            Message m = message.getExchange().getInFaultMessage();
            if (m == null) {
                m = message;
            }
            InternalContextUtils.rebaseResponse(inMAPs.getFaultTo(), inMAPs, m);
            Destination destination = InternalContextUtils.createDecoupledDestination(m.getExchange(), inMAPs.getFaultTo());
            m.getExchange().setDestination(destination);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Destination(org.apache.cxf.transport.Destination) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 75 with Conduit

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

the class MAPAggregatorTest method setUpRebase.

private void setUpRebase(Message message, Exchange exchange, Endpoint endpoint) throws Exception {
    setUpMessageProperty(message, "org.apache.cxf.ws.addressing.partial.response.sent", Boolean.FALSE);
    Binding binding = control.createMock(Binding.class);
    endpoint.getBinding();
    EasyMock.expectLastCall().andReturn(binding).anyTimes();
    Message partialResponse = getMessage();
    binding.createMessage(EasyMock.isA(Message.class));
    EasyMock.expectLastCall().andReturn(partialResponse);
    Destination target = control.createMock(Destination.class);
    setUpMessageDestination(message, target);
    Conduit backChannel = control.createMock(Conduit.class);
    target.getBackChannel(EasyMock.eq(message));
    EasyMock.expectLastCall().andReturn(backChannel);
// REVISIT test interceptor chain setup & send
}
Also used : Binding(org.apache.cxf.binding.Binding) Destination(org.apache.cxf.transport.Destination) Message(org.apache.cxf.message.Message) Conduit(org.apache.cxf.transport.Conduit)

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