/** * Read from a stream * * @param in * @throws IOException * @throws ClassNotFoundException */ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { attachments = (Map) in.readObject(); properties = (Map) in.readObject(); String src = (String) in.readObject(); if (src != null) { content = new StringSource(src); } securitySubject = (Subject) in.readObject(); }
public Source getResponseContent() { if (responseContent == null) { if (responseXml != null) { responseContent = new StringSource(responseXml); } else if (responseResource != null) { return new ResourceSource(responseResource); } } return responseContent; }
/** * Get the error messages as a String Source. * * @return */ private StringSource getStringSource() { return new StringSource(getMessagesWithRootElement()); }
public void setBodyText(String xml) { setContent(new StringSource(xml)); }
/** * Write to a Stream * * @param out * @throws IOException */ public void writeExternal(ObjectOutput out) throws IOException { try { convertAttachments(); out.writeObject(attachments); out.writeObject(properties); String src = TRANSFORMER.toString(content); out.writeObject(src); // We have read the source // so now, ensure that it can be re-read if ((content instanceof StreamSource || content instanceof SAXSource) && !(content instanceof StringSource) && !(content instanceof BytesSource) && !(content instanceof ResourceSource)) { content = new StringSource(src); } out.writeObject(securitySubject); } catch (TransformerException e) { throw (IOException) new IOException("Could not transform content to string").initCause(e); } }
return new StringSource(request);
public void convertToJBI(MessageExchange exchange, NormalizedMessage inMsg, PDU request, PDU response) throws MessagingException { // the output buffer StringBuffer sb = new StringBuffer(); // prepare the header sb.append(SNMP_TAG_OPEN); // now loop all variables of the response for (Object o : response.getVariableBindings()) { VariableBinding b = (VariableBinding)o; sb.append(ENTRY_TAG_OPEN); sb.append(OID_TAG_OPEN); sb.append(b.getOid().toString()); sb.append(OID_TAG_CLOSE); sb.append(VALUE_TAG_OPEN); sb.append(b.getVariable().toString()); sb.append(VALUE_TAG_CLOSE); sb.append(ENTRY_TAG_CLOSE); } // prepare the footer sb.append(SNMP_TAG_CLOSE); // now put the buffer to the message content inMsg.setContent(new StringSource(sb.toString())); } }
protected void transformContent(Transformer transformer, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception { Source src = in.getContent(); if (useDomSourceForContent != null && useDomSourceForContent.booleanValue()) { src = new DOMSource(getSourceTransformer().toDOMDocument(src)); } else if (useDomSourceForContent != null && !useDomSourceForContent.booleanValue()) { src = getSourceTransformer().toStreamSource(src); } else { if (src instanceof DOMSource) { src = new DOMSource(getSourceTransformer().toDOMDocument(src)); } } if (RESULT_BYTES.equalsIgnoreCase(getResult())) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Result result = new StreamResult(buffer); transformer.transform(src, result); out.setContent(new BytesSource(buffer.toByteArray())); } else if (RESULT_STRING.equalsIgnoreCase(getResult())) { StringWriter buffer = new StringWriter(); Result result = new StreamResult(buffer); transformer.transform(src, result); out.setContent(new StringSource(buffer.toString())); } else { DOMResult result = new DOMResult(); transformer.transform(src, result); out.setContent(new DOMSource(result.getNode())); } }
protected void transformContent(Transformer transformer, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception { Source src = in.getContent(); if (useDomSourceForContent != null && useDomSourceForContent.booleanValue()) { src = new DOMSource(getSourceTransformer().toDOMDocument(src)); } else if (useDomSourceForContent != null && !useDomSourceForContent.booleanValue()) { src = getSourceTransformer().toStreamSource(src); } else { if (src instanceof DOMSource) { src = new DOMSource(getSourceTransformer().toDOMDocument(src)); } } if (RESULT_BYTES.equalsIgnoreCase(getResult())) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Result result = new StreamResult(buffer); transformer.transform(src, result); out.setContent(new BytesSource(buffer.toByteArray())); } else if (RESULT_STRING.equalsIgnoreCase(getResult())) { StringWriter buffer = new StringWriter(); Result result = new StreamResult(buffer); transformer.transform(src, result); out.setContent(new StringSource(buffer.toString())); } else { DOMResult result = new DOMResult(); transformer.transform(src, result); out.setContent(new DOMSource(result.getNode())); } }
protected void queryContent(XQueryExpression expression, MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws Exception { Configuration config = getConfiguration(); DynamicQueryContext dynamicEnv = new DynamicQueryContext(config); DocumentInfo doc = staticEnv.buildDocument(in.getContent()); dynamicEnv.setContextItem(doc); configureQuery(dynamicEnv, exchange, in); Properties props = outputProperties != null ? outputProperties : EMPTY_PROPS; if (RESULT_BYTES.equalsIgnoreCase(getResult())) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); Result result = new StreamResult(buffer); expression.pull(dynamicEnv, result, props); out.setContent(new BytesSource(buffer.toByteArray())); } else if (RESULT_STRING.equalsIgnoreCase(getResult())) { StringWriter buffer = new StringWriter(); Result result = new StreamResult(buffer); expression.pull(dynamicEnv, result, props); out.setContent(new StringSource(buffer.toString())); } else { DOMResult result = new DOMResult(); expression.pull(dynamicEnv, result, props); out.setContent(new DOMSource(result.getNode())); } }
public void marshal(MessageExchange exchange, NormalizedMessage message, Object body) throws MessagingException { if (useDOM) { try { Document document = transformer.createDocument(); getXStream().marshal(body, new DomWriter(document)); message.setContent(new DOMSource(document)); } catch (ParserConfigurationException e) { throw new MessagingException("Failed to marshal: " + body + " to DOM document: " + e, e); } } else { String xml = getXStream().toXML(body); message.setContent(new StringSource(xml)); } }
private static void copyContent(NormalizedMessage from, NormalizedMessage to) throws MessagingException { String str = null; try { str = new SourceTransformer().toString(from.getContent()); } catch (Exception e) { throw new MessagingException(e); } if (str != null) { to.setContent(new StringSource(str)); } }
public NormalizedMessageImpl(NormalizedMessage message) throws MessagingException { try { String str = new SourceTransformer().contentToString(message); if (str != null) { this.content = new StringSource(str); } for (Iterator it = message.getPropertyNames().iterator(); it.hasNext();) { String name = (String) it.next(); this.properties.put(name, message.getProperty(name)); } for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext();) { String name = (String) it.next(); DataHandler dh = message.getAttachment(name); DataSource ds = dh.getDataSource(); if (!(ds instanceof ByteArrayDataSource)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtil.copyInputStream(ds.getInputStream(), baos); ByteArrayDataSource bads = new ByteArrayDataSource(baos.toByteArray(), ds.getContentType()); bads.setName(ds.getName()); dh = new DataHandler(bads); } this.attachments.put(name, dh); } this.subject = message.getSecuritySubject(); } catch (MessagingException e) { throw e; } catch (Exception e) { throw new MessagingException(e); } }
public void sendMessages(int messageCount, boolean sync) throws MessagingException { LOGGER.info("Looking for services for interface: {}", interfaceName); ServiceEndpoint[] endpoints = context.getEndpointsForService(interfaceName); if (endpoints.length > 0) { ServiceEndpoint endpoint = endpoints[0]; LOGGER.info("Sending to endpoint: {}", endpoint); for (int i = 0; i < messageCount; i++) { InOnly exchange = context.getDeliveryChannel().createExchangeFactory().createInOnlyExchange(); NormalizedMessage message = exchange.createMessage(); exchange.setEndpoint(endpoint); exchange.setInMessage(message); // lets set the XML as a byte[], String or DOM etc String xml = "<s12:Envelope xmlns:s12='http://www.w3.org/2003/05/soap-envelope'>" + " <s12:Body><foo>Hello!</foo> </s12:Body>" + "</s12:Envelope>"; message.setContent(new StringSource(xml)); LOGGER.info("sending message: {}", i); DeliveryChannel deliveryChannel = context.getDeliveryChannel(); LOGGER.info("sync send on deliverychannel: {}", deliveryChannel); if (sync) { deliveryChannel.sendSync(exchange); } else { deliveryChannel.send(exchange); } } } else { LOGGER.warn("No endpoints available for interface: {}", interfaceName); } }
message.setProperty("idText", "" + i); if (msg != null && msg.length() > 0) { message.setContent(new StringSource(msg)); } else { message.setContent(new StringSource(createMessageXmlText(i)));
/** * Convert the given {@link NormalizedMessage} instance's content to a re-readable {@link Source} This allows the * content to be read more than once (e.g. for XPath evaluation or auditing). * * @param message * the {@link NormalizedMessage} to convert the content for * @throws MessagingException */ public static void enableContentRereadability(NormalizedMessage message) throws MessagingException { if (message.getContent() instanceof StreamSource) { try { String content = new SourceTransformer().contentToString(message); if (content != null) { message.setContent(new StringSource(content)); } } catch (TransformerException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (ParserConfigurationException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (IOException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } catch (SAXException e) { throw new MessagingException("Unable to convert message content into StringSource", e); } } }
NormalizedMessage nm = me.createMessage(); me.setMessage(nm, "in"); nm.setContent(new StringSource(content)); me.setEndpoint(endpoint); if (operation != null) {
public void sendMessages(int messageCount, boolean sync) throws JBIException { ComponentContext context = getContext(); for (int i = 0; i < messageCount; i++) { InOnly exchange = context.getDeliveryChannel().createExchangeFactory().createInOnlyExchange(); NormalizedMessage msg = exchange.createMessage(); ServiceEndpoint destination = null; if (resolver != null) { destination = resolver.resolveEndpoint(getContext(), exchange, NullEndpointFilter.getInstance()); } if (destination != null) { // lets explicitly specify the destination - otherwise // we'll let the container choose for us exchange.setEndpoint(destination); } exchange.setInMessage(msg); // lets set the XML as a byte[], String or DOM etc msg.setContent(new StringSource(this.message)); if (sync) { boolean result = context.getDeliveryChannel().sendSync(exchange, 1000); if (!result) { throw new MessagingException("Message delivery using sendSync has timed out"); } } else { context.getDeliveryChannel().send(exchange); } } }
exchange.setFault(fault); fault.setContent(new StringSource(out.toString(charSet))); XFireFault xFault = (XFireFault) ctx.getExchange().getFaultMessage().getBody(); fault.setProperty(SOAP_FAULT_CODE, xFault.getFaultCode()); outMsg.setContent(new StringSource(out.toString(charSet)));
JDOMResult result = new JDOMResult(); String str = getTransformer().contentToString(me.getFault()); getTransformer().toResult(new StringSource(str), result); Element e = result.getDocument().getRootElement(); e = (Element) e.clone();