Search in sources :

Example 1 with StringPuller

use of org.switchyard.common.io.pull.StringPuller in project quickstarts by jboss-switchyard.

the class WorkServiceMain method main.

public static void main(String... args) throws Exception {
    Set<String> policies = new HashSet<String>();
    for (String arg : args) {
        arg = Strings.trimToNull(arg);
        if (arg != null) {
            if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
                policies.add(arg);
            } else {
                LOGGER.error(MAVEN_USAGE);
                throw new Exception(MAVEN_USAGE);
            }
        }
    }
    if (policies.contains(HELP)) {
        LOGGER.info(MAVEN_USAGE);
    } else {
        final String scheme;
        final int port;
        if (policies.contains(CONFIDENTIALITY)) {
            scheme = "https";
            port = getPort(8443);
            SSLContext sslcontext = SSLContext.getInstance("TLS");
            sslcontext.init(null, null, null);
            SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            Scheme https = new Scheme(scheme, port, sf);
            SchemeRegistry sr = new SchemeRegistry();
            sr.register(https);
        } else {
            scheme = "http";
            port = getPort(8080);
        }
        String binarySecurityToken = policies.contains(CLIENT_AUTHENTICATION) ? new StringPuller().pull("/xml/BinarySecurityToken.xml") : null;
        invokeWorkService(scheme, port, getContext(), binarySecurityToken);
    }
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) StringPuller(org.switchyard.common.io.pull.StringPuller) SSLContext(javax.net.ssl.SSLContext) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory) HashSet(java.util.HashSet)

Example 2 with StringPuller

use of org.switchyard.common.io.pull.StringPuller in project quickstarts by jboss-switchyard.

the class WorkServiceMain method invokeWorkService.

private static void invokeWorkService(String scheme, int port, String context, String binarySecurityToken) throws Exception {
    String soapRequest = new StringPuller().pull("/xml/soap-request.xml").replaceAll("WORK_CMD", "CMD-" + System.currentTimeMillis());
    if (binarySecurityToken != null) {
        soapRequest = soapRequest.replaceFirst("<!-- BinarySecurityToken -->", binarySecurityToken);
    }
    HTTPMixIn http = new HTTPMixIn();
    http.initialize();
    try {
        String endpoint = String.format("%s://localhost:%s/%s/WorkService", scheme, port, context);
        // LOGGER.info(String.format("Invoking work service at endpoint: %s with request: %s", endpoint, soapRequest));
        LOGGER.info(String.format("Invoking work service at endpoint: %s", endpoint));
        String soapResponse = http.postString(endpoint, soapRequest);
        // LOGGER.info(String.format("Received work service response: %s", soapResponse));
        if (soapResponse.toLowerCase().contains("fault")) {
            throw new Exception("Error invoking work service (check server log)");
        }
    } finally {
        http.uninitialize();
    }
}
Also used : HTTPMixIn(org.switchyard.component.test.mixins.http.HTTPMixIn) StringPuller(org.switchyard.common.io.pull.StringPuller)

Example 3 with StringPuller

use of org.switchyard.common.io.pull.StringPuller in project quickstarts by jboss-switchyard.

the class WorkServiceMain method invokeWorkService.

private static void invokeWorkService(String scheme, int port, String context, String[] userPass) throws Exception {
    String soapRequest = new StringPuller().pull("/xml/soap-request.xml").replaceAll("WORK_CMD", "CMD-" + System.currentTimeMillis());
    HTTPMixIn http = new HTTPMixIn();
    if (userPass != null && userPass.length == 2) {
        http.setRequestHeader("Authorization", "Basic " + Base64.encodeFromString(userPass[0] + ":" + userPass[1]));
    }
    http.initialize();
    try {
        String endpoint = String.format("%s://localhost:%s/%s/WorkService", scheme, port, context);
        // LOGGER.info(String.format("Invoking work service at endpoint: %s with request: %s", endpoint, soapRequest));
        LOGGER.info(String.format("Invoking work service at endpoint: %s", endpoint));
        String soapResponse = http.postString(endpoint, soapRequest);
        // LOGGER.info(String.format("Received work service response: %s", soapResponse));
        if (soapResponse.toLowerCase().contains("fault")) {
            throw new Exception("Error invoking work service (check server log)");
        }
    } finally {
        http.uninitialize();
    }
}
Also used : HTTPMixIn(org.switchyard.component.test.mixins.http.HTTPMixIn) StringPuller(org.switchyard.common.io.pull.StringPuller)

