org.apache.cxf.transport.MessageObserver Java Examples

The following examples show how to use org.apache.cxf.transport.MessageObserver. 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: CorbaServerConduitTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected CorbaServerConduit setupCorbaServerConduit(boolean send) {
    target = EasyMock.createMock(EndpointReferenceType.class);
    endpointInfo = EasyMock.createMock(EndpointInfo.class);
    CorbaServerConduit corbaServerConduit =
        new CorbaServerConduit(endpointInfo, target, targetObject,
                               null, orbConfig, corbaTypeMap);

    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {
            public void onMessage(Message m) {
                inMessage = m;
            }
        };
        corbaServerConduit.setMessageObserver(observer);
    }

    return corbaServerConduit;
}
 
Example #2
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuspendedException() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    final RuntimeException ex = new RuntimeException();
    observer = new MessageObserver() {
        public void onMessage(Message m) {
            throw new SuspendedInvocationException(ex);
        }
    };
    destination.setMessageObserver(observer);
    try {
        destination.doService(request, response);
        fail("Suspended invocation swallowed");
    } catch (RuntimeException runtimeEx) {
        assertSame("Original exception is not preserved", ex, runtimeEx);
    }
}
 
Example #3
Source File: AbstractClient.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected void setAsyncMessageObserverIfNeeded(Exchange exchange) {
    if (!exchange.isSynchronous()) {
        ExecutorService executor = (ExecutorService)cfg.getRequestContext().get(EXECUTOR_SERVICE_PROPERTY);
        if (executor != null) {
            exchange.put(Executor.class, executor);

            final ClientMessageObserver observer = new ClientMessageObserver(cfg);

            exchange.put(MessageObserver.class, message -> {
                if (!message.getExchange().containsKey(Executor.class.getName() + ".USING_SPECIFIED")) {
                    executor.execute(() -> {
                        observer.onMessage(message);
                    });
                } else {
                    observer.onMessage(message);
                }
            });
        }
    }
}
 
Example #4
Source File: CorbaConduitTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected CorbaConduit setupCorbaConduit(boolean send) {
    target = EasyMock.createMock(EndpointReferenceType.class);
    endpointInfo = EasyMock.createMock(EndpointInfo.class);
    CorbaConduit corbaConduit = new CorbaConduit(endpointInfo, target, orbConfig);

    if (send) {
        // setMessageObserver
        observer = new MessageObserver() {
            public void onMessage(Message m) {
                inMessage = m;
            }
        };
        corbaConduit.setMessageObserver(observer);
    }

    return corbaConduit;
}
 
Example #5
Source File: ServletControllerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testHideServiceListing() throws Exception {
    req.getPathInfo();
    EasyMock.expectLastCall().andReturn(null);

    registry.getDestinationForPath("", true);
    EasyMock.expectLastCall().andReturn(null).atLeastOnce();
    AbstractHTTPDestination dest = EasyMock.createMock(AbstractHTTPDestination.class);
    registry.checkRestfulRequest("");
    EasyMock.expectLastCall().andReturn(dest).atLeastOnce();
    dest.getBus();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    dest.getMessageObserver();
    EasyMock.expectLastCall().andReturn(EasyMock.createMock(MessageObserver.class)).atLeastOnce();

    expectServiceListGeneratorNotCalled();

    EasyMock.replay(req, registry, serviceListGenerator, dest);
    TestServletController sc = new TestServletController(registry, serviceListGenerator);
    sc.setHideServiceList(true);
    sc.invoke(req, res);
    assertTrue(sc.invokeDestinationCalled());
}
 
Example #6
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testSuspendedException() throws Exception {
    destination = setUpDestination(false, false);
    setUpDoService(false);
    final RuntimeException ex = new RuntimeException();
    observer = new MessageObserver() {
        public void onMessage(Message m) {
            throw new SuspendedInvocationException(ex);
        }
    };
    destination.setMessageObserver(observer);
    try {
        destination.doService(request, response);
        fail("Suspended invocation swallowed");
    } catch (RuntimeException runtimeEx) {
        assertSame("Original exception is not preserved", ex, runtimeEx);
    }
}
 
