org.apache.axiom.om.OMAbstractFactory Java Examples

The following examples show how to use org.apache.axiom.om.OMAbstractFactory. 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: APIAuthenticationHandler.java    From docs-apim with Apache License 2.0 6 votes vote down vote up
private OMElement getFaultPayload(APISecurityException e) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace(APISecurityConstants.API_SECURITY_NS,
            APISecurityConstants.API_SECURITY_NS_PREFIX);
    OMElement payload = fac.createOMElement("fault", ns);

    OMElement errorCode = fac.createOMElement("code", ns);
    errorCode.setText(String.valueOf(e.getErrorCode()));
    OMElement errorMessage = fac.createOMElement("message", ns);
    errorMessage.setText(APISecurityConstants.getAuthenticationFailureMessage(e.getErrorCode()));
    OMElement errorDetail = fac.createOMElement("description", ns);
    errorDetail.setText(e.getMessage());

    payload.addChild(errorCode);
    payload.addChild(errorMessage);
    payload.addChild(errorDetail);
    return payload;
}
 
Example #2
Source File: IterateClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement createGetQuotesRequestBody(String symbol, int iterations) {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement top = fac.createOMElement("getQuotes", omNs);

    for (int i = 0; i < iterations; i++) {
        OMElement method = fac.createOMElement("getQuote", omNs);
        OMElement value1 = fac.createOMElement("request", omNs);
        OMElement value2 = fac.createOMElement("symbol", omNs);
        value2.addChild(fac.createOMText(value1, symbol));
        value1.addChild(value2);
        method.addChild(value1);
        top.addChild(method);
    }

    return top;
}
 
Example #3
Source File: OutputMappingAsAttributeDataServiceTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement getPayloadAddOffice(String officeCode, String city, String state, String territory) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice", "ns1");
    OMElement payload = fac.createOMElement("addOffice", omNs);

    OMElement officeCodeOme = fac.createOMElement("officeCode", omNs);
    officeCodeOme.setText(officeCode);
    payload.addChild(officeCodeOme);

    OMElement cityOme = fac.createOMElement("city", omNs);
    cityOme.setText(city);
    payload.addChild(cityOme);

    OMElement stateOme = fac.createOMElement("state", omNs);
    stateOme.setText(state);
    payload.addChild(stateOme);

    OMElement territoryOme = fac.createOMElement("territory", omNs);
    territoryOme.setText(territory);
    payload.addChild(territoryOme);

    return payload;
}
 
Example #4
Source File: WSXACMLMessageReceiver.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope createDefaultSOAPEnvelope(MessageContext inMsgCtx) {

        String soapNamespace = inMsgCtx.getEnvelope().getNamespace()
                .getNamespaceURI();
        SOAPFactory soapFactory = null;
        if (soapNamespace.equals(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP11Factory();
        } else if (soapNamespace
                .equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
            soapFactory = OMAbstractFactory.getSOAP12Factory();
        } else {
            log.error("Unknown SOAP Envelope");
        }
        if (soapFactory != null) {
            return soapFactory.getDefaultEnvelope();
        }

        return null;
    }
 
Example #5
Source File: StockQuoteHandler.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new market activity request with a body as follows
 *  <m:getMarketActivity xmlns:m="http://services.samples">
 *      <m:request>
 *          <m:symbol>IBM</m:symbol>
 *          ...
 *          <m:symbol>MSFT</m:symbol>
 *      </m:request>
 *  </m:getMarketActivity>
 * @return OMElement for SOAP body
 */
public static OMElement createMarketActivityRequest() {
    OMFactory factory   = OMAbstractFactory.getOMFactory();
    OMNamespace ns      = factory.createOMNamespace("http://services.samples", "m0");
    OMElement getQuote  = factory.createOMElement("getMarketActivity", ns);
    OMElement request   = factory.createOMElement("request", ns);

    OMElement symb = null;
    for (int i=0; i<100; i++) {
        symb = factory.createOMElement("symbols", ns);
        symb.setText(randomString(3));
        request.addChild(symb);
    }

    getQuote.addChild(request);
    return getQuote;
}
 
Example #6
Source File: AGSpreadDataServiceTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.dss" }, invocationCount = 5, enabled = false)
public void selectOperation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac
            .createOMNamespace("http://ws.wso2.org/dataservice/samples/gspread_sample_service", "ns1");
    OMElement payload = fac.createOMElement("getCustomers", omNs);

    OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "getcustomers");
    log.info("Response : " + result);
    Assert.assertTrue((result.toString().indexOf("Customers") == 1),
            "Expected Result not found on response message");
    Assert.assertTrue(result.toString().contains("<customerNumber>"),
            "Expected Result not found on response message");
    Assert.assertTrue(result.toString().contains("</Customer>"), "Expected Result not found on response message");

    log.info("Service Invocation success");
}
 
