Example usage for org.apache.http.entity.mime.content FileBody FileBody

List of usage examples for org.apache.http.entity.mime.content FileBody FileBody

Introduction

In this page you can find the example usage for org.apache.http.entity.mime.content FileBody FileBody.

Prototype

public FileBody(final File file) 

Source Link

Usage

From source file:com.qsoft.components.gallery.utils.GalleryUtils.java

private static MultipartEntity addParamsForUpload(File file, String imageType, String imageName,
        Long equipmentId, Long userId, String locationDTO, Long equipmentHistoryId)
        throws UnsupportedEncodingException {
    MultipartEntity mpEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    mpEntity.addPart(ConstantImage.IMAGE_FILE, new FileBody(file));
    mpEntity.addPart(ConstantImage.IMAGE_TYPE, new StringBody(imageType.toUpperCase()));
    mpEntity.addPart(ConstantImage.IMAGE_NAME, new StringBody(imageName.toUpperCase()));
    if (equipmentId != null) {
        mpEntity.addPart(ConstantImage.EQUIPMENT_ID, new StringBody(equipmentId.toString()));
    }// ww w . j av a 2s  . c  o m
    if (userId != null) {
        mpEntity.addPart(ConstantImage.USER_ID, new StringBody(userId.toString()));
    }
    if (equipmentHistoryId != null) {
        mpEntity.addPart(ConstantImage.EQUIPMENTHISTORY_ID, new StringBody(equipmentHistoryId.toString()));
    }
    mpEntity.addPart(ConstantImage.IMAGE_LOCATION_DTO, new StringBody(locationDTO));

    return mpEntity;
}

From source file:org.witness.ssc.xfer.utils.PublishingUtils.java

