/** * Retrieve the string-value of a text node. This must not be null and should not be the empty * string. The XPath data model does not allow empty text nodes. * * @param object the text node * @return Returns the string-value of the node. */ public String getTextStringValue(Object object) { return ((OMText) object).getText(); }
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; }
/** * Mark the requied Base64 text values as optimized * @param env * @param optimizeParts This is a set of xPath expressions * * @throws WSSecurityException */ public static void optimize(SOAPEnvelope env, String optimizeParts) throws WSSecurityException { String separater = "<>"; StringTokenizer tokenizer = new StringTokenizer(optimizeParts, separater); while(tokenizer.hasMoreTokens()) { String xpathExpr = tokenizer.nextToken(); //Find binary content List list = findElements(env,xpathExpr); Iterator cipherValueElements = list.iterator(); while (cipherValueElements.hasNext()) { OMElement element = (OMElement) cipherValueElements.next(); OMText text = (OMText)element.getFirstOMChild(); text.setOptimize(true); } } }
/** * @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()"); }
public void writeTextTo(Writer writer) throws XMLStreamException, IOException { switch (currentEvent) { case CHARACTERS: case CDATA: case SPACE: OMText text = (OMText)node; if (text.isCharacters()) { writer.write(text.getTextCharacters()); } else { // TODO: we should cover the binary case in an optimized way writer.write(text.getText()); } break; case COMMENT: writer.write(((OMComment)node).getValue()); break; default: throw new IllegalStateException(); } }
OMText importedText = (OMText) child; OMText newText; if (importedText.isBinary()) { boolean isOptimize = importedText.isOptimized(); newText = createOMText(importedText .getDataHandler(), isOptimize); } else if (importedText.isCharacters()) { newText = createOMText(null, importedText .getTextCharacters(), importedText.getType()); } else { newText = createOMText(null, importedText .getText()/*, importedText.getOMNodeType()*/);
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 DataHandler getDataHandler() throws XMLStreamException { if (node instanceof OMText) { return (DataHandler)((OMText)node).getDataHandler(); } else { throw new IllegalStateException(); } }
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); } } }
if (lastNode instanceof OMText) { OMText text = (OMText) lastNode; return new Boolean(text.isBinary()); if (lastNode instanceof OMText) { OMText text = (OMText) lastNode; if (text.isBinary()) return text.getDataHandler();
public boolean isOptimized() { if (node instanceof OMText) { return ((OMText)node).isOptimized(); } else { throw new IllegalStateException(); } }
public String getContentID() { if (node instanceof OMText) { return ((OMText)node).getContentID(); } else { throw new IllegalStateException(); } }
OMText importedText = (OMText) child; OMText newText; if (importedText.isBinary()) { boolean isOptimize = importedText.isOptimized(); newText = createOMText(importedText .getDataHandler(), isOptimize); } else if (importedText.isCharacters()) { newText = createOMText(null, importedText .getTextCharacters(), importedText.getType()); } else { newText = createOMText(null, importedText .getText()/*, importedText.getOMNodeType()*/);
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 DataHandler getDataHandler() throws XMLStreamException { if (node instanceof OMText) { return (DataHandler)((OMText)node).getDataHandler(); } else { throw new IllegalStateException(); } }
public void writeTextTo(Writer writer) throws XMLStreamException, IOException { switch (currentEvent) { case CHARACTERS: case CDATA: case SPACE: OMText text = (OMText)node; if (text.isCharacters()) { writer.write(text.getTextCharacters()); } else { // TODO: we should cover the binary case in an optimized way writer.write(text.getText()); } break; case COMMENT: writer.write(((OMComment)node).getValue()); break; default: throw new IllegalStateException(); } }
public boolean isOptimized() { if (node instanceof OMText) { return ((OMText)node).isOptimized(); } else { throw new IllegalStateException(); } }
public String getContentID() { if (node instanceof OMText) { return ((OMText)node).getContentID(); } else { throw new IllegalStateException(); } }
public String getNodeValue() { return txt.getText(); }
OMText importedText = (OMText) child; OMText newText; if (importedText.isBinary()) { boolean isOptimize = importedText.isOptimized(); newText = this.factory.createOMText(importedText .getDataHandler(), isOptimize); } else if (importedText.isCharacters()) { newText = new TextImpl((DocumentImpl) this.getOwnerDocument(), importedText.getTextCharacters(), this.factory); } else { newText = new TextImpl((DocumentImpl) this.getOwnerDocument(), importedText.getText(), this.factory);