org.apache.axiom.om.OMText Java Examples

The following examples show how to use org.apache.axiom.om.OMText. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MTOMSwASampleService.java    From product-ei with Apache License 2.0 6 votes vote down vote up
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());
    }
 
Example #2
Source File: TableTemplateJrxmlHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void updateTableCellNames() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:componentElement//b:table//b:column" +
            "//b:detailCell//a:textFieldExpression");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    xpathExpression.addNamespace("b", "http://jasperreports.sourceforge.net/jasperreports/components");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);

    for (int i = 0; i < nodeList.size(); i++) {
        OMElement textFieldExpression = (OMElement) nodeList.get(i);
        int fieldNo = i + 1;
        textFieldExpression.setText("");
        OMFactory factory = document.getOMFactory();
        OMText cdataField = factory.createOMText(textFieldExpression, "$F{" + fieldNo + "}",
                OMText.CDATA_SECTION_NODE);
        textFieldExpression.addChild(cdataField);
    }
}
 
Example #3
Source File: TableTemplateJrxmlHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void updateTableFooterNames() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:componentElement//b:table//b:column" +
            "//b:columnFooter//a:text");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    xpathExpression.addNamespace("b", "http://jasperreports.sourceforge.net/jasperreports/components");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    for (int i = 0; i < nodeList.size(); i++) {
        OMElement textElement = (OMElement) nodeList.get(i);
        textElement.setText("");
        OMFactory factory = document.getOMFactory();
        OMText cdataField = factory.createOMText(textElement, tableReport.getColumns()[i].getColumnFooterName(),
                OMText.CDATA_SECTION_NODE);
        textElement.addChild(cdataField);
    }
}
 
Example #4
Source File: TableTemplateJrxmlHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void updateTableHeaderNames() throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:band//a:componentElement//b:table//b:column" +
            "//b:columnHeader//a:text");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    xpathExpression.addNamespace("b", "http://jasperreports.sourceforge.net/jasperreports/components");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    for (int i = 0; i < nodeList.size(); i++) {
        OMElement textElement = (OMElement) nodeList.get(i);
        textElement.setText("");
        OMFactory factory = document.getOMFactory();
        OMText cdataField = factory.createOMText(textElement, tableReport.getColumns()[i].getColumnHeaderName(),
                OMText.CDATA_SECTION_NODE);
        textElement.addChild(cdataField);
    }
}
 
Example #5
Source File: AbstractChartJrxmlHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void setValueAxisLabel(String chartText, String chartPlotText, ChartReportDTO chartReport)
        throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:" + chartText + "//a:" + chartPlotText +
            "//a:valueAxisLabelExpression");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    OMElement label = (OMElement) nodeList.get(0);

    label.setText("");
    OMFactory factory = document.getOMFactory();
    OMText cdataField = factory.createOMText(label, "\"" + chartReport.getyAxisLabel() + "\"",
            OMText.CDATA_SECTION_NODE);
    label.addChild(cdataField);

}
 
Example #6
Source File: AbstractChartJrxmlHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void setCategoryAxisLabel(String chartText, String chartPlotText, ChartReportDTO chartReport)
        throws JaxenException {
    AXIOMXPath xpathExpression = new AXIOMXPath("//a:title//a:" + chartText + "//a:" + chartPlotText +
            "//a:categoryAxisLabelExpression");
    xpathExpression.addNamespace("a", "http://jasperreports.sourceforge.net/jasperreports");
    OMElement documentElement = document.getOMDocumentElement();
    List nodeList = xpathExpression.selectNodes(documentElement);
    OMElement label = (OMElement) nodeList.get(0);

    label.setText("");
    OMFactory factory = document.getOMFactory();
    OMText cdataField = factory.createOMText(label, "\"" + chartReport.getxAxisLabel() + "\"",
            OMText.CDATA_SECTION_NODE);
    label.addChild(cdataField);

}
 
Example #7
Source File: ProvideAndRegisterDocumentSetTest.java    From openxds with Apache License 2.0 6 votes vote down vote up
/**
 * The 'document' node of a p&r might contain a whitespace node before the actual document data. This occurred, for example,
 * in a provide by ISC at the 2010 European Connectathon. This did not result in an error, but in an empty document to be
 * 'successfully' submitted.
 * 
 *  The p&r handler was modified to ignore whitespace nodes. This unittest tests this.
 * 
 * @throws IOException
 * @throws XMLStreamException
 */