Example #7
Source File: NestedAggregatesTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private OMElement createNestedQuoteRequestBody(String symbol, int noOfItr) {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method1 = fac.createOMElement("getQuotes", omNs);
    for (int i = 0; i < noOfItr; i++) {
        OMElement method2 = fac.createOMElement("getQuote", omNs);

        for (int j = 0; j < noOfItr; j++) {
            OMElement value1 = fac.createOMElement("request", omNs);
            OMElement value2 = fac.createOMElement("symbol", omNs);
            value2.addChild(fac.createOMText(value1, symbol));
            value1.addChild(value2);
            method2.addChild(value1);

        }
        method1.addChild(method2);
    }
    return method1;
}
 
Example #8
Source File: OutputMappingAsAttributeDataServiceTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private OMElement getPayloadAddOffice(String officeCode, String city, String state,
                                      String territory) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice", "ns1");
    OMElement payload = fac.createOMElement("addOffice", omNs);

    OMElement officeCodeOme = fac.createOMElement("officeCode", omNs);
    officeCodeOme.setText(officeCode);
    payload.addChild(officeCodeOme);

    OMElement cityOme = fac.createOMElement("city", omNs);
    cityOme.setText(city);
    payload.addChild(cityOme);

    OMElement stateOme = fac.createOMElement("state", omNs);
    stateOme.setText(state);
    payload.addChild(stateOme);

    OMElement territoryOme = fac.createOMElement("territory", omNs);
    territoryOme.setText(territory);
    payload.addChild(territoryOme);

    return payload;
}
 
Example #9
Source File: ESBJAVA4792AggregateTimeoutTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement getSleepOperationRequestForIterator() throws XMLStreamException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement omeSleep = fac.createOMElement("sleepOperation", null);
    OMElement omeLoad1 = fac.createOMElement("load", null);
    omeLoad1.setText("1000");
    omeSleep.addChild(omeLoad1);

    OMElement omeLoad2 = fac.createOMElement("load", null);
    omeLoad2.setText("1000");
    omeSleep.addChild(omeLoad2);

    OMElement omeLoad3 = fac.createOMElement("load", null);
    omeLoad3.setText("8000");
    omeSleep.addChild(omeLoad3);

    return omeSleep;

}
 
Example #10
Source File: GraphQLAPIHandler.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * @param description description of the error
 * @return the OMElement
 */
private OMElement getFaultPayload(String description) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace(APISecurityConstants.API_SECURITY_NS,
            APISecurityConstants.API_SECURITY_NS_PREFIX);
    OMElement payload = fac.createOMElement("fault", ns);

    OMElement errorCode = fac.createOMElement("code", ns);
    errorCode.setText(APISecurityConstants.GRAPHQL_INVALID_QUERY + "");
    OMElement errorMessage = fac.createOMElement("message", ns);
    errorMessage.setText(APISecurityConstants.GRAPHQL_INVALID_QUERY_MESSAGE);
    OMElement errorDetail = fac.createOMElement("description", ns);
    errorDetail.setText(description);

    payload.addChild(errorCode);
    payload.addChild(errorMessage);
    payload.addChild(errorDetail);
    return payload;
}
 
