Exemplo n.º 1
0
  public void send(MessageContext context, OutMessage message) throws XFireException {
    if (message.getUri().equals(Channel.BACKCHANNEL_URI)) {
      final OutputStream out = (OutputStream) context.getProperty(Channel.BACKCHANNEL_URI);
      if (out != null) {
        final XMLStreamWriter writer =
            STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context);

        message.getSerializer().writeMessage(message, writer, context);
      } else {
        throw new XFireRuntimeException("No backchannel exists for message");
      }

      try {
        Attachments atts = message.getAttachments();
        if (atts != null && atts.size() > 0) {
          writeAttachmentBody(context, message);
          // TODO response.setContentType(atts.getContentType());
          atts.write(out);
        } else {
          // TODO response.setContentType(getSoapMimeType(message));
          writeWithoutAttachments(context, message, out);
        }
      } catch (IOException e) {
        throw new XFireException("Couldn't send message.", e);
      }
    } else {
      try {
        sendViaClient(context, message);
      } catch (Exception e) {
        throw new XFireException("Failed to Send via MuleUniversalChannel: " + e.getMessage(), e);
      }
    }
  }
Exemplo n.º 2
0
  void writeAttachmentBody(MessageContext context, OutMessage message) throws XFireException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    writeWithoutAttachments(context, message, bos);

    Attachments atts = message.getAttachments();

    ByteDataSource ds = new ByteDataSource(bos.toByteArray());
    ds.setContentType(getSoapMimeType(message));
    DataHandler dh = new DataHandler(ds);

    SimpleAttachment att = new SimpleAttachment("soap-message.xml", dh);

    atts.setSoapMessage(att);
  }