本文整理了Java中org.apache.axiom.om.OMText.getDataHandler()
方法的一些代码示例,展示了OMText.getDataHandler()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。OMText.getDataHandler()
方法的具体详情如下:
包路径:org.apache.axiom.om.OMText
类名称:OMText
方法名:getDataHandler
[英]Gets the datahandler.
[中]获取数据处理程序。
代码示例来源:origin: org.apache.ws.commons.axiom/axiom-impl
public DataHandler getDataHandler() throws XMLStreamException {
if (node instanceof OMText) {
return (DataHandler)((OMText)node).getDataHandler();
} else {
throw new IllegalStateException();
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/om-aspects
public DataHandler getDataHandler() throws XMLStreamException {
if (node instanceof OMText) {
return (DataHandler)((OMText)node).getDataHandler();
} else {
throw new IllegalStateException();
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/axiom-common-impl
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();
}
}
}
代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api
/**
* @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()");
}
代码示例来源:origin: org.apache.axis2/axis2-transport-base
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;
}
代码示例来源:origin: org.apache.ws.commons.axiom/axiom-api
/**
* @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;
}
}
代码示例来源:origin: apache/axis2-java
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;
}
代码示例来源:origin: org.apache.axis2.transport/axis2-transport-testkit
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();
}
};
代码示例来源:origin: org.apache.synapse/synapse-extensions
/**
* 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;
}
代码示例来源:origin: wso2/wso2-synapse
/**
* 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;
}
代码示例来源:origin: org.apache.axis2/axis2-transport-testkit
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();
}
};
代码示例来源:origin: apache/axis2-java
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();
}
};
代码示例来源:origin: org.apache.synapse/synapse-core
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;
}
}
代码示例来源:origin: wso2/wso2-synapse
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;
}
}
代码示例来源:origin: org.apache.synapse/synapse-samples
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;
}
代码示例来源:origin: org.apache.sandesha2/sandesha2-samples
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);
}
}
}
代码示例来源:origin: org.wso2.ei/org.wso2.ei.samples
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;
}
代码示例来源:origin: org.wso2.wsas/wso2wsas-admin
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);
}
}
代码示例来源:origin: apache/axis2-java
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;
}
代码示例来源:origin: org.apache.axis2/axis2-adb
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;
}
内容来源于网络,如有侵权,请联系作者删除!