Example #11
Source File: StockQuoteHandler.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new order for a quantiry of a stock at a given price
 * <m:placeOrder xmlns:m="http://services.samples">
 *	  <m:order>
 *	      <m:price>3.141593E0</m:price>
 *	      <m:quantity>4</m:quantity>
 *	      <m:symbol>IBM</m:symbol>
 *    </m:order>
 * 	</m:placeOrder>
 *
 * @param purchPrice the purchase price
 * @param qty the quantiry
 * @param symbol the stock
 * @return an OMElement payload for the order
 */
public static OMElement createPlaceOrderRequest(double purchPrice, int qty, String symbol) {
    OMFactory factory   = OMAbstractFactory.getOMFactory();
    OMNamespace ns      = factory.createOMNamespace("http://services.samples", "m0");
    OMElement placeOrder= factory.createOMElement("placeOrder", ns);
    OMElement order     = factory.createOMElement("order", ns);
    OMElement price     = factory.createOMElement("price", ns);
    OMElement quantity  = factory.createOMElement("quantity", ns);
    OMElement symb      = factory.createOMElement("symbol", ns);
    price.setText(Double.toString(purchPrice));
    quantity.setText(Integer.toString(qty));
    symb.setText(symbol);
    order.addChild(price);
    order.addChild(quantity);
    order.addChild(symb);
    placeOrder.addChild(order);        
    return placeOrder;
}
 
Example #12
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private SOAPEnvelope buildSoapEnvelope(String clientID, String value) {
    SOAPFactory soapFactory = OMAbstractFactory.getSOAP12Factory();

    SOAPEnvelope envelope = soapFactory.createSOAPEnvelope();

    SOAPHeader header = soapFactory.createSOAPHeader();
    envelope.addChild(header);

    OMNamespace synNamespace = soapFactory.
            createOMNamespace("http://ws.apache.org/ns/synapse", "syn");
    OMElement clientIDElement = soapFactory.createOMElement("ClientID", synNamespace);
    clientIDElement.setText(clientID);
    header.addChild(clientIDElement);

    SOAPBody body = soapFactory.createSOAPBody();
    envelope.addChild(body);

    OMElement valueElement = soapFactory.createOMElement("Value", null);
    valueElement.setText(value);
    body.addChild(valueElement);

    return envelope;
}
 
Example #13
Source File: GraphQLQueryAnalysisHandler.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * @param errorCodeValue error code
 * @param message        fault message
 * @param description    description of the fault message
 * @return the OMElement
 */
private OMElement getFaultPayload(int errorCodeValue, String message, String description) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace(APISecurityConstants.API_SECURITY_NS,
            APISecurityConstants.API_SECURITY_NS_PREFIX);
    OMElement payload = fac.createOMElement("fault", ns);

    OMElement errorCode = fac.createOMElement("code", ns);
    errorCode.setText(errorCodeValue + "");
    OMElement errorMessage = fac.createOMElement("message", ns);
    errorMessage.setText(message);
    OMElement errorDetail = fac.createOMElement("description", ns);
    errorDetail.setText(description);

    payload.addChild(errorCode);
    payload.addChild(errorMessage);
    payload.addChild(errorDetail);
    return payload;
}
 
Example #14
Source File: TableReportMetaDataHandler.java    From carbon-commons with Apache License 2.0 6 votes vote down vote up
private void createTableReportColumnData(int id, ColumnDTO column) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement columnElement = fac.createOMElement(new QName(COLUMN));

    OMElement columnId = fac.createOMElement(new QName(COLUMN_ID));
    columnId.setText(String.valueOf(id));
    columnElement.addChild(columnId);

    OMElement columnTable = fac.createOMElement(new QName(COLUMN_DATA_TABLE));
    columnTable.setText(column.getColumnFamilyName());
    columnElement.addChild(columnTable);

    OMElement columnField = fac.createOMElement(new QName(COLUMN_DATA_FIELD));
    columnField.setText(column.getColumnName());
    columnElement.addChild(columnField);

    OMElement primaryColElement = fac.createOMElement(new QName(PRIMARY_COLUMN));
    if (column.isPrimaryColumn()) {
        primaryColElement.setText(PRIMARY_COLUMN_TRUE);
    } else {
        primaryColElement.setText(PRIMARY_COLUMN_FALSE);
    }
    columnElement.addChild(primaryColElement);

    tableReportElement.addChild(columnElement);
}
 
