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

The following examples show how to use org.apache.axis2.client.ServiceClient#cleanupTransport() . 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: 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 2
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleStockQuoteRequest(String trpUrl, String addUrl, String symbol)
        throws AxisFault {

    ServiceClient sc;
    sc=getServiceClient(trpUrl, addUrl);

    try {
        return buildResponse(sc.sendReceive(createStandardRequest(symbol)));
    } finally {
        sc.cleanupTransport();
    }
}
 
Example 3
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * Send place order request
 *
 * @param trpUrl transport url
 * @param addUrl address url
 * @param symbol symbol
 * @throws AxisFault if error occurs when sending request
 */
public void sendPlaceOrderRequest(String trpUrl, String addUrl, String symbol) throws AxisFault {
    double price = getRandom(100, 0.9, true);
    int quantity = (int) getRandom(10000, 1.0, true);
    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, "placeOrder");
    try {
        serviceClient.fireAndForget(createPlaceOrderRequest(price, quantity, symbol));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 4
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendMultipleQuoteRequest(String trpUrl, String addUrl, String symbol, int n)
        throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl);
    try {
        return buildResponse(serviceClient.sendReceive(createMultipleQuoteRequest(symbol, n)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 5
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement sendMultipleQuoteRequest(String trpUrl, String addUrl, String symbol, int n) throws AxisFault {

        ServiceClient serviceClient = getServiceClient(trpUrl, addUrl);
        try {
            return buildResponse(serviceClient.sendReceive(createMultipleQuoteRequest(symbol, n)));
        } finally {
            serviceClient.cleanupTransport();
        }
    }
 
Example 6
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement send(String trpUrl, String addUrl, String action, OMElement payload)
        throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, action);
    try {
        return buildResponse(serviceClient.sendReceive(payload));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 7
Source File: WSXACMLEntitlementServiceClient.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Get decision in a secured manner using the
 * SAML implementation of XACML using X.509 credentials
 *
 * @return decision extracted from the SAMLResponse sent from PDP
 * @throws Exception
 */
@Override
public String getDecision(Attribute[] attributes, String appId) throws Exception {

    String xacmlRequest;
    String xacmlAuthzDecisionQuery;
    OMElement samlResponseElement;
    String samlResponse;
    String result;
    try {
        xacmlRequest = XACMLRequetBuilder.buildXACML3Request(attributes);
        xacmlAuthzDecisionQuery = buildSAMLXACMLAuthzDecisionQuery(xacmlRequest);
        ServiceClient sc = new ServiceClient();
        Options opts = new Options();
        opts.setTo(new EndpointReference(serverUrl + "ws-xacml"));
        opts.setAction("XACMLAuthzDecisionQuery");
        opts.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
        opts.setManageSession(true);
        sc.setOptions(opts);
        samlResponseElement = sc.sendReceive(AXIOMUtil.stringToOM(xacmlAuthzDecisionQuery));
        samlResponse = samlResponseElement.toString();
        result = extractXACMLResponse(samlResponse);
        sc.cleanupTransport();
        return result;
    } catch (Exception e) {
        log.error("Error occurred while getting decision using SAML.", e);
        throw new Exception("Error occurred while getting decision using SAML.", e);
    }
}
 
Example 8
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendMultipleQuoteRequestREST(String trpUrl, String addUrl, String symbol,
                                               int n)
        throws AxisFault {

    ServiceClient serviceClient = getRESTEnabledServiceClient(trpUrl, addUrl);
    try {
        return buildResponse(serviceClient.sendReceive(createMultipleQuoteRequest(symbol, n)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 9
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement send(String trpUrl, String addUrl, String action, OMElement payload) throws AxisFault {

        ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, action);
        try {
            return buildResponse(serviceClient.sendReceive(payload));
        } finally {
            serviceClient.cleanupTransport();
        }
    }
 
Example 10
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendCustomQuoteRequestREST(String trpUrl, String addUrl, String symbol)
        throws AxisFault {

    ServiceClient serviceClient = getRESTEnabledServiceClient(trpUrl, addUrl);
    try {
        return buildResponse(serviceClient.sendReceive(createCustomQuoteRequest(symbol)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 11
Source File: SecureAxisServiceClient.java    From product-ei with Apache License 2.0 5 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
 * @return
 * @throws Exception
 */

public OMElement sendReceive(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);
    OMElement result;
    if (log.isDebugEnabled()) {
        log.debug("payload :" + payload);
        log.debug("Policy Path :" + securityPolicyPath);
        log.debug("Operation :" + operation);
        log.debug("username :" + userName);
        log.debug("password :" + password);
    }

    log.info("Endpoint reference :" + endpointReference);
    try {
        result = buildResponse(sc.sendReceive(payload));
        if (log.isDebugEnabled()) {
            log.debug("Response :" + result);
        }
    } catch (AxisFault axisFault) {
        log.error("AxisFault : " + axisFault.getMessage());
        throw axisFault;
    } finally {
        sc.cleanupTransport();
    }
    Assert.assertNotNull(result);
    return result;


}
 
Example 12
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleQuoteRequestREST(String trpUrl, String addUrl, String symbol)
        throws AxisFault {

    ServiceClient serviceClient = getRESTEnabledServiceClient(trpUrl, addUrl, "getSimpleQuote");
    try {
        return buildResponse(serviceClient.sendReceive(createStandardSimpleRequest(symbol)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 13
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleStockQuoteSoap12(String trpUrl, String addUrl, String symbol) throws AxisFault {

        ServiceClient serviceClient = getServiceClient(trpUrl, addUrl);
        serviceClient.getOptions().setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
        try {
            return buildResponse(serviceClient.sendReceive(createStandardRequest(symbol)));
        } finally {
            serviceClient.cleanupTransport();
        }
    }
 
Example 14
Source File: SecureAxisServiceClient.java    From product-ei with Apache License 2.0 5 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 15
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendCustomQuoteRequest(String trpUrl, String addUrl, String symbol)
        throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl);
    try {
        return buildResponse(serviceClient.sendReceive(createCustomQuoteRequest(symbol)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 16
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Send place order request
 *
 * @param trpUrl transport url
 * @param addUrl address url
 * @param symbol symbol
 * @throws AxisFault if error occurs when sending request
 */
public void sendPlaceOrderRequest(String trpUrl, String addUrl, String symbol) throws AxisFault {
    double price = getRandom(100, 0.9, true);
    int quantity = (int) getRandom(10000, 1.0, true);
    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl, "placeOrder");
    try {
        serviceClient.fireAndForget(createPlaceOrderRequest(price, quantity, symbol));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 17
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleStockQuoteRequestREST(String trpUrl, String addUrl, String symbol) throws AxisFault {
    ServiceClient sc = getRESTEnabledServiceClient(trpUrl, addUrl);
    try {
        return buildResponse(sc.sendReceive(createStandardRequest(symbol)));
    } finally {
        sc.cleanupTransport();
    }

}
 
Example 18
Source File: StockQuoteClient.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleStockQuoteRequest(String trpUrl, String addUrl, String symbol) throws AxisFault {

        ServiceClient sc;
        sc = getServiceClient(trpUrl, addUrl);

        try {
            return buildResponse(sc.sendReceive(createStandardRequest(symbol)));
        } finally {
            sc.cleanupTransport();
        }
    }
 
Example 19
Source File: StockQuoteClient.java    From product-ei with Apache License 2.0 5 votes vote down vote up
public OMElement sendSimpleStockQuoteSoap12(String trpUrl, String addUrl, String symbol)
        throws AxisFault {

    ServiceClient serviceClient = getServiceClient(trpUrl, addUrl);
    serviceClient.getOptions()
            .setSoapVersionURI(org.apache.axiom.soap.SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
    try {
        return buildResponse(serviceClient.sendReceive(createStandardRequest(symbol)));
    } finally {
        serviceClient.cleanupTransport();
    }
}
 
Example 20
Source File: SecureAxisServiceClient.java    From product-ei with Apache License 2.0 4 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
 * @return
 * @throws Exception
 */

public OMElement sendReceive(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");
    OMElement result;
    if (log.isDebugEnabled()) {
        log.debug("payload :" + payload);
        log.debug("Security Scenario No :" + securityScenarioNo);
        log.debug("Operation :" + operation);
        log.debug("username :" + userName);
        log.debug("password :" + password);
    }

    log.info("Endpoint reference :" + endpointReference);
    try {
        result = buildResponse(sc.sendReceive(payload));
        if (log.isDebugEnabled()) {
            log.debug("Response :" + result);
        }
    } catch (AxisFault axisFault) {
        log.error("AxisFault : " + axisFault.getMessage());
        throw axisFault;
    } finally {
        sc.cleanupTransport();
    }
    Assert.assertNotNull(result);
    return result;


}