public Thread videoUploadToVideoBin(final Activity activity, final Handler handler,
        final String video_absolutepath, final String title, final String description,
        final String emailAddress, final long sdrecord_id) {

    Log.d(TAG, "doPOSTtoVideoBin starting");

    // Make the progress bar view visible.
    ((SSCXferActivity) activity).startedUploading();
    final Resources res = activity.getResources();

    Thread t = new Thread(new Runnable() {
        public void run() {
            // Do background task.

            boolean failed = false;

            HttpClient client = new DefaultHttpClient();

            if (useProxy) {
                HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT_HTTP);
                client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
            }//from   w w w . ja va2 s  .co m

            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

            URI url = null;
            try {
                url = new URI(res.getString(R.string.http_videobin_org_add));
            } catch (URISyntaxException e) {
                // Ours is a fixed URL, so not likely to get here.
                e.printStackTrace();
                return;

            }
            HttpPost post = new HttpPost(url);
            CustomMultiPartEntity entity = new CustomMultiPartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,
                    new ProgressListener() {
                        int lastPercent = 0;

                        @Override
                        public void transferred(long num) {

                            percentUploaded = (int) (((float) num) / ((float) totalLength) * 99f);
                            //Log.d(TAG, "percent uploaded: " + percentUploaded + " - " + num + " / " + totalLength);
                            if (lastPercent != percentUploaded) {
                                ((SSCXferActivity) activity).showProgress("uploading...", percentUploaded);
                                lastPercent = percentUploaded;
                            }
                        }

                    });

            File file = new File(video_absolutepath);
            entity.addPart(res.getString(R.string.video_bin_API_videofile), new FileBody(file));

            try {
                entity.addPart(res.getString(R.string.video_bin_API_api),
                        new StringBody("1", "text/plain", Charset.forName("UTF-8")));

                // title
                entity.addPart(res.getString(R.string.video_bin_API_title),
                        new StringBody(title, "text/plain", Charset.forName("UTF-8")));

                // description
                entity.addPart(res.getString(R.string.video_bin_API_description),
                        new StringBody(description, "text/plain", Charset.forName("UTF-8")));

            } catch (IllegalCharsetNameException e) {
                // error
                e.printStackTrace();
                failed = true;

            } catch (UnsupportedCharsetException e) {
                // error
                e.printStackTrace();
                return;
            } catch (UnsupportedEncodingException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            post.setEntity(entity);

            totalLength = entity.getContentLength();

            // Here we go!
            String response = null;
            try {
                response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8");
            } catch (ParseException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (ClientProtocolException e) {
                // error
                e.printStackTrace();
                failed = true;
            } catch (IOException e) {
                // error
                e.printStackTrace();
                failed = true;
            }

            client.getConnectionManager().shutdown();

            if (failed) {
                // Use the handler to execute a Runnable on the
                // main thread in order to have access to the
                // UI elements.
                handler.postDelayed(new Runnable() {
                    public void run() {
                        // Update UI

                        // Indicate back to calling activity the result!
                        // update uploadInProgress state also.

                        ((SSCXferActivity) activity).finishedUploading(false);

                        ((SSCXferActivity) activity)
                                .createNotification(res.getString(R.string.upload_to_videobin_org_failed_));
                    }
                }, 0);

                return;
            }

            Log.d(TAG, " video bin got back " + response);

            // XXX Convert to preference for auto-email on videobin post
            // XXX ADD EMAIL NOTIF to all other upload methods
            // stuck on YES here, if email is defined.

            if (emailAddress != null && response != null) {

                // EmailSender through IR controlled gmail system.
                SSLEmailSender sender = new SSLEmailSender(
                        activity.getString(R.string.automatic_email_username),
                        activity.getString(R.string.automatic_email_password)); // consider
                // this
                // public
                // knowledge.
                try {
                    sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(),
                            activity.getString(R.string.url_of_hosted_video_is_) + " " + response, // body.getText().toString(),
                            activity.getString(R.string.automatic_email_from), // from.getText().toString(),
                            emailAddress // to.getText().toString()
                    );
                } catch (Exception e) {
                    Log.e(TAG, e.getMessage(), e);
                }
            }

            // Log record of this URL in POSTs table
            dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id,
                    res.getString(R.string.http_videobin_org_add), response, "");

            // Use the handler to execute a Runnable on the
            // main thread in order to have access to the
            // UI elements.
            handler.postDelayed(new Runnable() {
                public void run() {
                    // Update UI

                    // Indicate back to calling activity the result!
                    // update uploadInProgress state also.

                    ((SSCXferActivity) activity).finishedUploading(true);
                    ((SSCXferActivity) activity)
                            .createNotification(res.getString(R.string.upload_to_videobin_org_succeeded_));

                }
            }, 0);
        }
    });

    t.start();

    return t;

}

From source file:ecblast.test.EcblastTest.java

public String executeCompareReactions(File queryFile, File targetFile) {
    String urlString = "http://localhost:8080/ecblast-rest/compare";
    DefaultHttpClient client;/*  ww  w . j  av  a2 s  . c  o m*/
    client = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(urlString);

    try {
        //Set various attributes
        MultipartEntity multiPartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        FileBody queryFileBody = new FileBody(queryFile);
        //Prepare payload
        multiPartEntity.addPart("q", queryFileBody);
        multiPartEntity.addPart("Q", new StringBody("RXN", "text/plain", Charset.forName("UTF-8")));

        FileBody targetFileBody = new FileBody(targetFile);
        multiPartEntity.addPart("t", targetFileBody);
        multiPartEntity.addPart("T", new StringBody("RXN", "text/plain", Charset.forName("UTF-8")));
        //Set to request body
        postRequest.setEntity(multiPartEntity);

        //Send request
        HttpResponse response = client.execute(postRequest);

        //Verify response if any
        if (response != null) {
            System.out.println(response.getStatusLine().getStatusCode());

            return response.toString();
        }
    } catch (IOException ex) {
        return null;
    }
    return null;

}

From source file:org.hlc.http.resetfull.network.HttpExecutor.java

/**
 * Do post./*from  ww  w  .ja v  a  2  s . c  o m*/
 *
 * @param <E> the element type
 * @param url the url
 * @param paramter the paramter
 * @param files the files
 * @param readTimeout the read timeout
 * @param result the result
 * @return the e
 */