@Test
public void testWhitespaceBeforeDocument() throws IOException, XMLStreamException
{
	String message = IOUtils.toString(ProvideAndRegisterDocumentSetTest.class.getResourceAsStream("/data/submit_document.xml"));
	String documentString = IOUtils.toString(ProvideAndRegisterDocumentSetTest.class.getResourceAsStream("/data/referral_summary.xml"));
	//replace document and submission set uniqueId variables with actual uniqueIds. 
	message = message.replace("$XDSDocumentEntry.uniqueId", "2.16.840.1.113883.3.65.2." + System.currentTimeMillis());
	message = message.replace("$XDSSubmissionSet.uniqueId", "1.3.6.1.4.1.21367.2009.1.2.108." + System.currentTimeMillis());
	//message = message.replace("$patientId", patientId);
	//replace the document uuid.
	//String uuid = getUUID();
	//message = message.replace("$doc1", uuid);

	for (Boolean includeWhitespace : new Boolean[] { false, true })
	{
		OMElement request = OMUtil.xmlStringToOM(message);
		request = addOneDocument(request, documentString, "doc1", includeWhitespace);

		for (OMElement document : MetadataSupport.childrenWithLocalName(request, "Document")) {
			OMText text = ProvideAndRegisterDocumentSet.getBinaryNode(document);
			assertTrue("Blank document. Included whitespace: " + includeWhitespace, StringUtils.isNotBlank(text.getText()));
		}
	}
}
 
Example #8
Source File: Mtom.java    From openxds with Apache License 2.0 6 votes vote down vote up
public void decode(OMElement document) throws XdsIOException, IOException {
	this.document = document;
	OMText binaryNode = (OMText) document.getFirstOMChild();
	//System.out.println("isOptimized: " + binaryNode.isOptimized());

	xop = binaryNode.isOptimized(); 
	
	if (xop) {
		javax.activation.DataHandler datahandler = (javax.activation.DataHandler) binaryNode.getDataHandler();
		InputStream is = null;
		try {
			is = datahandler.getInputStream();
			contents = Io.getBytesFromInputStream(is);
		}
		catch (IOException e) {
			throw new XdsIOException("Error accessing XOP encoded document content from message");
		}
		this.content_type = datahandler.getContentType();
	} else {
		String base64 = binaryNode.getText();
		contents = Base64.decodeBase64(base64.getBytes());
		this.content_type = null;
	}

}
 
Example #9
Source File: ParamParserTest.java    From openxds with Apache License 2.0 6 votes vote down vote up
void addSlot(String name, String value_string1, String value_string2) {
	OMElement slot = om_factory().createOMElement("Slot", null);
	adhocquery.addChild(slot);
	slot.addAttribute("name", name, null);
	OMElement valuelist = om_factory().createOMElement("ValueList", null);
	slot.addChild(valuelist);
	
	OMElement value1 = om_factory().createOMElement("Value", null);
	valuelist.addChild(value1);
	OMText text1 = om_factory().createOMText(value_string1);
	value1.addChild(text1);
	
	OMElement value2 = om_factory().createOMElement("Value", null);
	valuelist.addChild(value2);
	OMText text2 = om_factory().createOMText(value_string2);
	value2.addChild(text2);
}
 
Example #10
Source File: BinaryExtractMediator.java    From product-ei with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #11
Source File: SOAPClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a SOAP message with MTOM attachment and returns response as a OMElement.
 *
 * @param fileName   name of file to be sent as an attachment
 * @param targetEPR  service url
 * @param soapAction SOAP Action to set. Specify with "urn:"
 * @return OMElement response from BE service
 * @throws AxisFault in case of an invocation failure
 */
public OMElement sendSOAPMessageWithAttachment(String fileName, String targetEPR, String soapAction) throws AxisFault {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction(soapAction);
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    return serviceClient.sendReceive(payload);
}
 
Example #12
Source File: CallOutMediatorWithMTOMTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(
            "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">" + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
}
 
Example #13
Source File: ESBJAVA4909MultipartRelatedTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    final String EXPECTED = "<m0:uploadFileUsingMTOMResponse xmlns:m0=\"http://services.samples\"><m0:response>" +
            "<m0:image>PHByb3h5PkFCQzwvcHJveHk+</m0:image></m0:response></m0:uploadFileUsingMTOMResponse>";
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(EXPECTED), "Attachment is missing in the response");
}
 
Example #14
Source File: SwaggerUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Util method to fetch a swagger resource from the registry.
 *
 * @param resourcePath registry path to the resource.
 * @return null if no resource found or the swagger as string.
 */