Example #7
Source File: JMSContinuation.java    From cxf with Apache License 2.0 6 votes vote down vote up
public JMSContinuation(Bus b, Message m, MessageObserver observer, Counter suspendendContinuations) {
    bus = b;
    inMessage = m;
    incomingObserver = observer;
    this.suspendendContinuations = suspendendContinuations;
    WorkQueueManager manager = bus.getExtension(WorkQueueManager.class);
    if (manager != null) {
        workQueue = manager.getNamedWorkQueue("jms-continuation");
        if (workQueue == null) {
            workQueue = manager.getAutomaticWorkQueue();
        }
    } else {
        LOG.warning("ERROR_GETTING_WORK_QUEUE");
    }
    loader = bus.getExtension(ClassLoader.class);
}
 
Example #8
Source File: JMSContinuationProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
public JMSContinuationProvider(Bus b,
                               Message m,
                               MessageObserver observer,
                               Counter suspendendContinuations) {
    bus = b;
    inMessage = m;
    incomingObserver = observer;
    this.suspendendContinuations = suspendendContinuations;
}
 
Example #9
Source File: AbstractClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected static MessageObserver setupInFaultObserver(final ClientConfiguration cfg) {
    return new InFaultChainInitiatorObserver(cfg.getBus()) {

        @Override
        protected void initializeInterceptors(Exchange ex, PhaseInterceptorChain chain) {
            chain.add(cfg.getInFaultInterceptors());
            chain.add(new ConnectionFaultInterceptor());
        }
    };
}
 
Example #10
Source File: AbstractConduitSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Conduit createConduit(Message message, Exchange exchange, ConduitInitiator conduitInitiator)
    throws IOException {
    Conduit c;
    synchronized (endpoint) {
        if (!conduits.isEmpty()) {
            c = findCompatibleConduit(message);
            if (c != null) {
                return c;
            }
        }
        EndpointInfo ei = endpoint.getEndpointInfo();
        String add = (String)message.get(Message.ENDPOINT_ADDRESS);
        String basePath = (String)message.get(Message.BASE_PATH);
        if (StringUtils.isEmpty(add)
            || add.equals(ei.getAddress())) {
            c = conduitInitiator.getConduit(ei, exchange.getBus());
            replaceEndpointAddressPropertyIfNeeded(message, add, c);
        } else {
            EndpointReferenceType epr = new EndpointReferenceType();
            AttributedURIType ad = new AttributedURIType();
            ad.setValue(StringUtils.isEmpty(basePath) ? add : basePath);
            epr.setAddress(ad);
            c = conduitInitiator.getConduit(ei, epr, exchange.getBus());
        }
        MessageObserver observer =
            exchange.get(MessageObserver.class);
        if (observer != null) {
            c.setMessageObserver(observer);
        } else {
            getLogger().warning("MessageObserver not found");
        }
        conduits.add(c);
    }
    return c;
}
 
Example #11
Source File: JAXWSHttpSpiDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    control = EasyMock.createNiceControl();
    bus = control.createMock(Bus.class);
    bus.getExtension(org.apache.cxf.policy.PolicyDataEngine.class);
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    observer = control.createMock(MessageObserver.class);
    context = control.createMock(HttpContext.class);
    endpoint = new EndpointInfo();
    endpoint.setAddress(ADDRESS);
}
 
Example #12
Source File: CorbaDestination.java    From cxf with Apache License 2.0 5 votes vote down vote up
public synchronized void setMessageObserver(MessageObserver observer) {
    if (observer != incomingObserver) {
        MessageObserver old = incomingObserver;
        incomingObserver = observer;
        if (observer != null) {
            if (old == null) {
                activate();
            }
        } else {
            if (old != null) {
                deactivate();
            }
        }
    }
}
 