public <E> E doPost(String url, Map<String, Object> paramter, Map<String, File> files, int readTimeout,
        MessageResolve<E> result) {
    MultipartEntity multipartEntity = new MultipartEntity();
    try {
        if (paramter != null) {
            for (String name : paramter.keySet()) {
                multipartEntity.addPart(name,
                        new StringBody(String.valueOf(paramter.get(name)), Charset.forName(HTTP.UTF_8)));
            }
        }
        if (files != null) {
            for (String name : files.keySet()) {
                multipartEntity.addPart(name, new FileBody(files.get(name)));
            }
        }
    } catch (Exception e) {
        Log.debug(e.getMessage());
        result.error(NETWORK_ERROR, DEFUALT_MESSAGE_TYPE, e.getMessage());
        return null;
    }
    HttpPost httpPost = new HttpPost(url);
    httpPost.setEntity(multipartEntity);
    return doExecute(httpPost, readTimeout, result);
}

From source file:com.android.volley.toolbox.http.HttpClientStack.java

private static void setEntityIfNonEmptyBody(HttpEntityEnclosingRequestBase httpRequest, Request<?> request)
        throws IOException, AuthFailureError {

    if (request.containsFile()) {
        /* MultipartEntity multipartEntity = new MultipartEntity();
        final Map<String, MultiPartParam> multipartParams = request.getMultiPartParams();
        for (String key : multipartParams.keySet()) {
        multipartEntity.addPart(new StringPart(key, multipartParams.get(key).value));
        }//  ww w. j a va  2s  . c  om
                
        final Map<String, File> filesToUpload = request.getFilesToUpload();
        if(filesToUpload!=null){
        for (String key : filesToUpload.keySet()) {
        File file = filesToUpload.get(key) ;
                
        if (file==null || !file.exists()) {
         throw new IOException(String.format("File not found: %s",file.getAbsolutePath()));
        }
                
        if (file.isDirectory()) {
         throw new IOException(String.format("File is a directory: %s", file.getAbsolutePath()));
        }
                
        multipartEntity.addPart(new FilePart(key, file, null, null));
        }
        }
        httpRequest.setEntity(multipartEntity);
        */
        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
        final Map<String, MultiPartParam> multipartParams = request.getMultiPartParams();
        for (String key : multipartParams.keySet()) {
            multipartEntity.addPart(key,
                    new StringBody(multipartParams.get(key).value, "text/plain", Charset.forName("UTF-8")));
        }

        final Map<String, File> filesToUpload = request.getFilesToUpload();
        if (filesToUpload != null) {
            for (String key : filesToUpload.keySet()) {
                File file = filesToUpload.get(key);

                if (file == null || !file.exists()) {
                    throw new IOException(String.format("File not found: %s", file.getAbsolutePath()));
                }

                if (file.isDirectory()) {
                    throw new IOException(String.format("File is a directory: %s", file.getAbsolutePath()));
                }
                multipartEntity.addPart(key, new FileBody(file));
            }
        }
        httpRequest.setEntity(multipartEntity);

    } else {
        byte[] body = request.getBody();
        if (body != null) {
            HttpEntity entity = new ByteArrayEntity(body);
            httpRequest.setEntity(entity);
        }
    }
}

From source file:com.liferay.ide.server.remote.ServerManagerConnection.java

public Object updateApplication(String appName, String absolutePath, IProgressMonitor monitor)
        throws APIException {
    try {/*from   w w w .ja  v a  2  s .  c om*/
        File file = new File(absolutePath);

        FileBody fileBody = new FileBody(file);

        MultipartEntity entity = new MultipartEntity();

        entity.addPart(file.getName(), fileBody);

        HttpPut httpPut = new HttpPut();

        httpPut.setEntity(entity);

        Object response = httpJSONAPI(httpPut, _getUpdateURI(appName));

        if (response instanceof JSONObject) {
            JSONObject jsonObject = (JSONObject) response;

            if (_isSuccess(jsonObject)) {
                System.out.println("updateApplication: success.\n\n");
            } else {
                if (_isError(jsonObject)) {
                    return jsonObject.getString("error");
                } else {
                    return "updateApplication error " + _getDeployURI(appName);
                }
            }
        }

        httpPut.releaseConnection();
    } catch (Exception e) {
        e.printStackTrace();

        return e.getMessage();
    }

    return null;
}

