List of usage examples for org.apache.commons.httpclient HttpStatus getStatusText
public static String getStatusText(int statusCode)
From source file:com.cloudbees.api.BeesClientBase.java
protected String executeUpload(String uploadURL, Map<String, String> params, Map<String, File> files, UploadProgress writeListener) throws Exception { HashMap<String, String> clientParams = getDefaultParameters(); clientParams.putAll(params);//from w ww . j a va 2s . c om PostMethod filePost = new PostMethod(uploadURL); try { ArrayList<Part> parts = new ArrayList<Part>(); int fileUploadSize = 0; for (Map.Entry<String, File> fileEntry : files.entrySet()) { FilePart filePart = new FilePart(fileEntry.getKey(), fileEntry.getValue()); parts.add(filePart); fileUploadSize += filePart.length(); //TODO: file params are not currently included in the signature, // we should hash the file contents so we can verify them } for (Map.Entry<String, String> entry : clientParams.entrySet()) { parts.add(new StringPart(entry.getKey(), entry.getValue())); } // add the signature String signature = calculateSignature(clientParams); parts.add(new StringPart("sig", signature)); ProgressUploadEntity uploadEntity = new ProgressUploadEntity(parts.toArray(new Part[parts.size()]), filePost.getParams(), writeListener, fileUploadSize); filePost.setRequestEntity(uploadEntity); HttpClient client = HttpClientHelper.createClient(this.beesClientConfiguration); client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); int status = client.executeMethod(filePost); String response = getResponseString(filePost.getResponseBodyAsStream()); if (status == HttpStatus.SC_OK) { trace("upload complete, response=" + response); } else { trace("upload failed, response=" + HttpStatus.getStatusText(status)); } return response; } finally { filePost.releaseConnection(); } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies//from www . ja v a 2s . com * get a session using the same existing previously requested * response cookies. * @throws MojoExecutionException * if any error occurred during this process. */ @SuppressWarnings("deprecation") private void getSession(final Cookie[] cookies) throws MojoExecutionException { PostMethod loginPost = new PostMethod(crxPath + "/login.jsp"); loginPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("login to " + loginPost.getPath()); loginPost.setParameter("Workspace", workspace); loginPost.setParameter("UserId", login); loginPost.setParameter("Password", password); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(loginPost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_MOVED_TEMPORARILY) { getLog().info("Login successful"); } else { logResponseDetails(loginPost); throw new MojoExecutionException("Login failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { loginPost.releaseConnection(); } }
From source file:com.serena.rlc.provider.jenkins.client.JenkinsClient.java
private JenkinsClientException createHttpError(HttpResponse response) { String message;//from www .j a va 2s. com try { StatusLine statusLine = response.getStatusLine(); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; StringBuffer responsePayload = new StringBuffer(); // Read response until the end while ((line = rd.readLine()) != null) { responsePayload.append(line); } message = String.format("request not successful: %d %s. Reason: %s", statusLine.getStatusCode(), HttpStatus.getStatusText(statusLine.getStatusCode()), responsePayload); logger.info(message); if (new Integer(HttpStatus.SC_UNAUTHORIZED).equals(statusLine.getStatusCode())) { return new JenkinsClientException("Invalid credentials provided."); } else if (new Integer(HttpStatus.SC_NOT_FOUND).equals(statusLine.getStatusCode())) { return new JenkinsClientException("Jenkins: Request URL not found."); } else if (new Integer(HttpStatus.SC_BAD_REQUEST).equals(statusLine.getStatusCode())) { return new JenkinsClientException("Jenkins: Bad request. " + responsePayload); } } catch (IOException e) { return new JenkinsClientException("Jenkins: Can't read response"); } return new JenkinsClientException(message); }
From source file:com.apatar.http.HttpNode.java
@Override protected void TransformTDBtoRDB(int mode) { DataBaseTools.completeTransfer();//from ww w . j a v a 2 s. c o m HttpConnection conn = (HttpConnection) ApplicationData.getProject().getProjectData(getConnectionDataID()) .getData(); String url = conn.getUrl(); HttpRequestMethod httpRequestMethod = (HttpRequestMethod) conn.getMethod(); TableInfo ti = getTiForConnection(IN_CONN_POINT_NAME); TableInfo tiOut = getTiForConnection(OUT_CONN_POINT_NAME); List<Record> selectionList = DataBaseTools.intersectionRecords(tiOut.getRecords(), ti.getRecords(), true); // read values from result set and put it in request SQLQueryString sqs = DataBaseTools.CreateSelectString(ApplicationData.getTempDataBase().getDataBaseInfo(), new SQLCreationData(selectionList, ti.getTableName()), null); if (sqs == null) { return; } ResultSet rs; try { rs = DataBaseTools.executeSelect(sqs, ApplicationData.getTempJDBC()); while (rs.next()) { KeyInsensitiveMap rsData = DataBaseTools.GetDataFromRS(rs); HttpMethod hm; if (httpRequestMethod == HttpRequestMethod.post) { hm = sendPost(url, rsData); } else { hm = sendGet(url, rsData); } HttpClient client = new HttpClient(); if (ApplicationData.httpClient.isUseProxy()) { HostConfiguration hostConfig = client.getHostConfiguration(); hostConfig.setProxy(ApplicationData.httpClient.getHost(), ApplicationData.httpClient.getPort()); String proxyUser = ApplicationData.httpClient.getUserName(); if (proxyUser != null) { client.getState().setProxyCredentials(AuthScope.ANY, new UsernamePasswordCredentials( proxyUser, ApplicationData.httpClient.getPassword())); } } client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(hm); KeyInsensitiveMap datas = new KeyInsensitiveMap(); if (status != HttpStatus.SC_OK) { datas.put("Response", "Upload failed, response=" + HttpStatus.getStatusText(status)); } else { datas.put("Response", hm.getResponseBodyAsString()); } ti = getTiForConnection(OUT_CONN_POINT_NAME); List<Record> recs = getTiForConnection(AbstractDataBaseNode.OUT_CONN_POINT_NAME).getSchemaTable() .getRecords(); for (int j = 1; j < recs.size(); j++) { Record rec = recs.get(j); datas.put(rec.getFieldName(), rs.getObject(rec.getFieldName())); } DataBaseTools.insertData(new DataProcessingInfo(ApplicationData.getTempDataBase().getDataBaseInfo(), ti.getTableName(), ti.getRecords(), ApplicationData.getTempJDBC()), datas); } } catch (Exception e) { e.printStackTrace(); } DataBaseTools.completeTransfer(); }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.candidacies.GenericCandidaciesDA.java
public ActionForward downloadFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { final GenericApplication application = getDomainObject(request, "applicationExternalId"); final String confirmationCode = (String) getFromRequest(request, "confirmationCode"); final GenericApplicationFile file = getDomainObject(request, "fileExternalId"); if (application != null && file != null && file.getGenericApplication() == application && ((confirmationCode != null && application.getConfirmationCode() != null && application.getConfirmationCode().equals(confirmationCode)) || application.getGenericApplicationPeriod().isCurrentUserAllowedToMange())) { response.setContentType(file.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); response.setContentLength(file.getSize().intValue()); final DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(file.getContent());//from w w w .java 2 s .co m dos.close(); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return null; }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies/* w w w . j a v a 2 s . c o m*/ * the previous requests cookies to keep in the same session. * @throws MojoExecutionException * if any error occurs during this process. */ @SuppressWarnings("deprecation") private void uploadPackage(final Cookie[] cookies) throws MojoExecutionException { PostMethod filePost = new PostMethod(crxPath + "/packmgr/list.jsp"); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("Uploading " + jarfile + " to " + filePost.getPath()); File jarFile = new File(jarfile); Part[] parts = { new FilePart("file", jarFile) }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(filePost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_MOVED_TEMPORARILY) { getLog().info("Upload complete"); } else { logResponseDetails(filePost); throw new MojoExecutionException( "Package upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { filePost.releaseConnection(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.candidacies.GenericCandidaciesDA.java
public ActionForward downloadRecomendationFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { final String confirmationCode = (String) getFromRequest(request, "confirmationCode"); final GenericApplicationLetterOfRecomentation file = getDomainObject(request, "fileExternalId"); if (file != null && file.getRecomentation() != null && file.getRecomentation().getConfirmationCode() != null && ((file.getRecomentation().getGenericApplication().getGenericApplicationPeriod() .isCurrentUserAllowedToMange()) || file.getRecomentation().getConfirmationCode().equals(confirmationCode))) { response.setContentType(file.getContentType()); response.addHeader("Content-Disposition", "attachment; filename=\"" + file.getFilename() + "\""); response.setContentLength(file.getSize().intValue()); final DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(file.getContent());/*from ww w. j a va2s. com*/ dos.close(); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return null; }
From source file:is.idega.block.finance.business.sp.SPDataInsert.java
private void sendCreateClaimsRequest(BankFileManager bfm) { PostMethod filePost = new PostMethod(POST_METHOD); File file = new File(FILE_NAME); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try {//from w w w .j a va 2 s. co m StringPart userPart = new StringPart("notendanafn", bfm.getUsername()); StringPart pwdPart = new StringPart("password", bfm.getPassword()); StringPart clubssnPart = new StringPart("KtFelags", bfm.getClaimantSSN()); FilePart filePart = new FilePart("Skra", file); Part[] parts = { userPart, pwdPart, clubssnPart, filePart }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } }
From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.candidacies.GenericCandidaciesDA.java
public ActionForward deleteFile(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException { final GenericApplication application = getDomainObject(request, "applicationExternalId"); final String confirmationCode = (String) getFromRequest(request, "confirmationCode"); final GenericApplicationFile file = getDomainObject(request, "fileExternalId"); if (application != null && confirmationCode != null && application.getConfirmationCode() != null && application.getConfirmationCode().equals(confirmationCode) && file != null && file.getGenericApplication() == application) { file.deleteFromApplication();// w ww . j av a 2s . com } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return confirmEmail(mapping, form, request, response); }
From source file:is.idega.block.finance.business.sp.SPDataInsertTest.java
private MultipartPostMethod sendCreateClaimsRequest() { /*/*from w w w.j a v a 2 s. co m*/ * HttpClient client = new HttpClient(); client.setStrictMode(false); * MultipartPostMethod post = new MultipartPostMethod(SITE + * POST_METHOD); File file = new File(FILE_NAME); * * try { post.addParameter("notendanafn", "lolo7452");// "aistest"); * post.addParameter("password", "12345felix"); * post.addParameter("KtFelags", "6812933379");// "5709902259"); * post.addParameter("Skra", file); * * post.setDoAuthentication(false); client.executeMethod(post); * * System.out.println("responseString: " + * post.getResponseBodyAsString()); } catch (FileNotFoundException e1) { * e1.printStackTrace(); } catch (IOException e2) { * e2.printStackTrace(); } finally { post.releaseConnection(); } return * post; */ PostMethod filePost = new PostMethod(SITE + POST_METHOD); File file = new File(FILE_NAME); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { StringPart userPart = new StringPart("notendanafn", "lolo7452"); StringPart pwdPart = new StringPart("password", "12345felix"); StringPart clubssnPart = new StringPart("KtFelags", "6812933379"); FilePart filePart = new FilePart("Skra", file); Part[] parts = { userPart, pwdPart, clubssnPart, filePart }; filePost.setRequestEntity(new MultipartRequestEntity(parts, filePost.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(filePost); if (status == HttpStatus.SC_OK) { System.out.println("Upload complete, response=" + filePost.getResponseBodyAsString()); } else { System.out.println("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { ex.printStackTrace(); } finally { filePost.releaseConnection(); } return null; /* * PostMethod authpost = new PostMethod(SITE + POST_METHOD); * * authpost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, * true); try { * * HttpClient client = new HttpClient(); * client.getHttpConnectionManager().getParams().setConnectionTimeout( * 5000); * * File file = new File(FILE_NAME); // Prepare login parameters * NameValuePair inputFile = new NameValuePair("xmldata", file); * authpost.setRequestBody(new NameValuePair[] { inputFile }); * * int status = client.executeMethod(authpost); System.out.println("Form * post: " + authpost.getStatusLine().toString()); if (status == * HttpStatus.SC_OK) { System.out.println("Submit complete, response=" + * authpost.getResponseBodyAsString()); } else { * System.out.println("Submit failed, response=" + * HttpStatus.getStatusText(status)); } } catch (Exception ex) { * ex.printStackTrace(); } finally { authpost.releaseConnection(); } */ }