Java Code Examples for org.apache.axiom.om.OMFactory#createOMNamespace()

The following examples show how to use org.apache.axiom.om.OMFactory#createOMNamespace() . 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: 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 2
Source File: ESBJAVA_4239_AccessHTTPSCAfterCallout.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ExcelSampleServiceTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.dss"}, invocationCount = 5, dependsOnMethods = "selectOperation")
public void xsltTransformation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice", "ns1");
    OMElement payload = fac.createOMElement("getProductClassifications", omNs);
    OMElement result = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "getProductClassifications");
    if (log.isDebugEnabled()) {
        log.debug("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("<Product-Name>"), "Expected Result Not found");
    Assert.assertTrue(result.toString().contains("<Product-Classification>"), "Expected Result Not found");

    log.info("XSLT Transformation Success");
}
 
Example 4
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 5
Source File: APIThrottleHandler.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
private OMElement getFaultPayload(int throttleErrorCode, String message, String description) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace(APIThrottleConstants.API_THROTTLE_NS,
                                           APIThrottleConstants.API_THROTTLE_NS_PREFIX);
    OMElement payload = fac.createOMElement("fault", ns);

    OMElement errorCode = fac.createOMElement("code", ns);
    errorCode.setText(String.valueOf(throttleErrorCode));
    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 6
Source File: EventingSampleTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement getAddPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice/samples/eventing_sample", "even");

    OMElement productCodeId = fac.createOMElement("productCode", omNs);
    OMElement productLine = fac.createOMElement("productLine", omNs);
    OMElement productName = fac.createOMElement("productName", omNs);
    OMElement quantityInStock = fac.createOMElement("quantityInStock", omNs);
    OMElement buyPrice = fac.createOMElement("buyPrice", omNs);

    productCodeId.setText(productCode);
    productLine.setText("Line1");
    productName.setText("TestProduct");
    quantityInStock.setText("100");
    buyPrice.setText("100.00");

    OMElement addProduct = fac.createOMElement("addProduct", omNs);
    addProduct.addChild(productCodeId);
    addProduct.addChild(productLine);
    addProduct.addChild(productName);
    addProduct.addChild(quantityInStock);
    addProduct.addChild(buyPrice);

    return addProduct;
}
 
Example 7
Source File: LoadbalanceFailoverClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This method is used to send a single request to the load balancing service which will invoke a sleep in the service
 * @param proxyURL will be the location where load balancing proxy or sequence is defined.
 * @param sleepTimeInMilliSeconds
 * @param clientTimeoutInMilliSeconds
 * @return
 * @throws org.apache.axis2.AxisFault
 */
public String sendSleepRequest(String proxyURL,String sleepTimeInMilliSeconds, String clientTimeoutInMilliSeconds) throws AxisFault {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement sleepOperation = fac.createOMElement("sleepOperation", omNs);
    OMElement load = fac.createOMElement("load",null);
    load.setText(sleepTimeInMilliSeconds);
    sleepOperation.addChild(load);



    Options options = new Options();
    if (proxyURL != null && !"null".equals(proxyURL)) {
        options.setTo(new EndpointReference(proxyURL));
    }

    options.setAction("urn:sleepOperation");

    long timeout = Integer.parseInt(getProperty("timeout", clientTimeoutInMilliSeconds));
    System.out.println("timeout=" + timeout);
    options.setTimeOutInMilliSeconds(timeout);

    serviceClient.setOptions(options);

    serviceClient.getOptions().setManageSession(true);
     OMElement responseElement = serviceClient.sendReceive(sleepOperation);
    String response = responseElement.getText();

    return response;
}
 
Example 8
Source File: InMemoryDSSampleTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.dss"}, invocationCount = 5, dependsOnMethods = "testServiceDeployment")
public void selectOperation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://www.w3.org/2005/08/addressing", "ns1");
    OMElement payload = fac.createOMElement("getAllUsers", omNs);

    OMElement result = new AxisServiceClient().sendReceive(payload, serviceUrl, "getAllUsers");
    Assert.assertTrue(result.toString().contains("Will Smith"));
    Assert.assertTrue(result.toString().contains("Denzel Washington"));

    log.info("Service invocation success");
}
 
Example 9
Source File: InMemoryDSSampleTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = { "wso2.dss" }, invocationCount = 5, dependsOnMethods = "testServiceDeployment")
public void selectOperation() throws AxisFault, XPathExpressionException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://www.w3.org/2005/08/addressing", "ns1");
    OMElement payload = fac.createOMElement("getAllUsers", omNs);

    OMElement result = new AxisServiceClient().sendReceive(payload, serviceUrl, "getAllUsers");
    Assert.assertTrue(result.toString().contains("Will Smith"));
    Assert.assertTrue(result.toString().contains("Denzel Washington"));

    log.info("Service invocation success");
}
 