From source file:org.ensembl.gti.seqstore.database.cramstore.EnaCramSubmitter.java

protected void submitXml(Collection<File> files) {
    try {//from w w w  . j  a v  a2s.co  m
        HttpPost post = new HttpPost(submitUri.replaceAll("USERNAME", user).replaceAll("PASSWORD", password));
        Date date = new Date();
        File xml = getAnalysisXml(date, files);
        log.info("XML written to " + xml.getPath());
        File subXml = getSubmissionXml(date, xml);

        FileBody xmlBody = new FileBody(xml);
        FileBody subBody = new FileBody(subXml);
        HttpEntity entity = MultipartEntityBuilder.create().addPart("ANALYSIS", xmlBody)
                .addPart("SUBMISSION", subBody).build();
        post.setEntity(entity);

        log.info("Uploading XML as post");
        HttpResponse response = httpClient.execute(post);
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new EnaSubmissionException(
                    "Could not submit XML to ENA: " + response.getStatusLine().toString());
        }
        log.info("Status: " + response.getStatusLine());
        String receipt = IOUtils.toString(response.getEntity().getContent());
        log.info("Receipt: " + receipt);
        Document receiptDoc = parseReceipt(receipt);

        if (isSuccess(receiptDoc)) {
            log.info("Successfully submitted to ENA with analysis accession "
                    + getElemAttrib(receiptDoc, "ANALYSIS", "accession") + " and submission accession "
                    + getElemAttrib(receiptDoc, "SUBMISSION", "accession"));
        } else {
            String msg = "Submission failed: " + StringUtils.join(getElems(receiptDoc, "ERROR"), "; ");
            log.error(msg);
            throw new EnaSubmissionException(msg);
        }
        for (File file : files) {
            log.info("Deleting file " + file);
            file.delete();
        }
        log.info("Completed submitting XML");
    } catch (IOException | UnsupportedOperationException e) {
        throw new EnaSubmissionException("Unexpected error during file submission", e);
    }
}

From source file:org.wso2.appcloud.integration.test.utils.clients.ApplicationClient.java

