Search in sources :

Example 61 with HttpResponse

use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class paloconnection method sendToServer.

public HttpEntity sendToServer(List<NameValuePair> qparams, String strAPIUrl) throws paloexception {
    try {
        URI uri = URIUtils.createURI("http", strServer, Integer.valueOf(strPort), strAPIUrl, URLEncodedUtils.format(qparams, "UTF-8"), null);
        HttpGet req = new HttpGet(uri);
        // System.out.println(req.getURI());
        // Send to Server
        HttpResponse rsp = paloHttpClient.execute(paloTargetHost, req);
        HttpEntity entity = rsp.getEntity();
        if (rsp.getStatusLine().getStatusCode() != 200) {
            // Error had been occured
            // Close Connection and thend raise paloexception error
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            paloexception plX = new paloexception(csv.get(0), csv.get(1), csv.get(2));
            csv.close();
            entity.consumeContent();
            // paloHttpClient.getConnectionManager().shutdown();
            throw (plX);
        } else {
            return entity;
        }
    } catch (Exception e) {
        // if(paloHttpClient!=null)paloHttpClient.getConnectionManager().shutdown();
        throw new paloexception(e.getMessage());
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI)

Example 62 with HttpResponse

use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class DynamicsCRMClient method createAndExecuteRequest.

/**
     * Created and executes a request
     * 
     * @param uri the request URI
     * @param httpEntity the entity to send.
     * @param method HTTP method
     * 
     * @return the response to the request.
     * @throws ServiceUnavailableException
     */
protected HttpResponse createAndExecuteRequest(URI uri, HttpEntity httpEntity, HttpMethod method) throws ServiceUnavailableException {
    boolean hasRetried = false;
    while (true) {
        try {
            httpClient = (DefaultHttpClient) httpClientFactory.create(null, null);
            HttpRequestBase request = null;
            if (method == HttpMethod.POST) {
                request = new HttpPost(uri);
            } else if (method == HttpMethod.PATCH) {
                request = new HttpPatch(uri);
            } else if (method == HttpMethod.DELETE) {
                request = new HttpDelete(uri);
            } else {
                throw new HttpClientException("Unsupported operation:" + method);
            }
            request.addHeader(HttpHeader.AUTHORIZATION, "Bearer " + authResult.getAccessToken());
            if (request instanceof HttpEntityEnclosingRequestBase) {
                ((HttpEntityEnclosingRequestBase) request).setEntity(httpEntity);
            }
            HttpResponse response = httpClient.execute(request);
            if (isResponseSuccess(response.getStatusLine().getStatusCode())) {
                request.releaseConnection();
                EntityUtils.consume(response.getEntity());
                return response;
            } else {
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && !hasRetried) {
                    refreshToken();
                    hasRetried = true;
                    continue;
                }
                HttpEntity entity = response.getEntity();
                String message = null;
                if (entity != null) {
                    message = odataClient.getDeserializer(ContentType.JSON).toError(entity.getContent()).getMessage();
                } else {
                    message = response.getStatusLine().getReasonPhrase();
                }
                throw new HttpClientException(message);
            }
        } catch (Exception e) {
            throw new HttpClientException(e);
        }
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpRequestBase(org.apache.http.client.methods.HttpRequestBase) HttpEntityEnclosingRequestBase(org.apache.http.client.methods.HttpEntityEnclosingRequestBase) HttpClientException(org.apache.olingo.client.api.http.HttpClientException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpEntity(org.apache.http.HttpEntity) HttpResponse(org.apache.http.HttpResponse) HttpPatch(org.apache.olingo.client.core.http.HttpPatch) URISyntaxException(java.net.URISyntaxException) ServiceUnavailableException(javax.naming.ServiceUnavailableException) ODataClientErrorException(org.apache.olingo.client.api.communication.ODataClientErrorException) HttpClientException(org.apache.olingo.client.api.http.HttpClientException)

Example 63 with HttpResponse

use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class WsdlTokenManager method getSOAPResponse.

private static String getSOAPResponse(URI issuerUri, String soapEnvelope) {
    HttpResponse response = null;
    // Create the request that will submit the request to the server
    try {
        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 180000);
        HttpClient client = new SystemDefaultHttpClient(params);
        HttpPost post = new HttpPost(issuerUri);
        StringEntity entity = new StringEntity(soapEnvelope);
        post.setHeader("Content-Type", "application/soap+xml; charset=UTF-8");
        post.setEntity(entity);
        response = client.execute(post);
        return EntityUtils.toString(response.getEntity());
    } catch (ClientProtocolException e) {
        logger.error(e.getMessage());
    } catch (IOException e) {
        logger.error(e.getMessage());
    }
    return null;
}
Also used : SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) BasicHttpParams(org.apache.http.params.BasicHttpParams) HttpParams(org.apache.http.params.HttpParams) HttpClient(org.apache.http.client.HttpClient) SystemDefaultHttpClient(org.apache.http.impl.client.SystemDefaultHttpClient) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) BasicHttpParams(org.apache.http.params.BasicHttpParams) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 64 with HttpResponse

use of org.apache.http.HttpResponse in project tdi-studio-se by Talend.

the class RestClient method executePostRequest.

private HttpResponse executePostRequest(String apiURI, String payloadAsString) {
    try {
        HttpPost postRequest = new HttpPost(bonitaURI + apiURI);
        StringEntity input = new StringEntity(payloadAsString);
        input.setContentType("application/json");
        postRequest.setEntity(input);
        HttpResponse response = httpClient.execute(postRequest, httpContext);
        return response;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) HttpResponse(org.apache.http.HttpResponse) ClientProtocolException(org.apache.http.client.ClientProtocolException) HttpHostConnectException(org.apache.http.conn.HttpHostConnectException) IOException(java.io.IOException)

Example 65 with HttpResponse

use of org.apache.http.HttpResponse in project selenium-tests by Wikia.

the class GraphApi method createFacebookTestUser.

public HashMap<String, String> createFacebookTestUser(String appId) {
    try {
        HttpResponse response = createTestUser(appId);
        String entity = EntityUtils.toString(response.getEntity());
        return new Gson().fromJson(entity, new TypeToken<HashMap<String, String>>() {
        }.getType());
    } catch (IOException e) {
        PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    } catch (URISyntaxException e) {
        PageObjectLogging.log(URI_SYNTAX_EXCEPTION, ExceptionUtils.getStackTrace(e), false);
        throw new WebDriverException(ERROR_MESSAGE);
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) HttpResponse(org.apache.http.HttpResponse) Gson(com.google.gson.Gson) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

HttpResponse (org.apache.http.HttpResponse)4168 Test (org.junit.Test)2110 HttpGet (org.apache.http.client.methods.HttpGet)1770 IOException (java.io.IOException)1000 URI (java.net.URI)817 HttpPost (org.apache.http.client.methods.HttpPost)699 HttpClient (org.apache.http.client.HttpClient)550 HttpEntity (org.apache.http.HttpEntity)496 TestHttpClient (io.undertow.testutils.TestHttpClient)403 InputStream (java.io.InputStream)373 Header (org.apache.http.Header)370 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)333 StringEntity (org.apache.http.entity.StringEntity)332 HttpPut (org.apache.http.client.methods.HttpPut)310 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)307 ArrayList (java.util.ArrayList)296 Identity (org.olat.core.id.Identity)262 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)237 File (java.io.File)192 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)191