Example 10
Source File: ParameterUtil.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create an Axis2 parameter based on key and value.
 *
 * @param name
 * @param value
 * @return Parameter
 * @throws AxisFault
 */
public static Parameter createParameter(String name, String value) throws AxisFault {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace ns = fac.createOMNamespace("", "");
    OMElement paramEle = fac.createOMElement("parameter", ns);

    if (name == null) {
        throw new AxisFault("Parameter name is madatory.");
    }
    paramEle.addAttribute("name", name, ns);
    if (value != null && value.length() != 0) {
        paramEle.setText(value);
    }
    return createParameter(paramEle);
}
 
Example 11
Source File: AGSpreadDataServiceTestCase.java    From product-ei with Apache License 2.0 5 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 12
Source File: MultipleServicesGeneratorTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement getPayloadService2() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://wso2.example.org", "wso2");

    OMElement payload = fac.createOMElement("select_with_key_REG_PROPERTY_operation", omNs);
    OMElement id = fac.createOMElement("REG_ID", omNs);
    id.setText("1");
    payload.addChild(id);
    return payload;
}
 
Example 13
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement createStandardSimpleRequest(String symbol) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getSimpleQuote", omNs);
    OMElement value1 = fac.createOMElement("symbol", omNs);

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

    return method;
}
 
Example 14
Source File: Utils.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public static OMElement getIncorrectRequest(String stringValue) {
	OMFactory fac = OMAbstractFactory.getOMFactory();
	OMNamespace omNs = fac.createOMNamespace(
			"http://echo.services.core.carbon.wso2.org", "echo");
	OMElement method = fac.createOMElement("echoInt", omNs);
	OMElement value1 = fac.createOMElement("in", omNs);
	value1.setText(stringValue);
	method.addChild(value1);
	return method;
}
 
Example 15
Source File: StockQuoteHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new custom quote request with a body as follows
 * <m0:CheckPriceRequest xmlns:m0="http://services.samples">
 *   <m0:Code>symbol</m0:Code>
 * </m0:CheckPriceRequest>
 * @param symbol the stock symbol
 * @return OMElement for SOAP body
 */
public static OMElement createCustomQuoteRequest(String symbol) {
    OMFactory factory   = OMAbstractFactory.getOMFactory();
    OMNamespace ns      = factory.createOMNamespace(
        "http://services.samples", "m0");
    OMElement chkPrice  = factory.createOMElement("CheckPriceRequest", ns);
    OMElement code      = factory.createOMElement("Code", ns);
    chkPrice.addChild(code);
    code.setText(symbol);
    return chkPrice;
}
 
Example 16
Source File: StockQuoteHandler.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new custom quote request with a body as follows
 * <m0:CheckPriceRequest xmlns:m0="http://services.samples">
 *   <m0:Code>symbol</m0:Code>
 * </m0:CheckPriceRequest>
 * @param symbol the stock symbol
 * @return OMElement for SOAP body
 */
public static OMElement createCustomQuoteRequest(String symbol) {
    OMFactory factory   = OMAbstractFactory.getOMFactory();
    OMNamespace ns      = factory.createOMNamespace(
        "http://services.samples", "m0");
    OMElement chkPrice  = factory.createOMElement("CheckPriceRequest", ns);
    OMElement code      = factory.createOMElement("Code", ns);
    chkPrice.addChild(code);
    code.setText(symbol);
    return chkPrice;
}
 
Example 17
Source File: HeaderFactory.java    From garoon-google with MIT License 5 votes vote down vote up
/**
 * ヘッダ全体を表すノードを生成します。
 * @return org.apache.axiom.om.OMElement ヘッダ
 */
private static OMElement getHeaderElement() {
    OMFactory omFactory = OMAbstractFactory.getOMFactory();
    OMNamespace headerNs = omFactory.createOMNamespace(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI, "soapenv");
    OMElement soapHeader = omFactory.createOMElement("Header", headerNs);

    return soapHeader;
}
 
Example 18
Source File: ServiceChainingTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement createStandardSimpleRequest(String symbol)
{
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getSimpleQuote", omNs);
    OMElement value1 = fac.createOMElement("symbol", omNs);

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

    return method;
}
 
Example 19
Source File: SQLDriverGspreadSheetTestCase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
private OMElement dropSheetSQLPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice/samples/" +
                                             "gspread_sql_driver_sample_service", "gsp");
    return fac.createOMElement("dropSheetSQL", omNs);
}
 
Example 20
Source File: SecureDataServiceSampleTestCase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
private OMElement getPayload() {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://ws.wso2.org/dataservice/samples/secure_dataservice", "ns1");
    return fac.createOMElement("showAllOffices", omNs);
}