Example #15
Source File: TestUtils.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static OMElement getPayload(String opName,
		Map<String, String> params) {
	OMFactory omFac = OMAbstractFactory.getOMFactory();
	OMNamespace omNs = omFac.createOMNamespace(
			"http://example1.org/example1", "example1");
	OMElement method = omFac.createOMElement(opName, omNs);

	if (params != null) {
		OMElement paramEl = null;
		for (String key : params.keySet()) {
			paramEl = omFac.createOMElement(key, omNs);
			paramEl.setText(params.get(key));
			method.addChild(paramEl);
		}
	}
	return method;
}
 
Example #16
Source File: Sample701TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement createPayload() {   // creation of payload for placeOrder

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://services.samples", "urn");
        OMNamespace xsdNs = fac.createOMNamespace("http://services.samples", "xsd");
        OMElement payload = fac.createOMElement("placeOrder", omNs);
        OMElement order = fac.createOMElement("order", omNs);

        OMElement price = fac.createOMElement("price", xsdNs);
        price.setText("10");
        OMElement quantity = fac.createOMElement("quantity", xsdNs);
        quantity.setText("100");
        OMElement symbol = fac.createOMElement("symbol", xsdNs);
        symbol.setText("WSO2");

        order.addChild(price);
        order.addChild(quantity);
        order.addChild(symbol);
        payload.addChild(order);
        return payload;
    }
 
Example #17
Source File: Sample705TestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
private OMElement createPayload() {   // creation of payload for placeOrder

        OMFactory fac = OMAbstractFactory.getOMFactory();
        OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ser");
        OMNamespace xsdNs = fac.createOMNamespace("http://services.samples", "xsd");
        OMElement payload = fac.createOMElement("placeOrder", omNs);
        OMElement order = fac.createOMElement("order", omNs);

        OMElement price = fac.createOMElement("price", xsdNs);
        price.setText("10");
        OMElement quantity = fac.createOMElement("quantity", xsdNs);
        quantity.setText("100");
        OMElement symbol = fac.createOMElement("symbol", xsdNs);
        symbol.setText("WSO2");

        order.addChild(price);
        order.addChild(quantity);
        order.addChild(symbol);
        payload.addChild(order);
        return payload;
    }
 
Example #18
Source File: PolicyUtil.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public static OMElement getPolicyAsOMElement(Policy policy) {

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
            policy.serialize(writer);
            writer.flush();
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            XMLStreamReader xmlStreamReader =
                    XMLInputFactory.newInstance().createXMLStreamReader(bais);
            StAXOMBuilder staxOMBuilder =
                    (StAXOMBuilder) OMXMLBuilderFactory.createStAXOMBuilder(
                            OMAbstractFactory.getOMFactory(), xmlStreamReader);
            return staxOMBuilder.getDocumentElement();

        } catch (Exception ex) {
            throw new RuntimeException("can't convert the policy to an OMElement", ex);
        }
    }
 
Example #19
Source File: DataServiceSqlDriverTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement deleteRecord(String idNum) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice", "dat");
    OMElement payload = fac.createOMElement("delete", omNs);
    OMElement id = fac.createOMElement("id", omNs);
    id.setText(idNum);
    payload.addChild(id);

    return payload;
}
 
Example #20
Source File: GSpreadDataServiceTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.dss"}, invocationCount = 5, enabled = true)
public void selectOperation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice/samples/gspread_sample_service", "ns1");
    OMElement payload = fac.createOMElement("getCustomers", omNs);

    OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "getcustomers");
    log.info("Response : " + result);
    Assert.assertTrue((result.toString().indexOf("Customers") == 1), "Expected Result not found on response message");
    Assert.assertTrue(result.toString().contains("<customerNumber>"), "Expected Result not found on response message");
    Assert.assertTrue(result.toString().contains("</Customer>"), "Expected Result not found on response message");


    log.info("Service Invocation success");
}
 
