Search in sources :

Example 16 with DefaultHttpMethodRetryHandler

use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient method getEngineComplianceVersion.

public static String getEngineComplianceVersion(String url) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(url);
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$ //$NON-NLS-2$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", "complianceVersion") };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient.serviceFailed"), method.getStatusLine().toString(), //$NON-NLS-1$
            method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.5", e.getMessage()));
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient.6", e.getMessage()));
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Example 17 with DefaultHttpMethodRetryHandler

use of org.apache.commons.httpclient.DefaultHttpMethodRetryHandler in project tdi-studio-se by Talend.

the class SpagoBITalendEngineClient_0_5_0 method getEngineInfo.

private String getEngineInfo(String infoType) throws EngineUnavailableException, ServiceInvocationFailedException {
    String version;
    HttpClient client;
    PostMethod method;
    NameValuePair[] nameValuePairs;
    version = null;
    client = new HttpClient();
    method = new PostMethod(getServiceUrl(ENGINE_INFO_SERVICE));
    // Provide custom retry handler is necessary
    method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
    //$NON-NLS-1$
    nameValuePairs = new NameValuePair[] { new NameValuePair("infoType", infoType) };
    method.setRequestBody(nameValuePairs);
    try {
        // Execute the method.
        int statusCode = client.executeMethod(method);
        if (statusCode != HttpStatus.SC_OK) {
            throw new ServiceInvocationFailedException(Messages.getString("SpagoBITalendEngineClient_0_5_0.serviceExcFailed") + ENGINE_INFO_SERVICE, //$NON-NLS-1$
            method.getStatusLine().toString(), method.getResponseBodyAsString());
        } else {
            version = method.getResponseBodyAsString();
        }
    } catch (HttpException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.protocolViolation") + e.getMessage());
    } catch (IOException e) {
        //$NON-NLS-1$
        throw new EngineUnavailableException(Messages.getString("SpagoBITalendEngineClient_0_5_0.transportError") + e.getMessage());
    } finally {
        // Release the connection.
        method.releaseConnection();
    }
    return version;
}
Also used : ServiceInvocationFailedException(it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException) NameValuePair(org.apache.commons.httpclient.NameValuePair) EngineUnavailableException(it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException) PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) DefaultHttpMethodRetryHandler(org.apache.commons.httpclient.DefaultHttpMethodRetryHandler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

Aggregations

DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)17 IOException (java.io.IOException)12 HttpClient (org.apache.commons.httpclient.HttpClient)12 HttpException (org.apache.commons.httpclient.HttpException)10 GetMethod (org.apache.commons.httpclient.methods.GetMethod)6 PostMethod (org.apache.commons.httpclient.methods.PostMethod)6 Header (org.apache.commons.httpclient.Header)5 NameValuePair (org.apache.commons.httpclient.NameValuePair)5 HttpMethod (org.apache.commons.httpclient.HttpMethod)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)3 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)2 EngineUnavailableException (it.eng.spagobi.engines.talend.client.exception.EngineUnavailableException)2 ServiceInvocationFailedException (it.eng.spagobi.engines.talend.client.exception.ServiceInvocationFailedException)2 InputStream (java.io.InputStream)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 InflaterInputStream (java.util.zip.InflaterInputStream)2 ImageInputStream (javax.imageio.stream.ImageInputStream)2 Credentials (org.apache.commons.httpclient.Credentials)2 HeaderElement (org.apache.commons.httpclient.HeaderElement)2