示例#1
1
    /**
     * Called for an incoming message.
     *
     * @param inMessage
     */
    public void onMessage(Message inMessage) {
      // disposable exchange, swapped with real Exchange on correlation
      inMessage.setExchange(new ExchangeImpl());
      inMessage.getExchange().put(Bus.class, bus);
      inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
      inMessage.put(Message.RESPONSE_CODE, HttpURLConnection.HTTP_OK);

      // remove server-specific properties
      // inMessage.remove(AbstractHTTPDestination.HTTP_REQUEST);
      // inMessage.remove(AbstractHTTPDestination.HTTP_RESPONSE);
      inMessage.remove(Message.ASYNC_POST_RESPONSE_DISPATCH);
      updateResponseCode(inMessage);

      // cache this inputstream since it's defer to use in case of async
      try {
        InputStream in = inMessage.getContent(InputStream.class);
        if (in != null) {
          CachedOutputStream cos = new CachedOutputStream();
          IOUtils.copy(in, cos);
          inMessage.setContent(InputStream.class, cos.getInputStream());
        }
        observer.onMessage(inMessage);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
示例#2
0
  protected void invokeColocObserver(Message outMsg, Endpoint inboundEndpoint) {
    if (colocObserver == null) {
      colocObserver = new ColocMessageObserver(inboundEndpoint, bus);
    }
    if (LOG.isLoggable(Level.FINE)) {
      LOG.fine("Invoke on Coloc Observer.");
    }

    colocObserver.onMessage(outMsg);
  }
  private HttpExchange setUpExchange() throws Exception {
    HttpExchange exchange = control.createMock(HttpExchange.class);
    expect(exchange.getHttpContext()).andReturn(context).anyTimes();
    expect(exchange.getQueryString()).andReturn(null);
    expect(exchange.getPathInfo()).andReturn(null);
    expect(exchange.getRequestURI()).andReturn(CONTEXT_PATH);
    expect(exchange.getContextPath()).andReturn(CONTEXT_PATH);
    Map<String, List<String>> reqHeaders = new HashMap<String, List<String>>();
    reqHeaders.put("Content-Type", Collections.singletonList("text/xml"));
    expect(exchange.getRequestHeaders()).andReturn(reqHeaders).anyTimes();
    OutputStream responseBody = control.createMock(OutputStream.class);
    responseBody.flush();
    EasyMock.expectLastCall();
    expect(exchange.getResponseBody()).andReturn(responseBody).anyTimes();
    observer.onMessage(isA(Message.class));
    EasyMock.expectLastCall();

    return exchange;
  }
  private void handleAbort(SoapMessage message, MessageContext context) {
    if (isRequestor(message)) {
      // client side outbound
      if (getInvoker(message).isOutbound()) {
        message.getInterceptorChain().abort();

        MessageObserver observer =
            (MessageObserver) message.getExchange().get(MessageObserver.class);
        if (!message.getExchange().isOneWay() && observer != null) {
          Endpoint e = message.getExchange().get(Endpoint.class);
          Message responseMsg = e.getBinding().createMessage();

          // the request message becomes the response message
          message.getExchange().setInMessage(responseMsg);
          SOAPMessage soapMessage = ((SOAPMessageContext) context).getMessage();

          if (soapMessage != null) {
            responseMsg.setContent(SOAPMessage.class, soapMessage);
            XMLStreamReader xmlReader = createXMLStreamReaderFromSOAPMessage(soapMessage);
            responseMsg.setContent(XMLStreamReader.class, xmlReader);
          }
          responseMsg.put(
              PhaseInterceptorChain.STARTING_AT_INTERCEPTOR_ID,
              SOAPHandlerInterceptor.class.getName());
          observer.onMessage(responseMsg);
        }
        // We dont call onCompletion here, as onCompletion will be called by inbound
        // LogicalHandlerInterceptor
      } else {
        // client side inbound - Normal handler message processing
        // stops, but the inbound interceptor chain still continues, dispatch the message
        // By onCompletion here, we can skip following Logical handlers
        onCompletion(message);
      }
    } else {
      if (!getInvoker(message).isOutbound()) {
        // server side inbound
        message.getInterceptorChain().abort();
        Endpoint e = message.getExchange().get(Endpoint.class);
        Message responseMsg = e.getBinding().createMessage();
        if (!message.getExchange().isOneWay()) {
          message.getExchange().setOutMessage(responseMsg);
          SOAPMessage soapMessage = ((SOAPMessageContext) context).getMessage();

          responseMsg.setContent(SOAPMessage.class, soapMessage);

          InterceptorChain chain =
              OutgoingChainInterceptor.getOutInterceptorChain(message.getExchange());
          responseMsg.setInterceptorChain(chain);
          // so the idea of starting interceptor chain from any
          // specified point does not work
          // well for outbound case, as many outbound interceptors
          // have their ending interceptors.
          // For example, we can not skip MessageSenderInterceptor.
          chain.doInterceptStartingAfter(
              responseMsg, SoapPreProtocolOutInterceptor.class.getName());
        }

      } else {
        // server side outbound - Normal handler message processing
        // stops, but still continue the outbound interceptor chain, dispatch the message
      }
    }
  }