Example #21
Source File: WSEventDispatcher.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void notify(Message message, Subscription subscription) {

        String endpoint = subscription.getEventSinkURL();

        String topic = subscription.getTopicName();
        OMFactory factory = OMAbstractFactory.getOMFactory();
        OMNamespace topicNs = factory.createOMNamespace(
                EventingConstants.NOTIFICATION_NS_URI,
                EventingConstants.NOTIFICATION_NS_PREFIX);
        OMElement topicEle = factory.createOMElement(EventingConstants.WSE_EN_TOPIC, topicNs);
        topicEle.setText(topic);
        
        OMElement domainElement = null;
        String tenantDomain = message.getProperty(MultitenantConstants.TENANT_DOMAIN_HEADER_NAME);
        if (tenantDomain != null) {
            OMNamespace domainNs = factory.createOMNamespace(MultitenantConstants.TENANT_DOMAIN_HEADER_NAMESPACE, null);
            domainElement = factory.createOMElement(MultitenantConstants.TENANT_DOMAIN_HEADER_NAME, domainNs);
            domainElement.setText(tenantDomain);
        }



        OMElement payload = message.getMessage().cloneOMElement();

        try {
            sendNotification(topicEle, domainElement, payload, endpoint);
        } catch (Exception e) {
            log.error("Unable to send message", e);
        }
    }
 
Example #22
Source File: SOAPEventHandler.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
private void sendError(HttpServletResponse res, Object object, String serviceName) throws EventHandlerException {
    try {
        // setup the response
        res.setContentType("text/xml");
        String xmlResults= SoapSerializer.serialize(object);
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xmlResults));
        StAXOMBuilder resultsBuilder = (StAXOMBuilder) OMXMLBuilderFactory.createStAXOMBuilder(OMAbstractFactory.getOMFactory(), xmlReader);
        OMElement resultSer = resultsBuilder.getDocumentElement();

        // create the response soap
        SOAPFactory factory = OMAbstractFactory.getSOAP11Factory();
        SOAPEnvelope resEnv = factory.createSOAPEnvelope();
        SOAPBody resBody = factory.createSOAPBody();
        OMElement errMsg = factory.createOMElement(new QName((serviceName != null ? serviceName : "") + "Response"));
        errMsg.addChild(resultSer.getFirstElement());
        resBody.addChild(errMsg);
        resEnv.addChild(resBody);

        // The declareDefaultNamespace method doesn't work see (https://issues.apache.org/jira/browse/AXIS2-3156)
        // so the following doesn't work:
        // resService.declareDefaultNamespace(ModelService.TNS);
        // instead, create the xmlns attribute directly:
        OMAttribute defaultNS = factory.createOMAttribute("xmlns", null, ModelService.TNS);
        errMsg.addAttribute(defaultNS);

        // log the response message
        if (Debug.verboseOn()) {
            try {
                Debug.logInfo("Response Message:\n" + resEnv + "\n", module);
            } catch (Throwable t) {
            }
        }

        resEnv.serialize(res.getOutputStream());
        res.getOutputStream().flush();
    } catch (Exception e) {
        throw new EventHandlerException(e.getMessage(), e);
    }
}
 
Example #23
Source File: ExcelDataServiceTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.dss" }, invocationCount = 5)
public void selectOperation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice", "ns1");
    OMElement payload = fac.createOMElement("getProducts", omNs);
    OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "getProducts");
    log.info("Response :" + result);
    Assert.assertTrue((result.toString().indexOf("Products") == 1), "Expected Result Not found");
    Assert.assertTrue(result.toString().contains("<Product>"), "Expected Result Not found");
    Assert.assertTrue(result.toString().contains("<ID>"), "Expected Result Not found");
    Assert.assertTrue(result.toString().contains("<Name>"), "Expected Result Not found");

    log.info("Service invocation success");
}
 
Example #24
Source File: ScheduleGetFacilitiesById.java    From garoon-google with MIT License 5 votes vote down vote up
@Override
public OMElement getParameters() {
       OMFactory omFactory = OMAbstractFactory.getOMFactory();
       OMElement parameters = omFactory.createOMElement("parameters", null);

       for( Integer id : ids )
       {
        OMElement eventNode = omFactory.createOMElement("facility_id", null);
        eventNode.setText( String.valueOf(id) );
        parameters.addChild( eventNode );
       }

	return parameters;
}
 
