Java Code Examples for org.apache.axis2.client.ServiceClient#sendRobust()

The following examples show how to use org.apache.axis2.client.ServiceClient#sendRobust() . 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: Sample704TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "RESTful Invocations with Message Forwarding" + " Processor test case")
public void messageStoreFIXStoringTest() throws Exception {

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);

    for (int i = 0; i < 10; i++) {
        serviceClient.sendRobust(createPayload());
    }

    Thread.sleep(2000);
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0, "Messages are stored");
}
 
Example 2
Source File: Sample701TestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Sampling Processor " +
        "test case")
public void messageStoreFIXStoringTest() throws Exception {

    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);

    for (int i = 0; i < 10; i++) {
        serviceClient.sendRobust(createPayload());
    }

    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) > 0,
            "Messages are not stored");

}
 
Example 3
Source File: Sample700TestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Store test case ")
public void messageStoringTest() throws Exception {
    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");
    // refer within a sequence through a store mediator, mediate messages
    // and verify the messages are stored correctly in the store.

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("SimpleStockQuoteService")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);
    serviceClient.sendRobust(createPayload());

    Thread.sleep(30000);
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 1,
            "Messages are missing or repeated");

}
 
Example 4
Source File: SecureAxisServiceClient.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * This will send request by getting keyStore wso2carbon.jks
 *
 * @param userName
 * @param password
 * @param endpointReference
 * @param operation
 * @param payload
 * @param securityScenarioNo
 * @throws Exception
 */

public void sendRobust(String userName, String password, String endpointReference,
                       String operation, OMElement payload, int securityScenarioNo)
        throws Exception {
    if (securityScenarioNo == 1) {
        Assert.assertTrue(endpointReference.startsWith("https:"), "Endpoint reference should be https");
    }


    String keyPath =
            FrameworkPathUtil.getSystemResourceLocation() + File.separator + "keystores" + File.separator + "products";
    String securityPolicyPath = FrameworkPathUtil.getSystemResourceLocation() + File.separator + "security"
            + File.separator + "policies" + "scenario" + securityScenarioNo + "-policy.xml";
    ServiceClient sc = getServiceClient(userName, password, endpointReference, operation,
            securityPolicyPath, "wso2carbon", "wso2carbon", keyPath, "wso2carbon");
    try {
        sc.sendRobust(payload);
        log.info("Request Sent");
    } catch (AxisFault axisFault) {
        log.error("AxisFault : " + axisFault.getMessage());
        throw axisFault;
    } finally {
        sc.cleanupTransport();
    }
}
 
Example 5
Source File: Sample702TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Forwarding Processor " + "test case")
public void messageStoringTest() throws Exception {
    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");
    // refer within a sequence through a store mediator, mediate messages
    // and verify the messages are stored correctly in the store.

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("SimpleStockQuoteService")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);
    serviceClient.sendRobust(createPayload());

    Thread.sleep(30000);
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Messages are not forwarded");

}
 
Example 6
Source File: Sample701TestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Sampling Processor " + "test case")
public void messageStoreFIXStoringTest() throws Exception {

    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);

    for (int i = 0; i < 10; i++) {
        serviceClient.sendRobust(createPayload());
    }

    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) > 0, "Messages are not stored");

}
 
Example 7
Source File: Sample702TestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Introduction to Message Forwarding Processor " +
        "test case")
public void messageStoringTest() throws Exception {
    // The count should be 0 as soon as the message store is created
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Message store should be initially empty");
    // refer within a sequence through a store mediator, mediate messages
    // and verify the messages are stored correctly in the store.

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getBackEndServiceUrl("SimpleStockQuoteService")));
    options.setAction("urn:placeOrder");
    options.setProperty(Constants.Configuration.TRANSPORT_URL, getMainSequenceURL());
    serviceClient.setOptions(options);
    serviceClient.sendRobust(createPayload());

    Thread.sleep(30000);
    Assert.assertTrue(messageStoreAdminClient.getMessageCount(MESSAGE_STORE_NAME) == 0,
            "Messages are not forwarded");

}
 
Example 8
Source File: SecureAxisServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * @param userName
 * @param password
 * @param endpointReference
 * @param operation
 * @param payload
 * @param securityPolicyPath
 * @param userCertAlias
 * @param encryptionUser
 * @param keyStorePath
 * @param keyStorePassword
 * @throws Exception
 */

