List of usage examples for org.apache.commons.httpclient HttpStatus getStatusText
public static String getStatusText(int statusCode)
From source file:is.idega.block.finance.business.kb.KBDataInsert.java
/** * Sends a http multipart post method to KBBanki to create the claims * // w w w. j a va 2 s. co m * @param bfm * @param groupId * @return */ private void sendCreateClaimsRequest(BankFileManager bfm) { /* HttpClient client = new HttpClient(); MultipartPostMethod post = new MultipartPostMethod(POST_METHOD); File file = new File(FILE_NAME); System.out.println("!!!kb:"); System.out.println("username = " + bfm.getUsername()); System.out.println("password = " + bfm.getPassword()); try { post.addParameter("cguser", bfm.getUsername());// "IK66TEST" post.addParameter("cgpass", bfm.getPassword());// "KBIK66" post.addParameter("cgutli", "0"); post.addParameter("cgskra", 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(POST_METHOD); File file = new File(FILE_NAME); filePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { StringPart userPart = new StringPart("cguser", bfm.getUsername()); StringPart pwdPart = new StringPart("password", bfm.getPassword()); StringPart clubssnPart = new StringPart("cgclaimBatchName", batchName); FilePart filePart = new FilePart("cgskra", 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:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies/* w ww. j a v a 2s. c om*/ * the previous request response existing cookies to keep the * session information. * @throws MojoExecutionException * in case of any errors during this process. */ @SuppressWarnings("deprecation") private void installPackage(final Cookie[] cookies) throws MojoExecutionException { File file = new File(jarfile); String url = crxPath + "/packmgr/unpack.jsp?Path=" + getPackagePath(file) + (aclIgnore ? "" : "&acHandling=overwrite"); GetMethod loginPost = new GetMethod(url); loginPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("installing: " + url); 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 it's ok, proceed if (status == HttpStatus.SC_OK) { InputStream response = loginPost.getResponseBodyAsStream(); if (response != null) { String responseBody = IOUtils.toString(response); if (responseBody.contains("Package installed in")) { getLog().info("Install successful"); } else { logResponseDetails(loginPost); throw new MojoExecutionException("Error installing package on crx"); } } else { throw new MojoExecutionException("Null response when installing package on crx"); } } else { logResponseDetails(loginPost); throw new MojoExecutionException("Installation failed"); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { loginPost.releaseConnection(); } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies/*from ww w.j a v a2 s. co m*/ * the previous request response existing cookies to keep the * session information. * @param path * the node path to delete. * @throws MojoExecutionException * in case of any errors during this process. */ @SuppressWarnings("deprecation") private void deleteNode(final Cookie[] cookies, final String pathInput) throws MojoExecutionException { String[] pathes = pathInput.split(","); for (String path : pathes) { GetMethod removeCall = new GetMethod( crxPath + "/browser/delete_recursive.jsp?Path=" + path + "&action=delete"); removeCall.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("removing " + path); getLog().info(crxPath + "/browser/delete_recursive.jsp?Path=" + path + "&action=delete"); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); removeCall.setFollowRedirects(false); if (isVersionable(cookies, path, client)) { getLog().info("Node at : " + path + " is mix:versionable."); checkout(cookies, path, client); } else { getLog().info("removing " + path); getLog().info(crxPath + "/browser/delete_recursive.jsp?Path=" + path + "&action=delete"); int status = client.executeMethod(removeCall); if (status == HttpStatus.SC_OK) { getLog().info("Node deleted"); // log the status getLog().info("Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); } else { logResponseDetails(removeCall); throw new MojoExecutionException( "Removing node " + path + " failed, response=" + HttpStatus.getStatusText(status)); } getLog().info("Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { removeCall.releaseConnection(); } } }
From source file:my.swingconnect.SwingConnectUI.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed {// w w w.j a va2 s . c o m int i = 0; while (i < results.size()) { String path = results.get(i); System.out.println("Printing path" + path); targetFile1 = new File(path); // String targetURL = jTextField3.getSelectedItem().toString(); // String targetURL = jTextField3.getSelectedText(); String targetURL = "http://photo-drop.com/uploader.php"; // if (!targetURL // // .equals( // // cmbURLModel.getElementAt( // // cmbURL.getSelectedIndex()))) { // // cmbURLModel.addElement(targetURL); // // } System.out.println(targetURL); //From the apache package: the class that implements POST method PostMethod filePost = new PostMethod(targetURL); filePost.getParams().setBooleanParameter( HttpMethodParams.USE_EXPECT_CONTINUE, jCheckBox1.isSelected()); try { System.out.println("Uploading " + targetFile1.getName() + " to " + targetURL); jTextArea2.append("Uploading " + targetFile1.getName() + " to " + targetURL); filename = targetFile1.toString(); System.out.println(filename); javapostmethod f = new javapostmethod(); f.sendPost(filename); Part[] parts = { new FilePart(targetFile1.getName(), targetFile1) }; 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) { jTextArea2.append("Upload complete, response=" + filePost.getResponseBodyAsString()); jTextArea2.append("Uploaded from:" + filename); } else { jTextArea2.append("Upload failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { jTextArea2.append("Error: " + ex.getMessage()); ex.printStackTrace(); } finally { filePost.releaseConnection(); } i++; } // } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
/** * @param cookies// w ww . j av a 2 s . co m * the previous request response existing cookies to keep the * session information. * @throws MojoExecutionException * in case of any errors during this process. */ @SuppressWarnings("deprecation") private void saveAll(final Cookie[] cookies) throws MojoExecutionException { GetMethod savePost = new GetMethod(crxPath + "/browser/content.jsp?Path=/&action_ops=saveAll"); savePost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("save all changes"); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(savePost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); if (status == HttpStatus.SC_OK) { getLog().info("All changes saved"); } else { logResponseDetails(savePost); throw new MojoExecutionException( "save all changes failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { savePost.releaseConnection(); } }
From source file:com.apatar.ui.Actions.java
private void publishToApatar() throws HttpException, IOException { JPublishToApatarDialog dlg = new JPublishToApatarDialog(ApatarUiMain.MAIN_FRAME); dlg.setVisible(true);/*from w w w .j av a 2s . co m*/ if (dlg.getOption() == JPublishToApatarDialog.CANCEL_OPTION) { return; } PostMethod method = new PostMethod(PUBLISH_TO_APATAR_URL); File file; if (dlg.isSelectFromFile()) { file = new File(dlg.getFilePath()); } else { String tempFolderName = "tempdatamap/"; File tempFolder = new File(tempFolderName); if (!tempFolder.exists()) { tempFolder.mkdir(); } String fileName = "tempdatamap/" + dlg.getDataMapName().replaceAll("[|/\\:*?\"<> ]", "_") + ".aptr"; ReadWriteXMLDataUi rwXMLdata = new ReadWriteXMLDataUi(); file = rwXMLdata.writeXMLData(fileName.toString(), ApplicationData.getProject(), true); } Part[] parts = new Part[14]; parts[0] = new StringPart("option", "com_remository"); parts[1] = new StringPart("task", ""); parts[1] = new StringPart("func", "savefile"); parts[2] = new StringPart("element", "component"); parts[3] = new StringPart("client", ""); parts[4] = new StringPart("oldid", "0"); parts[5] = new FilePart("userfile", file); parts[6] = new StringPart("containerid", "" + dlg.getDataMapLocation().getId()); parts[7] = new StringPart("filetitle", dlg.getDataMapName()); parts[8] = new StringPart("description", dlg.getDataMapDescription()); parts[9] = new StringPart("smalldesc", dlg.getShortDescription()); parts[10] = new StringPart("filetags", dlg.getTags()); parts[11] = new StringPart("pubExternal", "true"); parts[12] = new StringPart("username", dlg.getUserName()); parts[13] = new StringPart("password", CoreUtils.getMD5(dlg.getPassword())); method.setRequestEntity(new MultipartRequestEntity(parts, method.getParams())); HttpClient client = new HttpClient(); client.getHttpConnectionManager().getParams().setConnectionTimeout(10000); int status = client.executeMethod(method); if (status != HttpStatus.SC_OK) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "Upload failed, response=" + HttpStatus.getStatusText(status)); } else { StringBuffer buff = new StringBuffer(method.getResponseBodyAsString()); try { Matcher matcher = ApatarRegExp.getMatcher("<meta name=\"apatarResponse\" content=\"[a-zA-Z_0-9]+\"", buff.toString()); boolean patternFound = false; while (matcher.find()) { patternFound = true; String result = matcher.group(); result = result.replaceFirst("<meta name=\"apatarResponse\" content=\"", ""); result = result.replace("\"", ""); if (result.equalsIgnoreCase("done")) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "File has been published"); } else if (result.equalsIgnoreCase("error_xml")) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "File is not valid"); } else if (result.equalsIgnoreCase("error_login")) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "Name or Password is not valid"); } } if (!patternFound) { JOptionPane.showMessageDialog(ApatarUiMain.MAIN_FRAME, "Wrong response from server. Please check your connection."); } } catch (ApatarException e) { e.printStackTrace(); } } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
private boolean isVersionable(final Cookie[] cookies, String path, HttpClient client) throws HttpException, IOException, MojoExecutionException { GetMethod definitionCall = new GetMethod(crxPath + "/browser/definition.jsp?Path=" + path); definitionCall.setFollowRedirects(false); getLog().info("Getting definitions for node : " + path); getLog().info(crxPath + "/browser/definition.jsp?Path=" + path); int status = client.executeMethod(definitionCall); if (status == HttpStatus.SC_OK) { getLog().info("Successfully retrieved node definition."); } else {/*from w w w. j av a 2s . c o m*/ logResponseDetails(definitionCall); throw new MojoExecutionException("Getting definitions for node " + path + " failed, response=" + HttpStatus.getStatusText(status)); } String response = definitionCall.getResponseBodyAsString().toLowerCase(); return StringUtils.contains(response, "mix:versionable"); }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
private void checkout(final Cookie[] cookies, String path, HttpClient client) throws HttpException, IOException, MojoExecutionException { getLog().info("Checking out " + path); getLog().info(crxPath + "/browser/content.jsp?Path=" + path + "&action_ops=checkout"); PostMethod checkoutCall = new PostMethod(crxPath + "/browser/content.jsp"); checkoutCall.setFollowRedirects(false); checkoutCall.addParameter("Path", path); checkoutCall.addParameter("action_ops", "checkout"); int status = client.executeMethod(checkoutCall); if (status == HttpStatus.SC_OK) { getLog().info("Successfully checked out.\r\n"); } else {// w w w .j a v a 2 s . c o m logResponseDetails(checkoutCall); throw new MojoExecutionException( "Removing node " + path + " failed, response=" + HttpStatus.getStatusText(status)); } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
private void checkin(final Cookie[] cookies, String path, HttpClient client) throws HttpException, IOException, MojoExecutionException { getLog().info("Checking in " + path); getLog().info(crxPath + "/browser/content.jsp?Path=" + path + "&action_ops=checkin"); PostMethod checkinCall = new PostMethod(crxPath + "/browser/content.jsp"); checkinCall.setFollowRedirects(false); checkinCall.addParameter("Path", path); checkinCall.addParameter("action_ops", "checkin"); int status = client.executeMethod(checkinCall); if (status == HttpStatus.SC_OK) { getLog().info("Successfully checked in.\r\n"); } else {//from www .ja v a 2 s . c o m logResponseDetails(checkinCall); throw new MojoExecutionException( "Removing node " + path + " failed, response=" + HttpStatus.getStatusText(status)); } }
From source file:com.tacitknowledge.maven.plugin.crx.CRXPackageInstallerPlugin.java
@SuppressWarnings("deprecation") private void backUp(final Cookie[] cookies) throws MojoExecutionException { checkBackupFolder();// w w w. j a va 2 s . c o m File file = new File(jarfile); GetMethod backupPost = new GetMethod(crxPath + "/packmgr/service.jsp?cmd=get&_charset_=utf8&name=" + FilenameUtils.getBaseName(file.getName())); backupPost.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true); try { getLog().info("backing up /etc/packages/" + file.getName()); HttpClient client = new HttpClient(); client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY); client.getState().addCookies(cookies); client.getHttpConnectionManager().getParams().setConnectionTimeout(CONNECTION_DEFAULT_TIMEOUT); int status = client.executeMethod(backupPost); // log the status getLog().info( "Response status: " + status + ", statusText: " + HttpStatus.getStatusText(status) + "\r\n"); String backUpFileName = formatbackUpFileName(file); File backupFile = new File(backUpFileName); if (status == HttpStatus.SC_OK) { copyStreamToFile(backupPost.getResponseBodyAsStream(), backupFile); getLog().info("Back-up succesfull. The backup is " + backupFile.getAbsolutePath()); } else { logResponseDetails(backupPost); throw new MojoExecutionException("Back-up failed, response=" + HttpStatus.getStatusText(status)); } } catch (Exception ex) { getLog().error("ERROR: " + ex.getClass().getName() + " " + ex.getMessage()); throw new MojoExecutionException(ex.getMessage()); } finally { backupPost.releaseConnection(); } }