Example #25
Source File: MicroIntegratorRegistry.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Function to retrieve resource content as text
 *
 * @param url
 * @return
 * @throws IOException
 */
private OMNode readNonXML (URL url) throws IOException {

    URLConnection urlConnection = url.openConnection();
    urlConnection.connect();

    try (InputStream inputStream = urlConnection.getInputStream()) {

        if (inputStream == null) {
            return null;
        }

        String mediaType = DEFAULT_MEDIA_TYPE;
        Properties metadata = getMetadata(url.getPath());
        if (metadata != null) {
            mediaType = metadata.getProperty(METADATA_KEY_MEDIA_TYPE, DEFAULT_MEDIA_TYPE);
        }

        if (DEFAULT_MEDIA_TYPE.equals(mediaType)) {
            StringBuilder strBuilder = new StringBuilder();
            try (BufferedReader bReader = new BufferedReader(new InputStreamReader(inputStream))) {
                String line;
                while ((line = bReader.readLine()) != null) {
                    strBuilder.append(line);
                }
            }
            return OMAbstractFactory.getOMFactory().createOMText(strBuilder.toString());
        } else {
            return OMAbstractFactory.getOMFactory()
                    .createOMText(new DataHandler(new SynapseBinaryDataSource(inputStream, mediaType)), true);
        }
    }
}
 
Example #26
Source File: EnrichIntegrationReplaceBodyUsingXpathTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement createStandardRequest(String symbol) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "m");
    OMElement method = fac.createOMElement("getQuote", omNs);
    OMElement value1 = fac.createOMElement("testRequest", omNs);
    OMElement value2 = fac.createOMElement("testSymbol", omNs);

    value2.addChild(fac.createOMText(value1, symbol));
    value1.addChild(value2);
    method.addChild(value1);

    return method;
}
 
Example #27
Source File: TransportBuilderUtils.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public static OMElement serializeTransportListener(TransportInDescription transport) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement transportReceiver = fac.createOMElement(new QName(TAG_TRANSPORT_RECEIVER));
    transportReceiver.addAttribute(ATTRIBUTE_NAME, transport.getName(), null);
    transportReceiver.addAttribute(ATTRIBUTE_CLASS, transport.getReceiver().
            getClass().getName(), null);

    serializeParameters(transport, transportReceiver, fac);
    return transportReceiver;
}
 
Example #28
Source File: DataServiceProcessor.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private static OMElement generateRequestSuccessElement() {
	OMFactory fac = OMAbstractFactory.getOMFactory();
	OMElement result = fac.createOMElement(new QName(DBConstants.WSO2_DS_NAMESPACE,
               DBConstants.REQUEST_STATUS_WRAPPER_ELEMENT));
	result.setText(DBConstants.REQUEST_STATUS_SUCCESSFUL_MESSAGE);
	OMDocument doc = fac.createOMDocument();
	doc.addChild(result);
	return doc.getOMDocumentElement();
}
 
Example #29
Source File: EnrichIntegrationReplaceEnvelopeWithPropertyTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private OMElement createQuoteRequestBody(String symbol) {
    SOAPFactory fac = OMAbstractFactory.getSOAP11Factory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);

    OMElement value1 = fac.createOMElement("request", omNs);
    OMElement value2 = fac.createOMElement("symbol", omNs);
    value2.addChild(fac.createOMText(value1, symbol));
    value1.addChild(value2);
    method.addChild(value1);

    return method;
}
 
Example #30
Source File: GSpreadSQLDriverSampleTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private OMElement deleteCustomer() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac
            .createOMNamespace("http://ws.wso2.org/dataservice/samples/" + "gspread_sql_driver_sample_service",
                    "gsp");
    OMElement deleteCustomerSQL = fac.createOMElement("deleteCustomerSQL", omNs);
    OMElement customerNumber = fac.createOMElement("customerNumber", omNs);

    customerNumber.setText(inputValue);
    deleteCustomerSQL.addChild(customerNumber);
    return deleteCustomerSQL;
}