public DataHandler getDataHandler() throws XMLStreamException { if (node instanceof OMText) { return (DataHandler)((OMText)node).getDataHandler(); } else { throw new IllegalStateException(); } }
public DataHandler getDataHandler() throws XMLStreamException { if (node instanceof OMText) { return (DataHandler)((OMText)node).getDataHandler(); } else { throw new IllegalStateException(); } }
public DataHandler getDataHandler() throws XMLStreamException { if (parser != null) { if (dataHandlerReader != null) { return dataHandlerReader.getDataHandler(); } else { throw new IllegalStateException(); } } else { if (lastNode instanceof OMText) { return (DataHandler)((OMText)lastNode).getDataHandler(); } else { throw new IllegalStateException(); } } }
/** * @deprecated * Serialization code should use * {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)} * or {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandlerProvider, String, boolean)} * to submit any binary content and let this writer decide whether the content should be * written as base64 encoded character data or using <tt>xop:Include</tt>. If this is not * possible, then {@link #prepareDataHandler(DataHandler)} should be used. */ public void writeOptimized(OMText node) { log.debug("Start MTOMXMLStreamWriter.writeOptimized()"); otherParts.add(new Part(node.getContentID(), (DataHandler)node.getDataHandler())); log.debug("Exit MTOMXMLStreamWriter.writeOptimized()"); }
private DataHandler getDataHandler(MessageContext messageContext) { OMElement firstChild = messageContext.getEnvelope().getBody().getFirstElement(); if (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) { OMNode omNode = firstChild.getFirstOMChild(); if (omNode != null && omNode instanceof OMText) { Object dh = ((OMText)omNode).getDataHandler(); if (dh != null && dh instanceof DataHandler) { return (DataHandler)dh; } } } return null; }
/** * @deprecated * Serialization code should use * {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandler, String, boolean)} * or {@link XMLStreamWriterUtils#writeDataHandler(XMLStreamWriter, DataHandlerProvider, String, boolean)} * to submit any binary content and let this writer decide whether the content should be * written as base64 encoded character data or using <tt>xop:Include</tt>. If this is not * possible, then {@link #prepareDataHandler(DataHandler)} should be used. * All the aforementioned methods take into account the settings defined in * {@link OMOutputFormat} to determine whether the binary data should be optimized or not. * Therefore, there is not need for this method anymore. */ public boolean isOptimizedThreshold(OMText node){ // The optimize argument is set to true for compatibility. Indeed, older versions // left it to the caller to check OMText#isOptimized(). try { return optimizationPolicy.isOptimized((DataHandler)node.getDataHandler(), true); } catch (IOException ex) { return true; } }
private DataHandler getDataHandler(MessageContext messageContext) { OMElement firstChild = messageContext.getEnvelope().getBody().getFirstElement(); if (BaseConstants.DEFAULT_BINARY_WRAPPER.equals(firstChild.getQName())) { OMNode omNode = firstChild.getFirstOMChild(); if (omNode != null && omNode instanceof OMText) { Object dh = ((OMText)omNode).getDataHandler(); if (dh != null && dh instanceof DataHandler) { return (DataHandler)dh; } } } return null; }
public byte[] decode(ContentType contentType, AxisMessage message) throws Exception { SOAPEnvelope envelope = message.getEnvelope(); OMElement wrapper = envelope.getBody().getFirstElement(); Assert.assertEquals(BaseConstants.DEFAULT_BINARY_WRAPPER, wrapper.getQName()); OMNode child = wrapper.getFirstOMChild(); Assert.assertTrue(child instanceof OMText); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((DataHandler)((OMText)child).getDataHandler()).writeTo(baos); return baos.toByteArray(); } };
/** * Tries to extract the binary data source containing the Hessian message. * * @param omElement * * @return the binary data source containing the Hessian message or null, if the OMElement * does not contain a binary datasource. */ private SynapseBinaryDataSource extractSynapseBinaryDataSource(OMElement omElement) { SynapseBinaryDataSource synapseBinaryDataSource = null; Iterator it = omElement.getChildren(); while (it.hasNext() && synapseBinaryDataSource == null) { OMNode hessianElement = (OMNode) it.next(); if (hessianElement instanceof OMText) { OMText tempNode = (OMText) hessianElement; if (tempNode.getDataHandler() != null && ((DataHandler) tempNode.getDataHandler()).getDataSource() instanceof SynapseBinaryDataSource) { synapseBinaryDataSource = (SynapseBinaryDataSource) ((DataHandler) tempNode .getDataHandler()).getDataSource(); } } } return synapseBinaryDataSource; }
/** * Tries to extract the binary data source containing the Hessian message. * * @param omElement * * @return the binary data source containing the Hessian message or null, if the OMElement * does not contain a binary datasource. */ private SynapseBinaryDataSource extractSynapseBinaryDataSource(OMElement omElement) { SynapseBinaryDataSource synapseBinaryDataSource = null; Iterator it = omElement.getChildren(); while (it.hasNext() && synapseBinaryDataSource == null) { OMNode hessianElement = (OMNode) it.next(); if (hessianElement instanceof OMText) { OMText tempNode = (OMText) hessianElement; if (tempNode.getDataHandler() != null && ((DataHandler) tempNode.getDataHandler()).getDataSource() instanceof SynapseBinaryDataSource) { synapseBinaryDataSource = (SynapseBinaryDataSource) ((DataHandler) tempNode .getDataHandler()).getDataSource(); } } } return synapseBinaryDataSource; }
public byte[] decode(ContentType contentType, AxisMessage message) throws Exception { SOAPEnvelope envelope = message.getEnvelope(); OMElement wrapper = envelope.getBody().getFirstElement(); Assert.assertEquals(BaseConstants.DEFAULT_BINARY_WRAPPER, wrapper.getQName()); OMNode child = wrapper.getFirstOMChild(); Assert.assertTrue(child instanceof OMText); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((DataHandler)((OMText)child).getDataHandler()).writeTo(baos); return baos.toByteArray(); } };
public byte[] decode(ContentType contentType, AxisMessage message) throws Exception { SOAPEnvelope envelope = message.getEnvelope(); OMElement wrapper = envelope.getBody().getFirstElement(); Assert.assertEquals(BaseConstants.DEFAULT_BINARY_WRAPPER, wrapper.getQName()); OMNode child = wrapper.getFirstOMChild(); Assert.assertTrue(child instanceof OMText); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ((DataHandler)((OMText)child).getDataHandler()).writeTo(baos); return baos.toByteArray(); } };
public static DataHandler getBinaryPayload(SOAPEnvelope envelope) { OMElement el = getXMLPayload(envelope); if (el == null) return null; if (!el.getQName().equals(BINARYELT)) { log.error("Wrong QName" + el.getQName()); return null; } OMNode textNode = el.getFirstOMChild(); if (textNode.getType() != OMNode.TEXT_NODE) { log.error("Text Node not found"); return null; } OMText text = (OMText) textNode; try { return (DataHandler) text.getDataHandler(); } catch (ClassCastException ce) { log.error("cannot get DataHandler" + ce.getMessage()); return null; } }
public static DataHandler getBinaryPayload(SOAPEnvelope envelope) { OMElement el = getXMLPayload(envelope); if (el == null) return null; if (!el.getQName().equals(BINARYELT)) { log.error("Wrong QName" + el.getQName()); return null; } OMNode textNode = el.getFirstOMChild(); if (textNode.getType() != OMNode.TEXT_NODE) { log.error("Text Node not found"); return null; } OMText text = (OMText) textNode; try { return (DataHandler) text.getDataHandler(); } catch (ClassCastException ce) { log.error("cannot get DataHandler" + ce.getMessage()); return null; } }
public boolean mediate(MessageContext msgCtx) { try { log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length); SOAPBody soapBody = msgCtx.getEnvelope().getBody(); OMElement firstElement = soapBody.getFirstElement(); log.debug("First Element : "+firstElement.getLocalName()); log.debug("First Element Text : "+firstElement.getText()); OMText binaryNode =(OMText) firstElement.getFirstOMChild(); log.debug("First Element Node Text : "+binaryNode.getText()); DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler(); InputStream inputStream = dataHandler.getInputStream(); byte[] searchByte = new byte[length]; inputStream.skip(offset - 1); int readBytes = inputStream.read(searchByte,0,length); String outString = new String(searchByte,binaryEncoding); msgCtx.setProperty(variableName,outString); log.debug("Set property to MsgCtx, "+variableName+" = "+outString); inputStream.close(); } catch (IOException e) { log.error("Excepton on mediation : "+e.getMessage()); } return true; }
public void MTOMPing(OMElement in) throws Exception { OMElement attachmentElem = in.getFirstChildWithName(new QName(applicationNamespaceName, Attachment)); if (attachmentElem == null) throw new AxisFault("'Attachment' element is not present as a child of the 'Ping' element"); OMText binaryElem = (OMText) attachmentElem.getFirstOMChild(); binaryElem.setOptimize(true); DataHandler dataHandler = (DataHandler) binaryElem.getDataHandler(); try { File destinationFile = new File(DESTINATION_IMAGE_FILE); if (destinationFile.exists()) destinationFile.delete(); FileOutputStream fileOutputStream = new FileOutputStream(DESTINATION_IMAGE_FILE); InputStream inputStream = dataHandler.getDataSource().getInputStream(); byte[] bytes = new byte[5000]; int length = inputStream.read(bytes); fileOutputStream.write(bytes, 0, length); fileOutputStream.close(); } catch (Exception e) { throw AxisFault.makeFault(e); } } }
public boolean mediate(MessageContext msgCtx) { try { log.debug("BinaryExtractMediator Process, with offset: "+offset+" ,length "+length); SOAPBody soapBody = msgCtx.getEnvelope().getBody(); OMElement firstElement = soapBody.getFirstElement(); log.debug("First Element : "+firstElement.getLocalName()); log.debug("First Element Text : "+firstElement.getText()); OMText binaryNode =(OMText) firstElement.getFirstOMChild(); log.debug("First Element Node Text : "+binaryNode.getText()); DataHandler dataHandler =(DataHandler) binaryNode.getDataHandler(); InputStream inputStream = dataHandler.getInputStream(); byte[] searchByte = new byte[length]; inputStream.skip(offset - 1); int readBytes = inputStream.read(searchByte,0,length); String outString = new String(searchByte,binaryEncoding); msgCtx.setProperty(variableName,outString); log.debug("Set property to MsgCtx, "+variableName+" = "+outString); inputStream.close(); } catch (IOException e) { log.error("Excepton on mediation : "+e.getMessage()); } return true; }
public boolean deployService(OMElement element) throws AxisFault { try { if (element == null) { throw new AxisFault("Element is null"); } String fileName = element.getLocalName(); OMNode node = element.getFirstOMChild(); if (node instanceof OMText) { OMText txt = (OMText) node; String repo = getAxisConfig().getRepository().getPath(); DataHandler expectedDH = (DataHandler) txt.getDataHandler(); File serviceDir = new File(repo, "services"); File file = new File(serviceDir, fileName); OutputStream out = new FileOutputStream(file); expectedDH.writeTo(out); out.flush(); out.close(); return true; } else { throw new AxisFault("Invalid Message"); } } catch (IOException e) { throw AxisFault.makeFault(e); } }
public static DataHandler getDataHandler(OMElement element) { OMNode node = element.getFirstOMChild(); if (node instanceof OMText) { OMText txt = (OMText)node; if (txt.isOptimized()) { return (DataHandler)txt.getDataHandler(); } else { return new DataHandler(new ByteArrayDataSource(Base64Utils.decode(txt.getText()))); } } return null; }
public static DataHandler getDataHandler(OMElement element) { OMNode node = element.getFirstOMChild(); if (node instanceof OMText) { OMText txt = (OMText)node; if (txt.isOptimized()) { return (DataHandler)txt.getDataHandler(); } else { return new DataHandler(new ByteArrayDataSource(Base64Utils.decode(txt.getText()))); } } return null; }