Java Code Examples for org.apache.axiom.om.OMElement#setText()

The following examples show how to use org.apache.axiom.om.OMElement#setText() . 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: 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 2
Source File: ParameterUtil.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Create an Axis2 parameter based using param name, value and whether it is locked
 *
 * @param name - name of the parameter
 * @param value - value of the parameter
 * @param locked - whether it is a locked param
 * @return Parameter instance
 * @throws AxisFault - error while creating param
 */
public static Parameter createParameter(String name, String value, boolean locked) 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 (locked) {
        paramEle.addAttribute("locked", "true", ns);
    }
    if (value != null && value.length() != 0) {
        paramEle.setText(value);
    }
    return createParameter(paramEle);
}
 
Example 3
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Create place order request
 *
 * @param purchasePrice purchase price
 * @param qty           quantity
 * @param symbol        symbol
 * @return OMElement of request
 */
public OMElement createPlaceOrderRequest(double purchasePrice, 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(purchasePrice));
    quantity.setText(Integer.toString(qty));
    symb.setText(symbol);
    order.addChild(price);
    order.addChild(quantity);
    order.addChild(symb);
    placeOrder.addChild(order);
    return placeOrder;
}
 
Example 4
Source File: Query.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private OMElement createOMElementFromInputParams(InternalParamCollection params) {
	OMFactory fac = DBUtils.getOMFactory();
	OMDocument doc = fac.createOMDocument();
	OMElement retEl = fac.createOMElement(new QName(this.getQueryId()));
	OMElement scalarEl;
	List<OMElement> arrayEl;
	ParamValue paramValue;
	for (InternalParam param : params.getParams()) {
		paramValue = param.getValue();
		if (paramValue.getValueType() == ParamValue.PARAM_VALUE_SCALAR ||
				paramValue.getValueType() == ParamValue.PARAM_VALUE_UDT) {
			scalarEl = fac.createOMElement(new QName(param.getName()));
			scalarEl.setText(paramValue.getScalarValue());
			retEl.addChild(scalarEl);
		} else if (paramValue.getValueType() == ParamValue.PARAM_VALUE_ARRAY) {
			arrayEl = this.createOMElementsFromArrayValue(param.getName(), paramValue, fac);
			for (OMElement el : arrayEl) {
				retEl.addChild(el);
			}
		}
	}
	doc.addChild(retEl);
	return doc.getOMDocumentElement();
}
 
Example 5
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 6
Source File: BatchRequestTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private String employeeExists(String empId) throws AxisFault, XPathExpressionException {
    OMElement payload = fac.createOMElement("employeeExists", omNs);

    OMElement empNo = fac.createOMElement("employeeNumber", omNs);
    empNo.setText(empId);
    payload.addChild(empNo);

    OMElement response = new AxisServiceClient().sendReceive(payload, getServiceUrlHttp(serviceName), "employeeExists");
    assertNotNull("Response null " + response);
    return response.getFirstElement().getFirstElement().getText();
}
 
Example 7
Source File: SqlRepair.java    From openxds with Apache License 2.0 5 votes vote down vote up
public void repair(OMElement query) throws XdsInternalException, SqlRepairException {
		OMElement query_element = find_sql_query_element(query);
		String sql_text = query_element.getText().trim();
		
		OMElement response_option_ele = MetadataSupport.firstChildWithLocalName(query, "ResponseOption");
		if (response_option_ele == null)
			throw new SqlRepairException("Cannot find ResponseOption element");
		String return_type = response_option_ele.getAttributeValue(MetadataSupport.return_type_qname);
		if (return_type == null) 
			throw new SqlRepairException("Cannot find returnType option of ResponseOption");
		
		if (!return_type.equals("ObjectRef") && !return_type.equals("LeafClass") )
			throw new SqlRepairException("Invalid returnType: only ObjectRef or LeafClass are acceptable");

		String x = sql_text.replaceAll("\\(", " ( ");
		x = x.replaceAll("\\)", " ) ");
		String[] words = x.split("[ \t\n]");

		boolean repaired = true;
		int i = 0;
		start_at_word = 0;
		for ( ; i<20 && repaired; i++) {
//			System.out.println("fix?");
			 repaired = repair_once(words, return_type);
//			 if (repaired) {
//				 System.out.print("Fixed: ");
//				 for (int j=0; j<words.length; j++) System.out.print(" " + words[j]);
//				 System.out.println("");
//			 }
		}
		if (i >= 20)
			throw new SqlRepairException("SQL repair failed - cannot forward to backend registry");

		StringBuffer buf = new StringBuffer();
		for (int j=0; j<words.length; j++ ) {
			buf.append(" " + words[j]);
		}
		
		query_element.setText(buf.toString());
	}
 
