Java Code Examples for org.apache.cxf.message.Exchange#setDestination()

The following examples show how to use org.apache.cxf.message.Exchange#setDestination() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UriInfoImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message mockMessage(String baseAddress, String pathInfo,
                            String query, String fragment) {
    Message m = new MessageImpl();
    control.reset();
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    ServletDestination d = control.createMock(ServletDestination.class);
    e.setDestination(d);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    d.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(epr).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    control.replay();
    return m;
}
 
Example 2
Source File: HttpUtilsTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void doTestGetBaseAddress(String baseURI, String expected) {
    Message m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    Destination dest = EasyMock.createMock(Destination.class);
    exchange.setDestination(dest);
    m.put(Message.BASE_PATH, baseURI);
    String address = HttpUtils.getBaseAddress(m);
    assertEquals(expected, address);
}
 
Example 3
Source File: RequestPreprocessorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message mockMessage(String baseAddress,
                            String pathInfo,
                            String query,
                            String method,
                            String methodHeader) {
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    m.put("org.apache.cxf.endpoint.private", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    control.reset();
    Endpoint endp = control.mock(Endpoint.class);
    e.put(Endpoint.class, endp);
    EasyMock.expect(endp.isEmpty()).andReturn(true).anyTimes();
    EasyMock.expect(endp.get(ServerProviderFactory.class.getName())).andReturn(ServerProviderFactory.getInstance())
            .anyTimes();
    ServletDestination d = control.createMock(ServletDestination.class);
    e.setDestination(d);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    EasyMock.expect(d.getEndpointInfo()).andReturn(epr).anyTimes();
    EasyMock.expect(endp.getEndpointInfo()).andReturn(epr).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    m.put(Message.HTTP_REQUEST_METHOD, method);
    Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
    if (methodHeader != null) {
        headers.put("X-HTTP-Method-Override", Collections.singletonList(methodHeader));
    }
    m.put(Message.PROTOCOL_HEADERS, headers);
    BindingInfo bi = control.createMock(BindingInfo.class);
    epr.setBinding(bi);
    EasyMock.expect(bi.getProperties()).andReturn(Collections.emptyMap()).anyTimes();

    control.replay();
    return m;
}
 
Example 4
Source File: RMCaptureOutInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setTerminateSequence(Message msg, Identifier identifier, ProtocolVariation protocol)
    throws RMException {
    TerminateSequenceType ts = new TerminateSequenceType();
    ts.setIdentifier(identifier);
    MessageContentsList contents =
        new MessageContentsList(new Object[]{protocol.getCodec().convertToSend(ts)});
    msg.setContent(List.class, contents);

    // create a new exchange for this output-only exchange
    Exchange newex = new ExchangeImpl();
    Exchange oldex = msg.getExchange();

    newex.put(Bus.class, oldex.getBus());
    newex.put(Endpoint.class, oldex.getEndpoint());
    newex.put(Service.class, oldex.getEndpoint().getService());
    newex.put(Binding.class, oldex.getEndpoint().getBinding());
    newex.setConduit(oldex.getConduit(msg));
    newex.setDestination(oldex.getDestination());

    //Setup the BindingOperationInfo
    RMEndpoint rmep = getManager().getReliableEndpoint(msg);
    OperationInfo oi = rmep.getEndpoint(protocol).getEndpointInfo().getService().getInterface()
        .getOperation(protocol.getConstants().getTerminateSequenceAnonymousOperationName());
    BindingInfo bi = rmep.getBindingInfo(protocol);
    BindingOperationInfo boi = bi.getOperation(oi);

    newex.put(BindingInfo.class, bi);
    newex.put(BindingOperationInfo.class, boi);

    msg.setExchange(newex);
    newex.setOutMessage(msg);
}
 
Example 5
Source File: RMInInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void handleFault(Message message) {
    message.put(MAPAggregator.class.getName(), true);
    if (RMContextUtils.getProtocolVariation(message) != null) {
        if (PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
            // revert the delivering entry from the destination sequence
            try {
                Destination destination = getManager().getDestination(message);
                if (destination != null) {
                    destination.releaseDeliveringStatus(message);
                }
            } catch (RMException e) {
                LOG.log(Level.WARNING, "Failed to revert the delivering status");
            }
        } else if (isRedeliveryEnabled(message) && RMContextUtils.isServerSide(message)
                   && isApplicationMessage(message) && hasValidSequence(message)) {
            getManager().getRedeliveryQueue().addUndelivered(message);
        }
    }
    // make sure the fault is returned for an ws-rm related fault or an invalid ws-rm message
    // note that OneWayProcessingInterceptor handles the robust case, hence not handled here.
    if (isProtocolFault(message)
        && !PropertyUtils.isTrue(message.get(RMMessageConstants.DELIVERING_ROBUST_ONEWAY))) {
        Exchange exchange = message.getExchange();
        exchange.setOneWay(false);

        final AddressingProperties maps = ContextUtils.retrieveMAPs(message, false, false, true);
        if (maps != null && !ContextUtils.isGenericAddress(maps.getFaultTo())) {
            //TODO look at how we can refactor all these decoupled faultTo stuff
            exchange.setDestination(ContextUtils.createDecoupledDestination(exchange, maps.getFaultTo()));
        }
    }
}
 
Example 6
Source File: WadlGeneratorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message mockMessage(String baseAddress, String pathInfo, String query,
                            List<ClassResourceInfo> cris) throws Exception {
    Message m = new MessageImpl();
    Exchange e = new ExchangeImpl();
    e.put(Service.class, new JAXRSServiceImpl(cris));
    m.setExchange(e);
    control.reset();
    ServletDestination d = control.createMock(ServletDestination.class);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    d.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(epr).anyTimes();

    Endpoint endpoint = new EndpointImpl(null, null, epr);
    e.put(Endpoint.class, endpoint);
    endpoint.put(ServerProviderFactory.class.getName(), ServerProviderFactory.getInstance());
    e.setDestination(d);
    BindingInfo bi = control.createMock(BindingInfo.class);
    epr.setBinding(bi);
    bi.getProperties();
    EasyMock.expectLastCall().andReturn(Collections.emptyMap()).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    m.put(Message.HTTP_REQUEST_METHOD, "GET");
    control.replay();
    return m;
}
 
Example 7
Source File: WadlGeneratorJsonTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Message mockMessage(String baseAddress, String pathInfo, String query,
                            ClassResourceInfo cri) throws Exception {
    Message m = new MessageImpl();
    Exchange e = new ExchangeImpl();
    e.put(Service.class, new JAXRSServiceImpl(Collections.singletonList(cri)));
    m.setExchange(e);
    control.reset();
    ServletDestination d = control.createMock(ServletDestination.class);
    EndpointInfo epr = new EndpointInfo();
    epr.setAddress(baseAddress);
    d.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(epr).anyTimes();

    Endpoint endpoint = new EndpointImpl(null, null, epr);
    e.put(Endpoint.class, endpoint);

    e.setDestination(d);
    BindingInfo bi = control.createMock(BindingInfo.class);
    epr.setBinding(bi);
    bi.getProperties();
    EasyMock.expectLastCall().andReturn(Collections.emptyMap()).anyTimes();
    m.put(Message.REQUEST_URI, pathInfo);
    m.put(Message.QUERY_STRING, query);
    m.put(Message.HTTP_REQUEST_METHOD, "GET");
    control.replay();
    return m;
}
 
Example 8
Source File: UDPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void run() {
    while (true) {
        if (mcast == null) {
            return;
        }
        try {
            byte[] bytes = new byte[64 * 1024];
            final DatagramPacket p = new DatagramPacket(bytes, bytes.length);
            mcast.receive(p);

            LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream() {
                public void close() throws IOException {
                    super.close();
                    final DatagramPacket p2 = new DatagramPacket(getRawBytes(),
                                                                 0,
                                                                 this.size(),
                                                                 p.getSocketAddress());
                    mcast.send(p2);
                }
            };

            final MessageImpl m = new MessageImpl();
            final Exchange exchange = new ExchangeImpl();
            exchange.setDestination(UDPDestination.this);
            m.setDestination(UDPDestination.this);
            exchange.setInMessage(m);
            m.setContent(InputStream.class, new ByteArrayInputStream(bytes, 0, p.getLength()));
            m.put(OutputStream.class, out);
            queue.execute(() -> getMessageObserver().onMessage(m));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
 
Example 9
Source File: UDPDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected void processStreamIo(IoSession session, InputStream in, OutputStream out) {
    final MessageImpl m = new MessageImpl();
    final Exchange exchange = new ExchangeImpl();
    exchange.setDestination(UDPDestination.this);
    m.setDestination(UDPDestination.this);
    exchange.setInMessage(m);
    m.setContent(InputStream.class, in);
    out = new UDPDestinationOutputStream(out);
    m.put(OutputStream.class, out);
    queue.execute(() -> getMessageObserver().onMessage(m));
}
 
Example 10
Source File: BasicAuthenticationInterceptorTest.java    From dropwizard-jaxws with Apache License 2.0 5 votes vote down vote up
private Message createEmptyMessage() {
    Exchange exchange = new ExchangeImpl();
    exchange.setInMessage(inMessageMock);
    exchange.setOutMessage(outMessageMock);
    exchange.setDestination(destinationMock);

    Message message = new MessageImpl();
    message.setExchange(exchange);
    message.setInterceptorChain(interceptorChainMock);
    return message;
}
 
Example 11
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * 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);
        }
    }
}
 
Example 12
Source File: MultipleEndpointObserver.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void setExchangeProperties(Exchange exchange, Message m) {
    exchange.put(Bus.class, bus);
    if (exchange.getDestination() == null) {
        exchange.setDestination(m.getDestination());
    }
}