org.apache.axiom.om.impl.llom.util.AXIOMUtil Java Examples

The following examples show how to use org.apache.axiom.om.impl.llom.util.AXIOMUtil. 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: ESBJAVA4565TestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@BeforeClass(alwaysRun = true)
protected void init() throws Exception {
    super.init();
    verifySequenceExistence("ESBJAVA4565TestSequence");
    resourceAdminServiceStub =
            new ResourceAdminServiceClient(contextUrls.getBackEndUrl(), getSessionCookie());

    String ftpXmlPath = Paths.get(getESBResourceLocation(), "registry", "ftp.xml").toString();
    resourceAdminServiceStub.addResource(REGISTRY_ARTIFACT, "application/xml", "FTP Test account details",
                                         new DataHandler(new FileDataSource(new File(ftpXmlPath))));

    OMElement task = AXIOMUtil.stringToOM("<task:task xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"\n" +
                                          "           name=\"TestTask\"\n" +
                                          "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n" +
                                          "    <task:trigger interval=\"10\"/>\n" +
                                          "    <task:property name=\"format\" value=\"get\"/>\n" +
                                          "    <task:property name=\"sequenceName\" value=\"ESBJAVA4565TestSequence\"/>\n" +
                                          "    <task:property name=\"injectTo\" value=\"sequence\"/>\n" +
                                          "    <task:property name=\"message\"><empty/></task:property>\n" +
                                          "</task:task>");
    this.addScheduledTask(task);
}
 
Example #2
Source File: APIGatewayAdmin.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Deploy the sequence to the gateway
 *
 * @param sequence
 * @param tenantDomain
 * @throws AxisFault
 */
public boolean addSequenceForTenant(String sequence, String tenantDomain) throws AxisFault {

    SequenceAdminServiceProxy client = getSequenceAdminServiceClient(tenantDomain);
    if (sequence != null && !sequence.isEmpty()) {
        OMElement element = null;
        try {
            element = AXIOMUtil.stringToOM(sequence);
            client.addSequence(element);
            return true;
        } catch (XMLStreamException e) {
            log.error("Exception occurred while converting String to an OM.", e);
        }
    }
    return false;
}
 
Example #3
Source File: APIGatewayAdmin.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Deploy the sequence to the gateway
 *
 * @param sequence - The sequence element , which to be deployed in synapse
 * @throws AxisFault
 */
public boolean addSequence(String sequence) throws AxisFault {

    SequenceAdminServiceProxy client =
            getSequenceAdminServiceClient(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
    if (sequence != null && !sequence.isEmpty()) {
        OMElement element = null;
        try {
            element = AXIOMUtil.stringToOM(sequence);
            client.addSequence(element);
            return true;
        } catch (XMLStreamException e) {
            log.error("Exception occurred while converting String to an OM.", e);
        }
    }
    return false;
}
 
Example #4
Source File: AbstractEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public String getStatus(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement decision = null;

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision = result.getFirstChildWithName(new QName("Decision"));
        if (decision != null) {
            return decision.getText();
        }
    }

    return "Invalid Status";
}
 
Example #5
Source File: IdentityBaseUtil.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
public static Policy getSignOnlyPolicy() throws IdentityException {

        Policy policy;

        try {
            OMElement policyOM = AXIOMUtil.stringToOM(policyString);
            PolicyEngine policyEngine = new PolicyEngine();
            policy = policyEngine.getPolicy(policyOM);
        } catch (Exception e) {
            String msg = "error building policy from " + policyString;
            log.error(msg);
            throw IdentityException.error(msg, e);
        }

        return policy;

    }
 