public void sendRobust(String userName, String password, String endpointReference, String operation,
                       OMElement payload, String securityPolicyPath, String userCertAlias, String encryptionUser,
                       String keyStorePath, String keyStorePassword) throws Exception {
    ServiceClient sc = getServiceClient(userName, password, endpointReference, operation, securityPolicyPath,
                                        userCertAlias, encryptionUser, keyStorePath, keyStorePassword);
    if (log.isDebugEnabled()) {
        log.debug("payload :" + payload);
        log.debug("Security Policy Path :" + securityPolicyPath);
        log.debug("Operation :" + operation);
        log.debug("username :" + userName);
        log.debug("password :" + password);
    }

    log.info("Endpoint reference :" + endpointReference);
    try {
        sc.sendRobust(payload);
    } catch (AxisFault axisFault) {
        log.error("AxisFault : " + axisFault.getMessage());
        throw axisFault;
    } finally {
        sc.cleanupTransport();
    }

}
 
Example 9
Source File: SecureAxisServiceClient.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * This will send request by getting keyStore wso2carbon.jks
 *
 * @param userName
 * @param password
 * @param endpointReference
 * @param operation
 * @param payload
 * @param securityScenarioNo
 * @throws Exception
 */

public void sendRobust(String userName, String password, String endpointReference, String operation,
                       OMElement payload, int securityScenarioNo) throws Exception {
    if (securityScenarioNo == 1) {
        Assert.assertTrue(endpointReference.startsWith("https:"), "Endpoint reference should be https");
    }

    String keyPath = FrameworkPathUtil.getSystemResourceLocation() + File.separator + "keystores" + File.separator
            + "products";
    String securityPolicyPath =
            FrameworkPathUtil.getSystemResourceLocation() + File.separator + "security" + File.separator
                    + "policies" + "scenario" + securityScenarioNo + "-policy.xml";
    ServiceClient sc = getServiceClient(userName, password, endpointReference, operation, securityPolicyPath,
                                        "wso2carbon", "wso2carbon", keyPath, "wso2carbon");
    try {
        sc.sendRobust(payload);
        log.info("Request Sent");
    } catch (AxisFault axisFault) {
        log.error("AxisFault : " + axisFault.getMessage());
        throw axisFault;
    } finally {
        sc.cleanupTransport();
    }
}
 
Example 10
Source File: Sample705TestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
@Test(groups = { "wso2.esb" }, description = "Test forwarding with load balancing")
public void loadBalancingTest() throws Exception {

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getProxyServiceURLHttp("Sample705StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    serviceClient.setOptions(options);

    for (int i = 0; i < 100; i++) {
        serviceClient.sendRobust(createPayload());
    }

}
 
Example 11
Source File: SecurityVerificationTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
@Test(description = "Ensures that all Admin services are exposed only via HTTPS", enabled = false)
public void verifyAdminServiceSecurity() throws AxisFault, XPathExpressionException {
    ServiceClient client = new ServiceClient(null, null);
    Options opts = new Options();
    String serviceName = "SecurityVerifierService";

    EndpointReference epr = new EndpointReference(getServiceUrlHttp(serviceName));
    opts.setTo(epr);

    client.setOptions(opts);
    client.sendRobust(createPayLoad());   // robust send. Will get reply only if there is a fault
    log.info("sent the message");
}
 
Example 12
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 13
Source File: SecurityVerificationTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@Test(description = "Ensures that all Admin services are exposed only via HTTPS", enabled = false)
public void verifyAdminServiceSecurity() throws AxisFault, XPathExpressionException {
    ServiceClient client = new ServiceClient(null, null);
    Options opts = new Options();
    String serviceName = "SecurityVerifierService";

    EndpointReference epr =
            new EndpointReference(getServiceUrlHttp(serviceName));
    opts.setTo(epr);

    client.setOptions(opts);
    client.sendRobust(createPayLoad());   // robust send. Will get reply only if there is a fault
    log.info("sent the message");
}
 
Example 14
Source File: EventBrokerAdminClient.java    From product-ei 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 15
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method utilises serviceClient's sendRobust() method
 *
 * @param trpUrl  transport url
 * @param addUrl  address url
 * @param action  action
 * @param payload payload
 * @throws AxisFault if error occurs in sending the request
 */
public void sendRobust(String trpUrl, String addUrl, String action, OMElement payload) throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, action);
    try {
        serviceClient.sendRobust(payload);
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 16
Source File: BrokerClient.java    From carbon-commons 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, brokerUrl+"/publish/"+topic);
    configureCookie(service._getServiceClient());
    ServiceClient serviceClient = service._getServiceClient();

    OMElement header = fac.createOMElement(new QName(TOPIC_HEADER_NS, TOPIC_HEADER_NAME));
    header.setText(topic);
    serviceClient.addHeader(header);
    serviceClient.getOptions().setTo(new EndpointReference(brokerUrl+"/publish"));
    //serviceClient.getOptions().setTo(new EndpointReference(brokerUrl));
    serviceClient.getOptions().setAction("urn:publish");
    serviceClient.sendRobust(element);
}
 
Example 17
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * This method utilises serviceClient's sendRobust() method
 *
 * @param trpUrl transport url
 * @param addUrl address url
 * @param action action
 * @param payload payload
 * @throws AxisFault if error occurs in sending the request
 */