Example 8
Source File: BrokerClient.java    From carbon-commons with Apache License 2.0 5 votes vote down vote up
public void unsubscribe(String subscriptionID) throws RemoteException{
    log.debug("Unsubscribed to "+ subscriptionID);
    EventBrokerServiceStub service = new EventBrokerServiceStub(configurationContext, brokerUrl);
    configureCookie(service._getServiceClient());
    ServiceClient serviceClient = service._getServiceClient();
    OMElement header = fac.createOMElement(new QName(WSE_EVENTING_NS, WSE_EN_IDENTIFIER));
    header.setText(subscriptionID);
    serviceClient.addHeader(header);
    service.unsubscribe(new OMElement[]{});
}
 
Example 9
Source File: ServiceInvoker.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void addDummyElements(long numElements) {
    OMElement dummies = fac.createOMElement("Dummies", null);
    msg.addChild(dummies);

    for (long i = 0; i < numElements; i++) {
        OMElement dummy = fac.createOMElement("Dummy", null);
        dummy.setText("This is the dummy element " + i);
        dummies.addChild(dummy);
    }
}
 
Example 10
Source File: ConcurrencyThrottleTestClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private OMElement getSleepOperationRequest() throws XMLStreamException {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMElement omeSleep = fac.createOMElement("sleepOperation", null);
    OMElement omeLoad = fac.createOMElement("load", null);
    omeLoad.setText("2000");
    omeSleep.addChild(omeLoad);
    return omeSleep;

}
 
Example 11
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private OMElement createMultipleCustomQuoteRequest(String symbol, int iterations) {
    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace("http://services.samples", "ns");
    OMElement method = fac.createOMElement("getQuote", omNs);

    for (int i = 0; i < iterations; i++) {
        OMElement chkPrice = fac.createOMElement("CheckPriceRequest", omNs);
        OMElement code = fac.createOMElement("Code", omNs);
        chkPrice.addChild(code);
        code.setText(symbol);
        method.addChild(chkPrice);
    }
    return method;
}
 
Example 12
Source File: ServiceInvoker.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public ServiceInvoker(String epr, String operation) {

        this.operation = operation;

        Options options = new Options();
        options.setTo(new EndpointReference(epr));
        options.setAction(operation);

        try {
            ConfigurationContext configContext = ConfigurationContextFactory.
                    createConfigurationContextFromFileSystem("client_repo", null);

            client = new ServiceClient(configContext, null);
            options.setTimeOutInMilliSeconds(10000000);

            client.setOptions(options);
            client.engageModule("addressing");

        } catch (AxisFault axisFault) {
            axisFault.printStackTrace();
        }

        fac = OMAbstractFactory.getOMFactory();
        msg = fac.createOMElement("SampleMsg", null);

        OMElement load = fac.createOMElement("load", null);
        load.setText("1000");
        msg.addChild(load);
    }
 
Example 13
Source File: AddScheduleTaskTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement getEmployeeById(String employeeNumber) throws AxisFault {
    OMElement payload = fac.createOMElement("employeesByNumber", omNs);

    OMElement empNo = fac.createOMElement("employeeNumber", omNs);
    empNo.setText(employeeNumber);
    payload.addChild(empNo);

    OMElement result = new AxisServiceClient().sendReceive(payload, serviceEndPoint, "employeesByNumber");
    Assert.assertNotNull(result, "Employee record null");
    Assert.assertTrue(result.toString().contains("<first-name>AAA</first-name>"), "Expected Result Mismatched");
    return result;
}
 
Example 14
Source File: ESBJAVA2006RetryOnSOAPFaultTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement getThrowAxisFaultRequest() {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://processor.message.mediator.carbon.wso2.org", "proc");
    OMElement throwFault = factory.createOMElement("throwAxisFault", ns);
    OMElement str = factory.createOMElement("s", ns);
    str.setText("Throw_Fault");
    throwFault.addChild(str);

    return throwFault;
}
 
