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

The following examples show how to use org.apache.cxf.message.MessageImpl#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: CorbaConduit.java    From cxf with Apache License 2.0 6 votes vote down vote up
public void handleResponse() throws IOException {
    LOG.log(Level.FINE, "incoming observer is " + incomingObserver);
    Exchange exchange = message.getExchange();
    CorbaMessage corbaMsg = (CorbaMessage) message;
    MessageImpl inMessage = new MessageImpl();
    CorbaDestination destination = new CorbaDestination(endpointInfo, orbConfig, typeMap);
    inMessage.setDestination(destination);
    exchange.put(ORB.class, orb);
    inMessage.setExchange(exchange);
    CorbaMessage inCorbaMsg = new CorbaMessage(inMessage);
    inCorbaMsg.setCorbaTypeMap(typeMap);
    if (corbaMsg.getStreamableException() != null) {
        exchange.setInFaultMessage(corbaMsg);
        inCorbaMsg.setStreamableException(corbaMsg.getStreamableException());
    } else if (corbaMsg.getSystemException() != null) {
        exchange.setInFaultMessage(corbaMsg);
        inCorbaMsg.setSystemException(corbaMsg.getSystemException());
    }
    LOG.log(Level.FINE, "incoming observer is " + incomingObserver);
    incomingObserver.onMessage(inCorbaMsg);
    message.setContent(Exception.class, inCorbaMsg.getContent(Exception.class));
}
 
Example 2
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void invoke(ServerRequest request) throws CorbaBindingException {
    String opName = request.operation();
    QName requestOperation = operationMap.get(opName);

    MessageImpl msgImpl = new MessageImpl();
    msgImpl.setDestination(getDestination());
    Exchange exg = new ExchangeImpl();
    exg.put(String.class, requestOperation.getLocalPart());
    exg.put(ORB.class, getOrb());
    exg.put(ServerRequest.class, request);
    msgImpl.setExchange(exg);
    CorbaMessage msg = new CorbaMessage(msgImpl);
    msg.setCorbaTypeMap(typeMap);

    // If there's no output message part in our operation then it's a oneway op
    BindingMessageInfo bindingMsgOutputInfo = null;
    BindingOperationInfo bindingOpInfo = null;
    try {
        bindingOpInfo = this.destination.getEndPointInfo().getBinding().getOperation(requestOperation);
    } catch (Exception ex) {
        throw new CorbaBindingException("Invalid Request. Operation unknown: " + opName);
    }
    if (bindingOpInfo != null) {
        bindingMsgOutputInfo = bindingOpInfo.getOutput();
        if (bindingMsgOutputInfo == null) {
            exg.setOneWay(true);
        }
    }

    // invokes the interceptors
    getObserver().onMessage(msg);
}
 
Example 3
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 4
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 5
Source File: LocalConduit.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void dispatchDirect(Message message) throws IOException {
    if (destination.getMessageObserver() == null) {
        throw new IllegalStateException("Local destination does not have a MessageObserver on address "
                                        + destination.getAddress().getAddress().getValue());
    }

    MessageImpl copy = new MessageImpl();
    copy.put(IN_CONDUIT, this);
    copy.setDestination(destination);

    transportFactory.copy(message, copy);
    MessageImpl.copyContent(message, copy);

    OutputStream out = message.getContent(OutputStream.class);
    out.flush();
    out.close();

    CachedOutputStream stream = message.get(CachedOutputStream.class);
    copy.setContent(InputStream.class, stream.getInputStream());
    copy.removeContent(CachedOutputStream.class);
    stream.releaseTempFileHold();

    // Create a new incoming exchange and store the original exchange for the response
    ExchangeImpl ex = new ExchangeImpl();
    ex.setInMessage(copy);
    ex.put(IN_EXCHANGE, message.getExchange());
    ex.put(LocalConduit.DIRECT_DISPATCH, true);
    ex.setDestination(destination);

    destination.getMessageObserver().onMessage(copy);
}
 
Example 6
Source File: LocalTransportFactoryTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
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());
}