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); } } }
void writeWithoutAttachments(MessageContext context, OutMessage message, OutputStream out) throws XFireException { XMLStreamWriter writer = STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context); message.getSerializer().writeMessage(message, writer, context); try { writer.flush(); } catch (XMLStreamException e) { logger.error(e); throw new XFireException("Couldn't send message.", e); } }
public void run() { try { final XMLStreamWriter writer = STAXUtils.createXMLStreamWriter(stream, message.getEncoding(), context); message.getSerializer().writeMessage(message, writer, context); writer.close(); stream.close(); } catch (Exception e) { throw new XFireRuntimeException("Couldn't write stream.", e); } finally { semaphore.release(); } }
public void run() { try { final XMLStreamReader reader = STAXUtils.createXMLStreamReader(stream, message.getEncoding(), context); final InMessage inMessage = new InMessage(reader, uri); inMessage.setEncoding(message.getEncoding()); channel.receive(context, inMessage); reader.close(); stream.close(); } catch (Exception e) { throw new XFireRuntimeException("Couldn't read stream.", e); } finally { semaphore.release(); } }
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); }
public void send(final MessageContext context, final 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 { MessageContext oldContext = (MessageContext) context.getProperty(OLD_CONTEXT); sendViaNewChannel(context, oldContext, message, (String) context.getProperty(SENDER_URI)); } } else { MessageContext receivingContext = new MessageContext(); receivingContext.setXFire(context.getXFire()); receivingContext.setService(getService(context.getXFire(), message.getUri())); receivingContext.setProperty(OLD_CONTEXT, context); receivingContext.setProperty(SENDER_URI, getUri()); receivingContext.setSession(session); sendViaNewChannel(context, receivingContext, message, message.getUri()); } }
private void sendViaClient(final MessageContext context, final OutMessage message) throws Exception { OutputHandler handler = new OutputHandler() { public void write(UMOEvent event, OutputStream out) throws IOException { try { Attachments atts = message.getAttachments(); if (atts != null && atts.size() > 0) { atts.write(out); } else { XMLStreamWriter writer = STAXUtils.createXMLStreamWriter(out, message.getEncoding(), context); message.getSerializer().writeMessage(message, writer, context); try { writer.flush(); } catch (XMLStreamException e) { logger.error(e); throw new XFireException("Couldn't send message.", e); } } } catch (XFireException e) { logger.error("Couldn't send message.", e); throw new IOException(e.getMessage()); } } public Map getHeaders(UMOEvent event) { Map headers = new HashMap(); headers.put(HttpConstants.HEADER_CONTENT_TYPE, getSoapMimeType(message)); headers.put(SoapConstants.SOAP_ACTION, message.getProperty(SoapConstants.SOAP_ACTION)); UMOMessage msg = event.getMessage(); for (Iterator iterator = msg.getPropertyNames().iterator(); iterator.hasNext(); ) { String headerName = (String) iterator.next(); Object headerValue = msg.getStringProperty(headerName, null); // let us filter only MULE properties except MULE_USER, // Content-Type and Content-Lenght; all other properties are // allowed through including custom headers if ((!headerName.startsWith(MuleProperties.PROPERTY_PREFIX) || (MuleProperties.MULE_USER_PROPERTY.compareTo(headerName) == 0)) && (!HttpConstants.HEADER_CONTENT_TYPE.equalsIgnoreCase(headerName)) && (!HttpConstants.HEADER_CONTENT_LENGTH.equalsIgnoreCase(headerName))) { headers.put(headerName, headerValue); } } return headers; } }; // We can create a generic StreamMessageAdapter here as the underlying // transport will create one specific to the transport UMOStreamMessageAdapter sp = new StreamMessageAdapter(handler); sp.setProperty(HttpConnector.HTTP_METHOD_PROPERTY, HttpConstants.METHOD_POST); // set all properties on the message adapter UMOMessage msg = RequestContext.getEvent().getMessage(); for (Iterator i = msg.getPropertyNames().iterator(); i.hasNext(); ) { String propertyName = (String) i.next(); sp.setProperty(propertyName, msg.getProperty(propertyName)); } UMOStreamMessageAdapter result = null; try { result = sendStream(getUri(), sp); if (result != null) { InMessage inMessage; String contentType = sp.getStringProperty(HttpConstants.HEADER_CONTENT_TYPE, "text/xml"); InputStream in = result.getInputStream(); if (contentType.toLowerCase().indexOf("multipart/related") != -1) { try { Attachments atts = new JavaMailAttachments(in, contentType); InputStream msgIs = atts.getSoapMessage().getDataHandler().getInputStream(); inMessage = new InMessage( STAXUtils.createXMLStreamReader(msgIs, message.getEncoding(), context), getUri()); inMessage.setAttachments(atts); } catch (MessagingException e) { throw new IOException(e.getMessage()); } } else { inMessage = new InMessage( STAXUtils.createXMLStreamReader(in, message.getEncoding(), context), getUri()); } getEndpoint().onReceive(context, inMessage); } } finally { sp.release(); if (result != null) { result.release(); } } }