Search in sources :

Example 26 with Destination

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

the class LocalTransportFactory method getDestination.

protected Destination getDestination(EndpointInfo ei, EndpointReferenceType reference, Bus bus) throws IOException {
    Destination d = null;
    String addr = reference.getAddress().getValue();
    if (addr == null) {
        AddressType tp = ei.getExtensor(AddressType.class);
        if (tp != null) {
            addr = tp.getLocation();
        }
    }
    if (addr == null) {
        addr = NULL_ADDRESS;
    }
    d = destinations.get(addr);
    if (d == null) {
        d = createDestination(ei, reference, bus);
        Destination tmpD = destinations.putIfAbsent(addr, d);
        if (tmpD != null) {
            d = tmpD;
        }
    }
    return d;
}
Also used : Destination(org.apache.cxf.transport.Destination) AddressType(org.apache.cxf.wsdl.http.AddressType)

Example 27 with Destination

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

the class WebSocketTransportFactoryTest method testGetDestination.

@Test
public void testGetDestination() throws Exception {
    Bus bus = BusFactory.getDefaultBus();
    EndpointInfo ei = new EndpointInfo();
    ei.setAddress("ws://localhost:8888/bar/foo");
    WebSocketTransportFactory factory = bus.getExtension(WebSocketTransportFactory.class);
    assertNotNull(factory);
    Destination dest = factory.getDestination(ei, bus);
    assertNotNull(dest);
}
Also used : Bus(org.apache.cxf.Bus) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) Destination(org.apache.cxf.transport.Destination) Test(org.junit.Test)

Example 28 with Destination

use of org.apache.cxf.transport.Destination 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 29 with Destination

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

the class DecoupledFaultHandler method handleFault.

// Ideally, this code will instead be executed as part of the Fault chain
// but at the moment PhaseInterceptorChain needs to be tricked that this is
// a two way request for a fault chain be invoked
public void handleFault(SoapMessage message) {
    if (!ContextUtils.isRequestor(message)) {
        Exchange exchange = message.getExchange();
        Message inMessage = exchange.getInMessage();
        final AddressingProperties maps = ContextUtils.retrieveMAPs(inMessage, false, false, true);
        if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) {
            // Just keep the wsa headers to remove the not understand headers
            if (exchange.getOutMessage() != null) {
                message = (SoapMessage) exchange.getOutMessage();
            }
            Iterator<Header> iterator = message.getHeaders().iterator();
            while (iterator.hasNext()) {
                Header header = iterator.next();
                if (!isWSAHeader(header)) {
                    iterator.remove();
                }
            }
            exchange.setOneWay(false);
            exchange.setOutMessage(message);
            // manually set the action
            message.put(ContextUtils.ACTION, WSA_ACTION);
            Destination destination = createDecoupledDestination(exchange, maps.getFaultTo());
            exchange.setDestination(destination);
        }
    }
}
Also used : Exchange(org.apache.cxf.message.Exchange) Destination(org.apache.cxf.transport.Destination) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) Message(org.apache.cxf.message.Message) Header(org.apache.cxf.headers.Header) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties)

Example 30 with Destination

use of org.apache.cxf.transport.Destination 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

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