Example #13
Source File: CorbaDSIServantTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvoke() throws Exception {

    CorbaDestination dest = new TestUtils().getComplexTypesTestDestination();


    CorbaDSIServant dsiServant = new CorbaDSIServant();
    dsiServant.init(orb, null, dest, null);
    ServerRequest request = new ServerRequest() {
        public String operation() {
            return "greetMe";
        }
        public Context ctx() {
            return null;
        }

    };

    MessageObserver incomingObserver = new TestObserver();
    dsiServant.setObserver(incomingObserver);

    Map<String, QName> map = new HashMap<>(2);

    map.put("greetMe", new QName("greetMe"));
    dsiServant.setOperationMapping(map);

    dsiServant.invoke(request);
}
 
Example #14
Source File: JettyHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setupDecoupledBackChannel() throws IOException {
    decoupledBackChannel = EasyMock.createMock(Conduit.class);
    decoupledBackChannel.setMessageObserver(EasyMock.isA(MessageObserver.class));
    decoupledBackChannel.prepare(EasyMock.isA(Message.class));
    EasyMock.expectLastCall();
    EasyMock.replay(decoupledBackChannel);
}
 
Example #15
Source File: ServerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void stop() {
    if (stopped) {
        return;
    }

    LOG.fine("Server is stopping.");

    for (Closeable c : endpoint.getCleanupHooks()) {
        try {
            c.close();
        } catch (IOException e) {
            //ignore
        }
    }
    if (slcMgr != null) {
        slcMgr.stopServer(this);
    }

    MessageObserver mo = getDestination().getMessageObserver();
    if (mo instanceof MultipleEndpointObserver) {
        ((MultipleEndpointObserver)mo).getEndpoints().remove(endpoint);
        if (((MultipleEndpointObserver)mo).getEndpoints().isEmpty()) {
            getDestination().setMessageObserver(null);
        }
    } else {
        getDestination().setMessageObserver(null);
    }
    stopped = true;
}
 
Example #16
Source File: PreexistingConduitSelector.java    From cxf with Apache License 2.0 5 votes vote down vote up
/**
 * Called prior to the interceptor chain being traversed.
 *
 * @param message the current Message
 */
public void prepare(Message message) {
    MessageObserver observer =
        message.getExchange().get(MessageObserver.class);
    if (observer != null) {
        selectedConduit.setMessageObserver(observer);
    }
}
 
Example #17
Source File: InternalContextUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
public Conduit getBackChannel(Message inMessage) throws IOException {
    if (ContextUtils.isNoneAddress(reference)) {
        return null;
    }
    Bus bus = inMessage.getExchange().getBus();
    //this is a response targeting a decoupled endpoint.   Treat it as a oneway so
    //we don't wait for a response.
    inMessage.getExchange().setOneWay(true);
    ConduitInitiator conduitInitiator
        = bus.getExtension(ConduitInitiatorManager.class)
            .getConduitInitiatorForUri(reference.getAddress().getValue());
    if (conduitInitiator != null) {
        Conduit c = conduitInitiator.getConduit(ei, reference, bus);
        // ensure decoupled back channel input stream is closed
        c.setMessageObserver(new MessageObserver() {
            public void onMessage(Message m) {
                InputStream is = m.getContent(InputStream.class);
                if (is != null) {
                    try {
                        is.close();
                    } catch (Exception e) {
                        // ignore
                    }
                }
            }
        });
        return c;
    }
    return null;
}
 
Example #18
Source File: JMSDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testMessageObserverExceptionHandling() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    EndpointInfo ei = setupServiceInfo("HelloWorldPubSubService", "HelloWorldPubSubPort");
    JMSConduit conduit = setupJMSConduitWithObserver(ei);

    JMSDestination destination = setupJMSDestination(ei);
    destination.setMessageObserver(new MessageObserver() {
        @Override
        public void onMessage(Message message) {
            try {
                throw new RuntimeException("Error!");
            } finally {
                latch.countDown();
            }
        }
    });

    final Message outMessage = createMessage();
    Thread.sleep(500L);

    sendOneWayMessage(conduit, outMessage);
    latch.await(5, TimeUnit.SECONDS);

    conduit.close();
    destination.shutdown();
}
 