Example #6
Source File: TaskWithLargeIntervalValueTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"}, description = "Test successful deployment of scheduled task with large interval value")
public void testDeployWithLargeIntervalValue() throws Exception {

    OMElement task = AXIOMUtil.stringToOM("<task:task xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"\n" +
            "           name=\"ESBJAVA5234TestTask\"\n" +
            "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n" +
            "    <task:trigger count=\"1\" interval=\"25920000\"/>\n" +
            "    <task:property name=\"message\">\n" +
            "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" +
            "            <m0:order>\n" +
            "                <m0:price>100</m0:price>\n" +
            "                <m0:quantity>200</m0:quantity>\n" +
            "                <m0:symbol>IBM</m0:symbol>\n" +
            "            </m0:order>\n" +
            "        </m0:placeOrder>\n" +
            "    </task:property>\n" +
            "</task:task>");

    addScheduledTask(task);

    LogViewerClient logViewerClient = new LogViewerClient(context.getContextUrls().getBackEndUrl(), getSessionCookie());
    boolean assertValue = Utils.checkForLog(logViewerClient,
            "ESBJAVA5234TestTask was added to the Synapse configuration successfully",
            5);
    assertTrue(assertValue, "Scheduled task with large interval value has not deployed.");
}
 
Example #7
Source File: InjectToProxyTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"wso2.esb"})
public void injectToProxyTest() throws Exception {
    OMElement task = AXIOMUtil.stringToOM("<task:task xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"\n" +
                                          "           name=\"SampleInjectToProxyTask\" class=\"org.apache.synapse.startup.tasks.MessageInjector\"\n" +
                                          "           group=\"synapse.simple.quartz\">\n" +
                                          "    <task:trigger count=\"1\" interval=\"1\"/>\n" +
                                          "    <task:property name=\"message\">\n" +
                                          "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" +
                                          "            <m0:order>\n" +
                                          "                <m0:price>100</m0:price>\n" +
                                          "                <m0:quantity>200</m0:quantity>\n" +
                                          "                <m0:symbol>IBM</m0:symbol>\n" +
                                          "            </m0:order>\n" +
                                          "        </m0:placeOrder>\n" +
                                          "    </task:property>\n" +
                                          "    <task:property name=\"proxyName\" value=\"SampleProxy\"/>\n" +
                                          "    <task:property name=\"injectTo\" value=\"proxy\"/>\n" +
                                          "</task:task>");

    addScheduledTask(task);
    boolean invokedLogFound = Utils.checkForLog(logViewer, "PROXY INVOKED", 4);
    assertTrue(invokedLogFound);
}
 
Example #8
Source File: AbstractEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
public String getStatus(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement decision = null;

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision = result.getFirstChildWithName(new QName("Decision"));
        if (decision != null) {
            return decision.getText();
        }
    }

    return "Invalid Status";
}
 
