use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.
the class PayloadFactoryMediatorFactory method removeIndentations.
private void removeIndentations(OMElement element) {
List<OMText> removables = new ArrayList<OMText>();
removeIndentations(element, removables);
for (OMText node : removables) {
node.detach();
}
}
use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.
the class EntryFactory method createEntry.
public static Entry createEntry(OMElement elem, Properties properties) {
String customFactory = SynapsePropertiesLoader.getPropertyValue("synapse.entry.factory", "");
if (customFactory != null && !"".equals(customFactory)) {
try {
Class c = Class.forName(customFactory);
Object o = c.newInstance();
if (o instanceof IEntryFactory) {
return ((IEntryFactory) o).createEntry(elem);
}
} catch (ClassNotFoundException e) {
handleException("Class specified by the synapse.entry.factory " + "synapse property not found: " + customFactory, e);
} catch (InstantiationException e) {
handleException("Class specified by the synapse.entry.factory " + "synapse property cannot be instantiated: " + customFactory, e);
} catch (IllegalAccessException e) {
handleException("Class specified by the synapse.entry.factory " + "synapse property cannot be accessed: " + customFactory, e);
}
}
OMAttribute key = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
if (key == null) {
handleException("The 'key' attribute is required for a local registry entry");
return null;
} else {
Entry entry = new Entry(key.getAttributeValue());
OMElement descriptionElem = elem.getFirstChildWithName(DESCRIPTION_Q);
if (descriptionElem != null) {
entry.setDescription(descriptionElem.getText());
descriptionElem.detach();
}
String src = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "src"));
// are initialized at startup
if (src != null) {
try {
entry.setSrc(new URL(src.trim()));
entry.setType(Entry.URL_SRC);
entry.setValue(SynapseConfigUtils.getObject(entry.getSrc(), properties));
} catch (MalformedURLException e) {
handleException("The entry with key : " + key + " refers to an invalid URL");
}
} else {
OMNode nodeValue = elem.getFirstOMChild();
OMElement elemValue = elem.getFirstElement();
if (elemValue != null) {
entry.setType(Entry.INLINE_XML);
entry.setValue(elemValue);
} else if (nodeValue != null && nodeValue instanceof OMText) {
entry.setType(Entry.INLINE_TEXT);
entry.setValue(elem.getText().trim());
}
}
return entry;
}
}
use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.
the class Target method insertElement.
private void insertElement(ArrayList<OMNode> sourceNodeList, OMElement e, SynapseLog synLog) {
if (action.equals(ACTION_REPLACE)) {
boolean isInserted = false;
for (OMNode elem : sourceNodeList) {
if (elem instanceof OMElement) {
e.insertSiblingBefore(elem);
isInserted = true;
} else if (elem instanceof OMText) {
e.setText(((OMText) elem).getText());
} else {
synLog.error("Invalid Source object to be inserted.");
}
}
if (isInserted) {
e.detach();
}
} else if (action.equals(ACTION_ADD_CHILD)) {
for (OMNode elem : sourceNodeList) {
if (elem instanceof OMElement) {
synchronized (elem) {
e.addChild(elem);
}
}
}
} else if (action.equals(ACTION_ADD_SIBLING)) {
for (OMNode elem : sourceNodeList) {
if (elem instanceof OMElement) {
e.insertSiblingAfter(elem);
}
}
}
}
use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.
the class BinaryExtractMediator method mediate.
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;
}
use of org.apache.axiom.om.OMText in project wso2-synapse by wso2.
the class MTOMSwASampleService method oneWayUploadUsingMTOM.
public void oneWayUploadUsingMTOM(OMElement element) throws Exception {
OMText binaryNode = (OMText) element.getFirstOMChild();
DataHandler dataHandler = (DataHandler) binaryNode.getDataHandler();
InputStream is = dataHandler.getInputStream();
File tempFile = File.createTempFile("mtom-", ".gif");
FileOutputStream fos = new FileOutputStream(tempFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER);
byte[] data = new byte[BUFFER];
int count;
while ((count = is.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
System.out.println("Wrote to file : " + tempFile.getAbsolutePath());
}
Aggregations