public void createNewApplication(String applicationName, String runtime, String appTypeName,
        String applicationRevision, String applicationDescription, String uploadedFileName,
        String runtimeProperties, String tags, File uploadArtifact, boolean isNewVersion,
        String applicationContext, String conSpec, boolean setDefaultVersion, String appCreationMethod,
        String gitRepoUrl, String gitRepoBranch, String projectRoot) throws AppCloudIntegrationTestException {

    HttpClient httpclient = null;/*from w w  w  .  j a  v  a2s  .c o  m*/
    org.apache.http.HttpResponse response = null;
    int timeout = (int) AppCloudIntegrationTestUtils.getTimeOutPeriod();
    try {
        httpclient = HttpClients.custom().setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE).build();
        RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout)
                .setConnectTimeout(timeout).build();
        HttpPost httppost = new HttpPost(this.endpoint);
        httppost.setConfig(requestConfig);

        MultipartEntityBuilder builder = MultipartEntityBuilder.create();
        builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);

        builder.addPart(PARAM_NAME_ACTION, new StringBody(CREATE_APPLICATION_ACTION, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APP_CREATION_METHOD,
                new StringBody(appCreationMethod, ContentType.TEXT_PLAIN));
        if (GITHUB.equals(appCreationMethod)) {
            builder.addPart(PARAM_NAME_GIT_REPO_URL, new StringBody(gitRepoUrl, ContentType.TEXT_PLAIN));
            builder.addPart(PARAM_NAME_GIT_REPO_BRANCH, new StringBody(gitRepoBranch, ContentType.TEXT_PLAIN));
            builder.addPart(PARAM_NAME_PROJECT_ROOT, new StringBody(projectRoot, ContentType.TEXT_PLAIN));
        } else if (DEFAULT.equals(appCreationMethod)) {
            builder.addPart(PARAM_NAME_FILE_UPLOAD, new FileBody(uploadArtifact));
            builder.addPart(PARAM_NAME_UPLOADED_FILE_NAME,
                    new StringBody(uploadedFileName, ContentType.TEXT_PLAIN));
            builder.addPart(PARAM_NAME_IS_FILE_ATTACHED,
                    new StringBody(Boolean.TRUE.toString(), ContentType.TEXT_PLAIN));//Setting true to send the file in request
        }
        builder.addPart(PARAM_NAME_CONTAINER_SPEC, new StringBody(conSpec, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APPLICATION_NAME, new StringBody(applicationName, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APPLICATION_DESCRIPTION,
                new StringBody(applicationDescription, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_RUNTIME, new StringBody(runtime, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APP_TYPE_NAME, new StringBody(appTypeName, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APP_CONTEXT, new StringBody(applicationContext, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_APPLICATION_REVISION,
                new StringBody(applicationRevision, ContentType.TEXT_PLAIN));

        builder.addPart(PARAM_NAME_PROPERTIES, new StringBody(runtimeProperties, ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_TAGS, new StringBody(tags, ContentType.TEXT_PLAIN));

        builder.addPart(PARAM_NAME_IS_NEW_VERSION,
                new StringBody(Boolean.toString(isNewVersion), ContentType.TEXT_PLAIN));
        builder.addPart(PARAM_NAME_SET_DEFAULT_VERSION,
                new StringBody(Boolean.toString(setDefaultVersion), ContentType.TEXT_PLAIN));

        httppost.setEntity(builder.build());
        httppost.setHeader(HEADER_COOKIE, getRequestHeaders().get(HEADER_COOKIE));
        response = httpclient.execute(httppost);

        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            String result = EntityUtils.toString(response.getEntity());
            throw new AppCloudIntegrationTestException("CreateNewApplication failed " + result);
        }

    } catch (ConnectTimeoutException | java.net.SocketTimeoutException e1) {
        // In most of the cases, even though connection is timed out, actual activity is completed.
        // If application is not created, in next test case, it will be identified.
        log.warn("Failed to get 200 ok response from endpoint:" + endpoint, e1);
    } catch (IOException e) {
        log.error("Failed to invoke application creation API.", e);
        throw new AppCloudIntegrationTestException("Failed to invoke application creation API.", e);
    } finally {
        HttpClientUtils.closeQuietly(response);
        HttpClientUtils.closeQuietly(httpclient);
    }
}

From source file:io.undertow.servlet.test.multipart.MultiPartTestCase.java

@Test
public void testMultiPartIndividualFileToLarge() throws IOException {
    TestHttpClient client = new TestHttpClient();
    try {/*  ww  w .  j a  va2s  .com*/
        String uri = DefaultServer.getDefaultServerURL() + "/servletContext/3";
        HttpPost post = new HttpPost(uri);
        MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        entity.addPart("formValue", new StringBody("myValue", "text/plain", StandardCharsets.UTF_8));
        entity.addPart("file",
                new FileBody(new File(MultiPartTestCase.class.getResource("uploadfile.txt").getFile())));

        post.setEntity(entity);
        HttpResponse result = client.execute(post);
        String response = HttpClientUtils.readResponse(result);
        Assert.assertEquals("TEST FAILED: wrong response code\n" + response, StatusCodes.INTERNAL_SERVER_ERROR,
                result.getStatusLine().getStatusCode());
    } finally {
        client.getConnectionManager().shutdown();
    }
}

From source file:core.AbstractTest.java

private int httpRequest(String sUrl, String sMethod, JsonNode payload, Map<String, String> mParameters) {
    Logger.info("\n\nREQUEST:\n" + sMethod + " " + sUrl + "\nHEADERS: " + mHeaders + "\nParameters: "
            + mParameters + "\nPayload: " + payload + "\n");
    HttpURLConnection conn = null;
    BufferedReader br = null;/*w w w  .j  a v  a2 s  .  com*/
    int nRet = 0;
    boolean fIsMultipart = false;

    try {
        setStatusCode(-1);
        setResponse(null);
        conn = getHttpConnection(sUrl, sMethod);
        if (mHeaders.size() > 0) {
            Set<String> keys = mHeaders.keySet();
            for (String sKey : keys) {
                conn.addRequestProperty(sKey, mHeaders.get(sKey));
                if (sKey.equals(HTTP.CONTENT_TYPE)) {
                    if (mHeaders.get(sKey).startsWith(MediaType.MULTIPART_FORM_DATA)) {
                        fIsMultipart = true;
                    }
                }
            }
        }

        if (payload != null || mParameters != null) {
            DataOutputStream out = new DataOutputStream(conn.getOutputStream());

            try {
                if (payload != null) {
                    //conn.setRequestProperty("Content-Length", "" + node.toString().length());
                    out.writeBytes(payload.toString());
                }

                if (mParameters != null) {
                    Set<String> sKeys = mParameters.keySet();

                    if (fIsMultipart) {
                        out.writeBytes("--" + BOUNDARY + "\r\n");
                    }

                    for (String sKey : sKeys) {
                        if (fIsMultipart) {
                            out.writeBytes("Content-Disposition: form-data; name=\"" + sKey + "\"\r\n\r\n");
                            out.writeBytes(mParameters.get(sKey));
                            out.writeBytes("\r\n");
                            out.writeBytes("--" + BOUNDARY + "--\r\n");
                        } else {
                            out.writeBytes(URLEncoder.encode(sKey, "UTF-8"));
                            out.writeBytes("=");
                            out.writeBytes(URLEncoder.encode(mParameters.get(sKey), "UTF-8"));
                            out.writeBytes("&");
                        }
                    }

                    if (fIsMultipart) {
                        if (nvpFile != null) {
                            File f = Play.application().getFile(nvpFile.getName());
                            if (f == null) {
                                assertFail("Cannot find file <" + nvpFile.getName() + ">");
                            }
                            FileBody fb = new FileBody(f);
                            out.writeBytes("Content-Disposition: form-data; name=\"" + PARAM_FILE
                                    + "\";filename=\"" + fb.getFilename() + "\"\r\n");
                            out.writeBytes("Content-Type: " + nvpFile.getValue() + "\r\n\r\n");
                            out.write(getResource(nvpFile.getName()));
                        }
                        out.writeBytes("\r\n--" + BOUNDARY + "--\r\n");
                    }
                }
            } catch (Exception ex) {
                assertFail("Send request: " + ex.getMessage());
            } finally {
                try {
                    out.flush();
                } catch (Exception ex) {
                }
                try {
                    out.close();
                } catch (Exception ex) {
                }
            }
        }

        nRet = conn.getResponseCode();
        setStatusCode(nRet);
        if (nRet / 100 != 2) {
            if (conn.getErrorStream() != null) {
                br = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
            }
        } else {
            if (conn.getInputStream() != null) {
                br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            }
        }

        if (br != null) {
            String temp = null;
            StringBuilder sb = new StringBuilder(1024);
            while ((temp = br.readLine()) != null) {
                sb.append(temp).append("\n");
            }
            setResponse(sb.toString().trim());
        }
        Logger.info("\nRESPONSE\nHTTP code: " + nRet + "\nContent: " + sResponse + "\n");
    } catch (Exception ex) {
        assertFail("httpRequest: " + ex.getMessage());
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (Exception ex) {
            }
        }
        if (conn != null) {
            conn.disconnect();
        }
    }

    return nRet;
}