Example 15
Source File: APIAuthenticationHandler.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
protected 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(APISecurityConstants.getFailureMessageDetailDescription(e.getErrorCode(), e.getMessage()));

    // if custom auth header is configured, the error message should specify its name instead of default value
    if (e.getErrorCode() == APISecurityConstants.API_AUTH_MISSING_CREDENTIALS) {
        String errorDescription =
                APISecurityConstants.getFailureMessageDetailDescription(e.getErrorCode(), e.getMessage()) + "'"
                        + authorizationHeader + " : Bearer ACCESS_TOKEN' or '" + authorizationHeader +
                        " : Basic ACCESS_TOKEN' or 'apikey: API_KEY'" ;
        errorDetail.setText(errorDescription);
    }

    payload.addChild(errorCode);
    payload.addChild(errorMessage);
    payload.addChild(errorDetail);
    return payload;
}
 
Example 16
Source File: FileServiceTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.dss"}, dependsOnMethods = {"createNewFile"})
    public void addRecord() throws IOException, XPathExpressionException {
        OMElement payload = fac.createOMElement("_postappenddatatofile", omNs);
        String recordsExpected = "";

        OMElement fileName = fac.createOMElement("fileName", omNs);
        fileName.setText(txtFileName);
        payload.addChild(fileName);

        OMElement fileRecord = fac.createOMElement("data", omNs);
        AxisServiceClient axisClient = new AxisServiceClient();
        Base64 encoder = new Base64();
//        encoder.e
//        BASE64Decoder decoder = new BASE64Decoder();
        for (int i = 0; i < 5; i++) {
            String record = "TestFileRecord" + i;
            fileRecord.setText(new String(encoder.encode(record.getBytes())));
            payload.addChild(fileRecord);
            recordsExpected = recordsExpected + record + ";";
            axisClient.sendRobust(payload, getServiceUrlHttp(serviceName), "_postappenddatatofile");

        }
        log.info("Records Added");
        OMElement response = getRecord();
        Iterator file = response.getChildrenWithLocalName("File");
        String recordData = "";
        while (file.hasNext()) {
            OMElement data = (OMElement) file.next();
            recordData = recordData + new String(encoder.decode(data.getFirstElement().getText().getBytes())) + ";";

        }
        Assert.assertNotSame("", recordsExpected, "No Record added to file. add records to file");
        Assert.assertEquals(recordData, recordsExpected, "Record Data Mismatched");
    }
 
Example 17
Source File: InvalidSoapActionTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private OMElement createCustomQuoteRequest(String symbol) {
    OMFactory factory = OMAbstractFactory.getOMFactory();
    OMNamespace ns = factory.createOMNamespace("http://services.samples", "ns");
    OMElement chkPrice = factory.createOMElement("CheckPriceRequest", ns);
    OMElement code = factory.createOMElement("Code", ns);
    chkPrice.addChild(code);
    code.setText(symbol);
    return chkPrice;
}
 
Example 18
Source File: EventBrokerAdminClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public void publish(String topic, OMElement element) throws AxisFault {
    log.debug("published element to " + topic);
    EventBrokerServiceStub service = new EventBrokerServiceStub(configurationContext,
                                                                backendUrl + "/publish/" + topic);
    configureCookie(service._getServiceClient());
    ServiceClient serviceClient = service._getServiceClient();

    OMElement header = omFactory.createOMElement(new QName(TOPIC_HEADER_NS, TOPIC_HEADER_NAME));
    header.setText(topic);
    serviceClient.addHeader(header);
    serviceClient.getOptions().setTo(new EndpointReference(backendUrl + "/publish"));
    //serviceClient.getOptions().setTo(new EndpointReference(brokerUrl));
    serviceClient.getOptions().setAction("urn:publish");
    serviceClient.sendRobust(element);
}
 
Example 19
Source File: DistributedTransactionTestCase.java    From product-ei with Apache License 2.0 3 votes vote down vote up
private OMElement getAccountBalanceFromBank2(int accId) {
    OMElement payload = fac.createOMElement("getAccountBalanceFromBank2", omNs);

    OMElement accountId = fac.createOMElement("accountId", omNs);
    accountId.setText(accId + "");
    payload.addChild(accountId);

    return payload;

}
 
Example 20
Source File: SampleDataServiceClient.java    From product-ei with Apache License 2.0 3 votes vote down vote up
public void deleteEmployeeById(String employeeNumber)
        throws AxisFault {
    OMElement payload = fac.createOMElement("deleteEmployeeById", omNs);

    OMElement empNo = fac.createOMElement("employeeNumber", omNs);
    empNo.setText(employeeNumber);
    payload.addChild(empNo);

    new AxisServiceClient().sendRobust(payload, serviceEndpoint, "deleteEmployeeById");


}