public static String fetchSwaggerFromRegistry(String resourcePath) {

    String defString = null;
    SynapseConfiguration synapseConfig =
            SynapseConfigUtils.getSynapseConfiguration(Constants.SUPER_TENANT_DOMAIN_NAME);
    Registry registry = synapseConfig.getRegistry();
    OMNode regContent = registry.lookup(resourcePath);

    if (regContent instanceof OMText) {
        defString = ((OMText) regContent).getText();
        byte[] decodedBytes = Base64.getDecoder().decode(defString);
        defString = new String(decodedBytes);
    }
    return defString;
}
 
Example #15
Source File: SOAPClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Sends a SOAP message with MTOM attachment and returns response as a OMElement.
 *
 * @param fileName   name of file to be sent as an attachment
 * @param targetEPR  service url
 * @param soapAction SOAP Action to set. Specify with "urn:"
 * @return OMElement response from BE service
 * @throws AxisFault in case of an invocation failure
 */
public OMElement sendSOAPMessageWithAttachment(String fileName, String targetEPR, String soapAction) throws AxisFault {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction(soapAction);
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    return serviceClient.sendReceive(payload);
}
 
Example #16
Source File: MTOMSwASampleService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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());
    }
 
Example #17
Source File: ESBJAVA4909MultipartRelatedTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    final String EXPECTED = "<m0:uploadFileUsingMTOMResponse xmlns:m0=\"http://services.samples\"><m0:response>"
            + "<m0:image>PHByb3h5PkFCQzwvcHJveHk+</m0:image></m0:response></m0:uploadFileUsingMTOMResponse>";
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(EXPECTED), "Attachment is missing in the response");
}
 
Example #18
Source File: CallOutMediatorWithMTOMTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public void sendUsingMTOM(String fileName, String targetEPR) throws IOException {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "m0");
    OMElement payload = factory.createOMElement("uploadFileUsingMTOM", ns);
    OMElement request = factory.createOMElement("request", ns);
    OMElement image = factory.createOMElement("image", ns);

    FileDataSource fileDataSource = new FileDataSource(new File(fileName));
    DataHandler dataHandler = new DataHandler(fileDataSource);
    OMText textData = factory.createOMText(dataHandler, true);
    image.addChild(textData);
    request.addChild(image);
    payload.addChild(request);

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(targetEPR));
    options.setAction("urn:uploadFileUsingMTOM");
    options.setProperty(Constants.Configuration.ENABLE_MTOM, Constants.VALUE_TRUE);
    options.setCallTransportCleanup(true);
    serviceClient.setOptions(options);
    OMElement response = serviceClient.sendReceive(payload);
    Assert.assertTrue(response.toString().contains(
            "<m:testMTOM xmlns:m=\"http://services.samples/xsd\">" + "<m:test1>testMTOM</m:test1></m:testMTOM>"));
}
 
Example #19
Source File: MTOMSwASampleService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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());
    }
 
Example #20
Source File: BinaryExtractMediator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: MTOMSwASampleService.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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());
    }
 
Example #22
Source File: BinaryExtractMediator.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #23
Source File: DBUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves the registry key
 * This method uses SynapseEnvironment to resolve the keys
 *
 * @param synapseConfig      SynapseConfiguration
 * @param regEntryKey registry entry key to be resolved
 * @return Resolved reg entry
 */
private static String resolveRegistryEntryText(SynapseConfiguration synapseConfig, String regEntryKey) {
    Object regEntry = synapseConfig.getRegistry().lookup(regEntryKey);
    String resolvedValue = "";
    if (regEntry instanceof OMElement) {
        OMElement e = (OMElement) regEntry;
        resolvedValue = e.toString();
    } else if (regEntry instanceof OMText) {
        resolvedValue = ((OMText) regEntry).getText();
    } else if (regEntry instanceof String) {
        resolvedValue = (String) regEntry;
    }
    return resolvedValue;
}
 
Example #24
Source File: HL7MessageUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement generateHL7RawMessaegElement(String hl7XmlMessage) {
    OMElement hl7Element = omFactory.createOMElement(new QName("rawMessage"));
    OMText rawMessage = hl7Element.getOMFactory().createOMText(hl7Element, hl7XmlMessage, XMLStreamConstants.CDATA);
    hl7Element.addChild(rawMessage);
    OMElement messageEl = fac.createOMElement(Axis2HL7Constants.HL7_MESSAGE_ELEMENT_NAME, ns);
    messageEl.addChild(hl7Element);
    return messageEl;
}
 
