示例#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 handle(Message message) throws SequenceFault, RMException {
    LOG.entering(getClass().getName(), "handleMessage");
    // This message capturing mechanism will need to be changed at some point.
    // Until then, we keep this interceptor here and utilize the robust
    // option to avoid the unnecessary message capturing/caching.
    if (!MessageUtils.isTrue(message.getContextualProperty(Message.ROBUST_ONEWAY))) {
      InputStream is = message.getContent(InputStream.class);
      if (is != null) {
        CachedOutputStream saved = new CachedOutputStream();
        try {
          IOUtils.copy(is, saved);

          saved.flush();
          is.close();
          saved.lockOutputStream();

          LOG.fine("Capturing the original RM message");
          RewindableInputStream ris = RewindableInputStream.makeRewindable(saved.getInputStream());
          message.setContent(InputStream.class, ris);
          message.put(RMMessageConstants.SAVED_CONTENT, ris);
        } catch (Exception e) {
          throw new Fault(e);
        }
      }
    }
  }
  private void doFromSoapMessage(Message message, Object sm) {
    SOAPMessage m = (SOAPMessage) sm;
    MessageContentsList list = (MessageContentsList) message.getContent(List.class);
    if (list == null) {
      list = new MessageContentsList();
      message.setContent(List.class, list);
    }
    Object o = m;

    if (StreamSource.class.isAssignableFrom(type)) {
      try {
        try (CachedOutputStream out = new CachedOutputStream()) {
          XMLStreamWriter xsw = StaxUtils.createXMLStreamWriter(out);
          StaxUtils.copy(new DOMSource(m.getSOAPPart()), xsw);
          xsw.close();
          o = new StreamSource(out.getInputStream());
        }
      } catch (Exception e) {
        throw new Fault(e);
      }
    } else if (SAXSource.class.isAssignableFrom(type)) {
      o = new StaxSource(new W3CDOMStreamReader(m.getSOAPPart()));
    } else if (Source.class.isAssignableFrom(type)) {
      o = new DOMSource(m.getSOAPPart());
    }
    list.set(0, o);
  }
    @Override
    public void onClose(CachedOutputStream cos) {
      long l = LOG.logStart();
      byte[] buf = new byte[1024];
      int len;
      InputStream is;
      try {
        is = cos.getInputStream();
        while ((len = is.read(buf)) > 0) {
          logOutputStream.write(buf, 0, len);
        }
      } catch (IOException ex) {
        LOG.logError(l, ex);
      }
      LoggingMessage buffer = setupBuffer(message, fout);
      LOG.log(buffer.toString());

      try {
        // empty out the cache
        cos.lockOutputStream();
        cos.resetOut(null, false);
      } catch (Exception ex) {
        LOG.logWarn(l, "Error clearing cache: " + ex.getMessage(), null);
      }
      message.setContent(OutputStream.class, origStream);
    }
示例#5
0
 private InputStream copyIn(InputStream in) throws Exception {
   try (CachedOutputStream bos = new CachedOutputStream()) {
     IOUtils.copyAndCloseInput(in, bos);
     in = bos.getInputStream();
     bos.close();
     return in;
   }
 }
  @Override
  protected void marshalToWriter(
      Marshaller ms, Object obj, XMLStreamWriter writer, Annotation[] anns, MediaType mt)
      throws Exception {
    CachedOutputStream out = new CachedOutputStream();
    marshalToOutputStream(ms, obj, out, anns, mt);

    StaxUtils.copy(new StreamSource(out.getInputStream()), writer);
  }
 @Override
 public void onClose(CachedOutputStream wrapper) {
   InputStream transformedStream = null;
   try {
     transformedStream = XSLTUtils.transform(xsltTemplate, wrapper.getInputStream());
     IOUtils.copyAndCloseInput(transformedStream, origStream);
   } catch (IOException e) {
     throw new Fault("STREAM_COPY", LOG, e, e.getMessage());
   } finally {
     try {
       origStream.close();
     } catch (IOException e) {
       LOG.warning("Cannot close stream after transformation: " + e.getMessage());
     }
   }
 }
 @Override
 protected Object unmarshalFromReader(
     Unmarshaller unmarshaller, XMLStreamReader reader, Annotation[] anns, MediaType mt)
     throws JAXBException {
   CachedOutputStream out = new CachedOutputStream();
   try {
     XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
     StaxUtils.copy(new StaxSource(reader), writer);
     writer.writeEndDocument();
     writer.flush();
     writer.close();
     return unmarshalFromInputStream(unmarshaller, out.getInputStream(), anns, mt);
   } catch (Exception ex) {
     throw ExceptionUtils.toBadRequestException(ex, null);
   }
 }
示例#9
0
    @Override
    public void close(Message message) throws IOException {
      if (Boolean.TRUE.equals(message.getExchange().get(LocalConduit.DIRECT_DISPATCH))) {
        final Exchange exchange = (Exchange) message.getExchange().get(LocalConduit.IN_EXCHANGE);

        MessageImpl copy = new MessageImpl();
        copy.putAll(message);
        MessageImpl.copyContent(message, copy);
        CachedOutputStream stream = (CachedOutputStream) message.getContent(OutputStream.class);
        copy.setContent(InputStream.class, stream.getInputStream());
        if (exchange != null && exchange.getInMessage() == null) {
          exchange.setInMessage(copy);
        }
        conduit.getMessageObserver().onMessage(copy);
        return;
      }

      super.close(message);
    }