Example #19
Source File: AbstractJMSTester.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected MessageObserver createMessageObserver() {
        return new MessageObserver() {
            public void onMessage(Message m) {
//                Exchange exchange = new ExchangeImpl();
//                exchange.setInMessage(m);
//                m.setExchange(exchange);
                destMessage.set(m);
                synchronized (destMessage) {
                    destMessage.notifyAll();
                }
            }
        };
    }
 
Example #20
Source File: AbstractJMSTester.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected JMSConduit setupJMSConduitWithObserver(EndpointInfo ei) throws IOException {
    JMSConduit jmsConduit = setupJMSConduit(ei);
    MessageObserver observer = new MessageObserver() {
        public void onMessage(Message m) {
            inMessage.set(m);
            synchronized (inMessage) {
                inMessage.notifyAll();
            }
        }
    };
    jmsConduit.setMessageObserver(observer);
    return jmsConduit;
}
 
Example #21
Source File: RequestResponseTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void sendAndReceiveMessages(EndpointInfo ei, boolean synchronous)
        throws IOException, InterruptedException {
    // set up the conduit send to be true
    JMSConduit conduit = setupJMSConduitWithObserver(ei);
    final Message outMessage = createMessage();
    final JMSDestination destination = setupJMSDestination(ei);

    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
            try {
                Conduit 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);

    try {
        sendMessage(conduit, outMessage, synchronous);
        // wait for the message to be got from the destination,
        // create the thread to handler the Destination incoming message

        verifyReceivedMessage(waitForReceiveInMessage());
    } finally {
        conduit.close();
        destination.shutdown();
    }
}
 
Example #22
Source File: JMSContinuationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    m = new MessageImpl();
    Exchange exchange = new ExchangeImpl();
    m.setExchange(exchange);
    m.setInterceptorChain(EasyMock.createMock(InterceptorChain.class));
    exchange.setInMessage(m);

    b = BusFactory.getDefaultBus();
    observer = EasyMock.createMock(MessageObserver.class);
}
 
Example #23
Source File: UndertowHTTPDestinationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private void setupDecoupledBackChannel() throws IOException {
    decoupledBackChannel = EasyMock.createMock(Conduit.class);
    decoupledBackChannel.setMessageObserver(EasyMock.isA(MessageObserver.class));
    decoupledBackChannel.prepare(EasyMock.isA(Message.class));
    EasyMock.expectLastCall();
    EasyMock.replay(decoupledBackChannel);
}
 
Example #24
Source File: CorbaServerConduit.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void setMessageObserver(MessageObserver observer) {
}
 
Example #25
Source File: CorbaDestination.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MessageObserver getMessageObserver() {
    return incomingObserver;
}
 
Example #26
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void init(ORB theOrb,
                 POA poa,
                 CorbaDestination dest,
                 MessageObserver observer) {
    init(theOrb, poa, dest, observer, null);
}
 
Example #27
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MessageObserver getObserver() {
    return incomingObserver;
}
 
Example #28
Source File: CorbaServerConduit.java    From cxf with Apache License 2.0 4 votes vote down vote up
public MessageObserver getMessageObserver() {
    return null;
}
 