Example 4 with StringPuller

use of org.switchyard.common.io.pull.StringPuller in project quickstarts by jboss-switchyard.

the class WorkServiceMain method invokeWorkService.

private static void invokeWorkService(String scheme, int port, String context, Element assertion) throws Exception {
    String soapRequest = new StringPuller().pull("/xml/soap-request.xml").replaceAll("WORK_CMD", "CMD-" + System.currentTimeMillis());
    if (assertion != null) {
        soapRequest = soapRequest.replaceFirst("<!-- Assertion -->", XMLHelper.toString(assertion));
    }
    HTTPMixIn http = new HTTPMixIn();
    http.initialize();
    try {
        String endpoint = String.format("%s://localhost:%s/%s/WorkService", scheme, port, context);
        // LOGGER.info(String.format("Invoking work service at endpoint: %s with request: %s", endpoint, soapRequest));
        LOGGER.info(String.format("Invoking work service at endpoint: %s", endpoint));
        String soapResponse = http.postString(endpoint, soapRequest);
        // LOGGER.info(String.format("Received work service response: %s", soapResponse));
        if (soapResponse.toLowerCase().contains("fault")) {
            throw new Exception("Error invoking work service (check server log)");
        }
    } finally {
        http.uninitialize();
    }
}
Also used : HTTPMixIn(org.switchyard.component.test.mixins.http.HTTPMixIn) StringPuller(org.switchyard.common.io.pull.StringPuller)

Example 5 with StringPuller

use of org.switchyard.common.io.pull.StringPuller in project quickstarts by jboss-switchyard.

the class WorkServiceMain method invokeWorkService.

private static void invokeWorkService(String scheme, int port, String context, boolean signencrypt) throws Exception {
    String soapRequest;
    if (signencrypt) {
        soapRequest = new StringPuller().pull("/xml/secure-request.xml");
    } else {
        soapRequest = new StringPuller().pull("/xml/insecure-request.xml").replaceAll("WORK_CMD", "CMD-" + System.currentTimeMillis());
    }
    HTTPMixIn http = new HTTPMixIn();
    http.initialize();
    try {
        String endpoint = String.format("%s://localhost:%s/%s/WorkService", scheme, port, context);
        // LOGGER.info(String.format("Invoking work service at endpoint: %s with request: %s", endpoint, soapRequest));
        LOGGER.info(String.format("Invoking work service at endpoint: %s", endpoint));
        String soapResponse = http.postString(endpoint, soapRequest);
        // LOGGER.info(String.format("Received work service response: %s", soapResponse));
        if (soapResponse.toLowerCase().contains("fault")) {
            throw new Exception("Error invoking work service (check server log)");
        }
    } finally {
        http.uninitialize();
    }
}
Also used : HTTPMixIn(org.switchyard.component.test.mixins.http.HTTPMixIn) StringPuller(org.switchyard.common.io.pull.StringPuller)

Aggregations

StringPuller (org.switchyard.common.io.pull.StringPuller)8 HTTPMixIn (org.switchyard.component.test.mixins.http.HTTPMixIn)7 HashSet (java.util.HashSet)1 SSLContext (javax.net.ssl.SSLContext)1 Scheme (org.apache.http.conn.scheme.Scheme)1 SchemeRegistry (org.apache.http.conn.scheme.SchemeRegistry)1 SSLSocketFactory (org.apache.http.conn.ssl.SSLSocketFactory)1