Example #9
Source File: InjectToSequenceTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" })
public void injectToSequenceTest() throws Exception {
    OMElement task = AXIOMUtil.stringToOM(
            "<task xmlns=\"http://ws.apache.org/ns/synapse\"\n"
                    + "           name=\"SampleInjectToSequenceTask\"\n"
                    + "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n"
                    + "    <trigger count=\"1\" interval=\"1\"/>\n" + "    <property name=\"message\" \n"
                    + " xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\">\n"
                    + "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" + "            <m0:order>\n"
                    + "                <m0:price>100</m0:price>\n"
                    + "                <m0:quantity>200</m0:quantity>\n"
                    + "                <m0:symbol>IBM</m0:symbol>\n" + "            </m0:order>\n"
                    + "        </m0:placeOrder>\n" + "    </property>\n"
                    + "    <property name=\"sequenceName\" value=\"SampleSequence\" \n"
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"injectTo\" value=\"sequence\" \n"
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n" + "</task>");

    Utils.deploySynapseConfiguration(task, "SampleInjectToSequenceTask", "tasks",  true);
    TimeUnit.SECONDS.sleep(5);

    boolean invokedLogFound = carbonLogReader.checkForLog("SEQUENCE INVOKED", DEFAULT_TIMEOUT);
    assertTrue(invokedLogFound);
}
 
Example #10
Source File: InjectToProxyTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" })
public void injectToProxyTest() throws Exception {
    OMElement task = AXIOMUtil.stringToOM(
            "<task xmlns=\"http://ws.apache.org/ns/synapse\"\n"
                    + "           name=\"SampleInjectToProxyTask\" class=\"org.apache.synapse.startup.tasks.MessageInjector\"\n"
                    + "           group=\"synapse.simple.quartz\">\n"
                    + "    <trigger count=\"1\" interval=\"1\"/>\n" + "    <property name=\"message\" "
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\">\n"
                    + "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" + "            <m0:order>\n"
                    + "                <m0:price>100</m0:price>\n"
                    + "                <m0:quantity>200</m0:quantity>\n"
                    + "                <m0:symbol>IBM</m0:symbol>\n" + "            </m0:order>\n"
                    + "        </m0:placeOrder>\n" + "    </property>\n"
                    + "    <property name=\"proxyName\" value=\"SampleProxy\" xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"injectTo\" value=\"proxy\" xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "</task>");
    carbonLogReader.start();
    Utils.deploySynapseConfiguration(task, "SampleInjectToProxyTask", "tasks", true);
    boolean invokedLogFound = Utils.logExists(carbonLogReader, "PROXY INVOKED", 4);
    assertTrue(invokedLogFound);
}
 
Example #11
Source File: ESBJAVA4565TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@BeforeClass(alwaysRun = true)
protected void init() throws Exception {
    super.init();

    OMElement task = AXIOMUtil.stringToOM(
            "<task \n"
                    + "           name=\"TestTask\"\n"
                    + "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\" "
                    + "xmlns=\"http://ws.apache.org/ns/synapse\">\n"
                    + "    <trigger interval=\"10\"/>\n"
                    + "    <property name=\"format\" "
                    + "value=\"get\" xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"sequenceName\" value=\"ESBJAVA4565TestSequence\" "
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"injectTo\" value=\"sequence\" xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"message\" xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"><empty/></property>\n" + "</task>");
    Utils.deploySynapseConfiguration(task, "TestTask", "tasks", true);
    carbonLogReader.start();
}
 
Example #12
Source File: ClientUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to extract the boolean response
 *
 * @param xmlstring XACML resource as String
 * @return Decision
 * @throws Exception if fails
 */
public static String getStatus(String xmlstring) throws Exception {

    OMElement response = null;
    OMElement result = null;
    OMElement decision = null;
    response = AXIOMUtil.stringToOM(xmlstring);

    OMNamespace nameSpace = response.getNamespace();

    if (nameSpace != null) {
        result = response.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Result"));
    } else {
        result = response.getFirstElement();
    }
    if (result != null) {
        if (nameSpace != null) {
            decision = result.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Decision"));
        } else {
            decision = result.getFirstChildWithName(new QName("Decision"));
        }
        if (decision != null) {
            return decision.getText();
        }
    }

    return "Invalid Status";
}
 
Example #13
Source File: InjectToSequenceTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(groups = {"wso2.esb"})
public void injectToSequenceTest() throws Exception {
   OMElement task = AXIOMUtil.stringToOM("<task:task xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"\n" +
                                          "           name=\"SampleInjectToSequenceTask\"\n" +
                                          "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n" +
                                          "    <task:trigger count=\"1\" interval=\"1\"/>\n" +
                                          "    <task:property name=\"message\">\n" +
                                          "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" +
                                          "            <m0:order>\n" +
                                          "                <m0:price>100</m0:price>\n" +
                                          "                <m0:quantity>200</m0:quantity>\n" +
                                          "                <m0:symbol>IBM</m0:symbol>\n" +
                                          "            </m0:order>\n" +
                                          "        </m0:placeOrder>\n" +
                                          "    </task:property>\n" +
                                          "    <task:property name=\"sequenceName\" value=\"SampleSequence\"/>\n" +
                                          "    <task:property name=\"injectTo\" value=\"sequence\"/>\n" +
                                          "</task:task>");

    logViewer.clearLogs();
    addScheduledTask(task);
    TimeUnit.SECONDS.sleep(5);
    LogEvent[] logs = logViewer.getAllRemoteSystemLogs();
    int afterLogSize = logs.length;

    boolean invokedLogFound = false;
    for (int i = 0; i < afterLogSize; i++) {
        if (logs[i].getMessage().contains("SEQUENCE INVOKED")) {
            invokedLogFound = true;
            break;
        }
    }
    assertTrue(invokedLogFound);
}
 
Example #14
Source File: AbstractEntitlementServiceClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement[] getStatusOMElement(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement[] decision = new OMElement[3];

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision[0] = result.getFirstChildWithName(new QName("Decision"));
        decision[1] = result.getFirstChildWithName(new QName("Obligations"));
        decision[2] = result.getFirstChildWithName(new QName("AssociatedAdvice"));
    }
    return decision;
}
 
Example #15
Source File: ClientUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Helper method to extract the boolean response
 *
 * @param xmlstring XACML resource as String
 * @return Decision
 * @throws Exception if fails
 */
public static String getStatus(String xmlstring) throws Exception {

    OMElement response = null;
    OMElement result = null;
    OMElement decision = null;
    response = AXIOMUtil.stringToOM(xmlstring);

    OMNamespace nameSpace = response.getNamespace();

    if (nameSpace != null) {
        result = response.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Result"));
    } else {
        result = response.getFirstElement();
    }
    if (result != null) {
        if (nameSpace != null) {
            decision = result.getFirstChildWithName(new QName(nameSpace.getNamespaceURI(), "Decision"));
        } else {
            decision = result.getFirstChildWithName(new QName("Decision"));
        }
        if (decision != null) {
            return decision.getText();
        }
    }

    return "Invalid Status";
}
 
Example #16
Source File: TaskWithLargeIntervalValueTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(groups = {
        "wso2.esb" }, description = "Test successful deployment of scheduled task with large interval value")
public void testDeployWithLargeIntervalValue() throws Exception {

    OMElement task = AXIOMUtil.stringToOM(
            "<task xmlns=\"http://ws.apache.org/ns/synapse\"\n"
                    + "           name=\"ESBJAVA5234TestTask\"\n"
                    + "           class=\"org.apache.synapse.startup.tasks.MessageInjector\" group=\"synapse.simple.quartz\">\n"
                    + "    <trigger count=\"1\" interval=\"25920000\"/>\n"
                    + "    <property name=\"message\" "
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\">\n"
                    + "        <m0:placeOrder xmlns:m0=\"http://services.samples\">\n" + "            <m0:order>\n"
                    + "                <m0:price>100</m0:price>\n"
                    + "                <m0:quantity>200</m0:quantity>\n"
                    + "                <m0:symbol>IBM</m0:symbol>\n" + "            </m0:order>\n"
                    + "        </m0:placeOrder>\n" + "    </property>\n "
                    + "<property name=\"proxyName\" value=\"ProxyForTaskWithLargeInterval\" \n"
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n"
                    + "    <property name=\"injectTo\" value=\"proxy\" \n"
                    + "xmlns:task=\"http://www.wso2.org/products/wso2commons/tasks\"/>\n" + "</task>");

    Utils.deploySynapseConfiguration(task, "ESBJAVA5234TestTask", "tasks", true);
    boolean assertValue = Utils
            .logExists(carbonLogReader, "injected value from ESBJAVA5234TestTask received",
                    5);
    assertTrue(assertValue, "Scheduled task with large interval value has not deployed.");
}
 
Example #17
Source File: AbstractEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public OMElement[] getStatusOMElement(String xmlstring) throws Exception {
    OMElement response = null;
    OMElement result = null;
    OMElement[] decision = new OMElement[3];

    response = AXIOMUtil.stringToOM(xmlstring);
    result = response.getFirstChildWithName(new QName("Result"));
    if (result != null) {
        decision[0] = result.getFirstChildWithName(new QName("Decision"));
        decision[1] = result.getFirstChildWithName(new QName("Obligations"));
        decision[2] = result.getFirstChildWithName(new QName("AssociatedAdvice"));
    }
    return decision;
}
 
Example #18
Source File: UTResponseCode401UTauthFailure.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {
    super.init();
    verifyProxyServiceExistence("UTResponseCode401UTauthFailureProxy");
    payload = AXIOMUtil.stringToOM(requestPayload);
}
 
Example #19
Source File: UTResponseCode401UTauthFailure.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {
    super.init();
    verifyProxyServiceExistence("UTResponseCode401UTauthFailureProxy");
    payload = AXIOMUtil.stringToOM(requestPayload);
}