Example #29
Source File: CorbaDSIServant.java    From cxf with Apache License 2.0 4 votes vote down vote up
public void init(ORB theOrb,
                 POA poa,
                 CorbaDestination dest,
                 MessageObserver observer,
                 CorbaTypeMap map) {
    orb = theOrb;
    servantPOA = poa;
    destination = dest;
    incomingObserver = observer;
    typeMap = map;

    // Get the list of interfaces that this servant will support
    try {
        BindingType bindType = destination.getBindingInfo().getExtensor(BindingType.class);
        if (bindType == null) {
            throw new CorbaBindingException("Unable to determine corba binding information");
        }

        List<String> bases = bindType.getBases();
        interfaces = new ArrayList<>();
        interfaces.add(bindType.getRepositoryID());
        for (Iterator<String> iter = bases.iterator(); iter.hasNext();) {
            interfaces.add(iter.next());
        }
    } catch (java.lang.Exception ex) {
        LOG.log(Level.SEVERE, "Couldn't initialize the corba DSI servant");
        throw new CorbaBindingException(ex);
    }

    // Build the list of CORBA operations and the WSDL operations they map to.  Note that
    // the WSDL operation name may not always match the CORBA operation name.
    BindingInfo bInfo = destination.getBindingInfo();
    Iterator<BindingOperationInfo> i = bInfo.getOperations().iterator();

    operationMap = new HashMap<>(bInfo.getOperations().size());

    while (i.hasNext()) {
        BindingOperationInfo bopInfo = i.next();
        OperationType opType = bopInfo.getExtensor(OperationType.class);
        if (opType != null) {
            operationMap.put(opType.getName(), bopInfo.getName());
        }
    }
}
 
Example #30
Source File: HTTPConduit.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected void handleResponseOnWorkqueue(boolean allowCurrentThread, boolean forceWQ) throws IOException {
    Runnable runnable = new Runnable() {
        public void run() {
            try {
                handleResponseInternal();
            } catch (Throwable e) {
                ((PhaseInterceptorChain)outMessage.getInterceptorChain()).abort();
                outMessage.setContent(Exception.class, e);
                ((PhaseInterceptorChain)outMessage.getInterceptorChain()).unwind(outMessage);
                MessageObserver mo = outMessage.getInterceptorChain().getFaultObserver();
                if (mo == null) {
                    mo = outMessage.getExchange().get(MessageObserver.class);
                }
                mo.onMessage(outMessage);
            }
        }
    };
    HTTPClientPolicy policy = getClient(outMessage);
    boolean exceptionSet = outMessage.getContent(Exception.class) != null;
    if (!exceptionSet) {
        try {
            Executor ex = outMessage.getExchange().get(Executor.class);
            if (forceWQ && ex != null) {
                final Executor ex2 = ex;
                final Runnable origRunnable = runnable;
                runnable = new Runnable() {
                    public void run() {
                        outMessage.getExchange().put(Executor.class.getName()
                                                     + ".USING_SPECIFIED", Boolean.TRUE);
                        ex2.execute(origRunnable);
                    }
                };
            }
            if (ex == null || forceWQ) {
                WorkQueueManager mgr = outMessage.getExchange().getBus()
                    .getExtension(WorkQueueManager.class);
                AutomaticWorkQueue qu = mgr.getNamedWorkQueue("http-conduit");
                if (qu == null) {
                    qu = mgr.getAutomaticWorkQueue();
                }
                long timeout = 1000;
                if (policy != null && policy.isSetAsyncExecuteTimeout()) {
                    timeout = policy.getAsyncExecuteTimeout();
                }
                if (timeout > 0) {
                    qu.execute(runnable, timeout);
                } else {
                    qu.execute(runnable);
                }
            } else {
                outMessage.getExchange().put(Executor.class.getName()
                                         + ".USING_SPECIFIED", Boolean.TRUE);
                ex.execute(runnable);
            }
        } catch (RejectedExecutionException rex) {
            if (!allowCurrentThread
                || (policy != null
                && policy.isSetAsyncExecuteTimeoutRejection()
                && policy.isAsyncExecuteTimeoutRejection())) {
                throw rex;
            }
            if (!hasLoggedAsyncWarning) {
                LOG.warning("EXECUTOR_FULL_WARNING");
                hasLoggedAsyncWarning = true;
            }
            LOG.fine("EXECUTOR_FULL");
            handleResponseInternal();
        }
    }
}