Example #25
Source File: JMSReplySenderTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void setSOAPEnvelopWithBinaryBody(MessageContext messageContext, BytesMessage message) throws AxisFault {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    OMElement firstEle = fac.createOMElement(BaseConstants.DEFAULT_BINARY_WRAPPER);
    DataHandler dataHandler = new DataHandler(new BytesMessageDataSource(message));
    OMText textEle = fac.createOMText(dataHandler, true);
    firstEle.addChild(textEle);
    env.getBody().addChild(firstEle);
    messageContext.setEnvelope(env);
}
 
Example #26
Source File: JMSReplySenderTest.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private void setSOAPEnvelopWithoutTypeByteMessageBody(MessageContext messageContext, BytesMessage message)
        throws AxisFault {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    SOAPEnvelope env = fac.createSOAPEnvelope();
    fac.createSOAPBody(env);
    OMElement firstEle = fac.createOMElement(new QName("Binary"));
    DataHandler dataHandler = new DataHandler(new BytesMessageDataSource(message));
    OMText textEle = fac.createOMText(dataHandler, true);
    firstEle.addChild(textEle);
    env.getBody().addChild(firstEle);
    messageContext.setEnvelope(env);
}
 
Example #27
Source File: DOMHASHGenerator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This is an overloaded method for the digest generation for OMNode.
 *
 * @param node            - OMNode to be subjected to the key generation
 * @param digestAlgorithm - digest algorithm as a String
 * @return byte[] representing the calculated digest over the provided node
 * @throws CachingException if there is an error in generating the digest
 */
public byte[] getDigest(OMNode node, String digestAlgorithm) throws CachingException {

    if (node.getType() == OMNode.ELEMENT_NODE) {
        return getDigest((OMElement) node, digestAlgorithm);
    } else if (node.getType() == OMNode.TEXT_NODE) {
        return getDigest((OMText) node, digestAlgorithm);
    } else if (node.getType() == OMNode.PI_NODE) {
        return getDigest((OMProcessingInstruction) node, digestAlgorithm);
    } else {
        return new byte[0];
    }
}
 
Example #28
Source File: HttpRequestHashGenerator.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This is an overloaded method for the digest generation for OMNode and request.
 *
 * @param node            - OMNode to be subjected to the key generation
 * @param toAddress       - Request To address to be subjected to the key generation
 * @param headers         - Header parameters to be subjected to the key generation
 * @param digestAlgorithm - digest algorithm as a String
 * @return byte[] representing the calculated digest over the provided node
 * @throws CachingException if there is an error in generating the digest
 */
public byte[] getDigest(OMNode node, String toAddress, Map<String, String> headers,
                        String digestAlgorithm) throws CachingException {

    if (node.getType() == OMNode.ELEMENT_NODE) {
        return getDigest((OMElement) node, toAddress, headers, digestAlgorithm);
    } else if (node.getType() == OMNode.TEXT_NODE) {
        return getDigest((OMText) node, digestAlgorithm);
    } else if (node.getType() == OMNode.PI_NODE) {
        return getDigest((OMProcessingInstruction) node, digestAlgorithm);
    } else {
        return new byte[0];
    }
}
 
Example #29
Source File: AbstractChartJrxmlHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private void setValueExpr(String YField, OMElement categorySeriesElement, String yExpressionText)
        throws JaxenException {
    Iterator iter = categorySeriesElement.getChildrenWithName(new QName(yExpressionText));
    OMElement aValueExpr = (OMElement) iter.next();

    aValueExpr.setText("");
    OMFactory factory = document.getOMFactory();
    OMText cdataField = factory.createOMText(aValueExpr, "$F{" + YField + "}", OMText.CDATA_SECTION_NODE);
    aValueExpr.addChild(cdataField);

}
 
Example #30
Source File: AbstractChartJrxmlHandler.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
private void setCategoryExpr(String XField, OMElement categorySeriesElement, String xExpressionText)
        throws JaxenException {
    Iterator iter = categorySeriesElement.getChildrenWithName(new QName(xExpressionText));
    OMElement aCatExpr = (OMElement) iter.next();

    aCatExpr.setText("");
    OMFactory factory = document.getOMFactory();
    OMText cdataField = factory.createOMText(aCatExpr, "$F{" + XField + "}", OMText.CDATA_SECTION_NODE);
    aCatExpr.addChild(cdataField);

}