public void sendRobust(String trpUrl, String addUrl, String action, OMElement payload) throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, action);
    try {
        serviceClient.sendRobust(payload);
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 18
Source File: Sample705TestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@SetEnvironment(executionEnvironments = {ExecutionEnvironment.STANDALONE})
@Test(groups = { "wso2.esb" }, description = "Test forwarding with load balancing")
public void loadBalancingTest() throws Exception {

    ServiceClient serviceClient = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(getProxyServiceURLHttp("StockQuoteProxy")));
    options.setAction("urn:placeOrder");
    serviceClient.setOptions(options);

    for (int i = 0; i < 100; i++ ) {
        serviceClient.sendRobust(createPayload());
    }

}
 
Example 19
Source File: DTPBatchRequestSampleTestcase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@Test(groups = { "wso2.dss" }, dependsOnMethods = "testServiceDeployment")
public void testDTPWithBatchRequests() throws DataServiceFault, RemoteException {
    DTPSampleServiceStub stub = new DTPSampleServiceStub(serverEpr);
    stub._getServiceClient().getOptions().setManageSession(true);
    stub._getServiceClient().getOptions()
            .setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

    //Add two accounts to Bank 1
    Entry[] entry1_1 = stub.addAccountToBank1(1000.00);
    Entry[] entry1_2 = stub.addAccountToBank1(1000.00);
    //Add an account to Bank 2
    Entry[] entry2 = stub.addAccountToBank2(2000.00);

    ServiceClient sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(serverEpr));
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
    options.setManageSession(true);
    sender.setOptions(options);

    options.setAction("urn:" + "begin_boxcar");
    sender.setOptions(options);
    sender.sendRobust(begin_boxcar());

    //Send a batch request to Bank 1 to update two accounts
    OMElement payload = createBatchRequestPayload(entry1_1[0].getID().intValue(), entry1_2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank1_batch_req");
    sender.setOptions(options);
    sender.sendRobust(payload);

    //this line will cases dss fault due to service input parameter validation
    payload = createAccountUpdatePayload(entry2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank2");
    sender.setOptions(options);
    sender.sendRobust(payload);

    try {
        options.setAction("urn:" + "end_boxcar");
        sender.setOptions(options);
        sender.sendRobust(end_boxcar());
    } catch (AxisFault dssFault) {
        log.error("DSS fault ignored");
    }

    assertEquals(stub.getAccountBalanceFromBank1(entry1_1[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank1(entry1_2[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank2(entry2[0].getID().intValue()), 2000.00);
}
 
Example 20
Source File: DTPBatchRequestSampleTestcase.java    From product-ei with Apache License 2.0 4 votes vote down vote up
@Test(groups = {"wso2.dss"}, dependsOnMethods = "testServiceDeployment")
public void testDTPWithBatchRequests() throws DataServiceFault, RemoteException {
    DTPSampleServiceStub stub = new DTPSampleServiceStub(serverEpr);
    stub._getServiceClient().getOptions().setManageSession(true);
    stub._getServiceClient().getOptions().setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);

    //Add two accounts to Bank 1
    Entry[] entry1_1 = stub.addAccountToBank1(1000.00);
    Entry[] entry1_2 = stub.addAccountToBank1(1000.00);
    //Add an account to Bank 2
    Entry[] entry2 = stub.addAccountToBank2(2000.00);

    ServiceClient sender = new ServiceClient();
    Options options = new Options();
    options.setTo(new EndpointReference(serverEpr));
    options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CHUNKED, Boolean.FALSE);
    options.setManageSession(true);
    sender.setOptions(options);
    
    options.setAction("urn:" + "begin_boxcar");
    sender.setOptions(options);
    sender.sendRobust(begin_boxcar());
    

    //Send a batch request to Bank 1 to update two accounts
    OMElement payload = createBatchRequestPayload(entry1_1[0].getID().intValue(), entry1_2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank1_batch_req");
    sender.setOptions(options);
    sender.sendRobust(payload);
             

    //this line will cases dss fault due to service input parameter validation
    payload = createAccountUpdatePayload(entry2[0].getID().intValue());
    options.setAction("urn:" + "addToAccountBalanceInBank2");
    sender.setOptions(options);
    sender.sendRobust(payload);

    try {
    	options.setAction("urn:" + "end_boxcar");
        sender.setOptions(options);
    	sender.sendRobust(end_boxcar());
    } catch (AxisFault dssFault) {
        log.error("DSS fault ignored");
    }

    assertEquals(stub.getAccountBalanceFromBank1(entry1_1[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank1(entry1_2[0].getID().intValue()), 1000.00);
    assertEquals(stub.getAccountBalanceFromBank2(entry2[0].getID().intValue()), 2000.00);
}