List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:domderrien.wrapper.UrlFetch.UrlFetchHttpConnection.java
@Override public String readLine(String charset) throws IOException, IllegalStateException { if (waitForHttpStatus) { // Dom Derrien: called only once to get the HTTP status, other information being read from the response output stream int responseCode = getResponse().getResponseCode(); String line = "HTTP/1.1 " + responseCode; switch (responseCode) { case HttpStatus.SC_OK: line += " OK"; break; case HttpStatus.SC_BAD_REQUEST: line += " BAD REQUEST"; break; case HttpStatus.SC_UNAUTHORIZED: line += " UNAUTHORIZED"; break; case HttpStatus.SC_FORBIDDEN: line += " FORBIDDEN"; break; case HttpStatus.SC_NOT_FOUND: line += " NOT FOUND"; break; case HttpStatus.SC_INTERNAL_SERVER_ERROR: line += " INTERNAL SERVER ERROR"; break; case HttpStatus.SC_SERVICE_UNAVAILABLE: line += " SERVICE UNAVAILABLE"; break; default:// ww w. j a v a2 s.c o m line = "HTTP/1.1 " + HttpStatus.SC_BAD_REQUEST + " BAD REQUEST"; } waitForHttpStatus = false; return line; } throw new RuntimeException("readLine(String)"); }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.webservice.client.impl.ShippedBiospecimenWSQueriesImpl.java
private <T> T handleClientResponse(final ClientResponse clientResponse, final Class<T> responseType) { T response = null;/* w ww . j a va2s . com*/ int responseStatus = clientResponse.getStatus(); StringBuilder errorMessage = null; if (HttpStatus.SC_OK == responseStatus) { response = clientResponse.getEntity(responseType); } else if (HttpStatus.SC_UNPROCESSABLE_ENTITY == responseStatus) { // this actually means the entity was not found which might // be a valid response, so just return null, don't assume it's an error // HttpStatus 400 } else if (HttpStatus.SC_BAD_REQUEST == responseStatus) { errorMessage = new StringBuilder().append("Request returned HTTP response status of '") .append(responseStatus).append(" - ").append(HttpStatus.getStatusText(responseStatus)) .append("'. Check the request and try again."); // HttpStatus 413 } else if (HttpStatus.SC_REQUEST_TOO_LONG == responseStatus) { errorMessage = new StringBuilder().append("Request returned HTTP response status of '") .append(responseStatus).append(" - ").append(HttpStatus.getStatusText(responseStatus)) .append("'. The number of requests to this web service has exceeded the DCC limits.") .append(" You should reduce the number of concurrent instances of the stand-alone validator running or use the -noremote flag."); if (qcContext != null) { qcContext.addError(errorMessage.toString()); } throw new RuntimeException(errorMessage.toString()); } if (errorMessage != null) { handleErrorMessage(errorMessage.toString()); } return response; }
From source file:com.serena.rlc.provider.jira.client.JiraClient.java
private JiraClientException createHttpError(HttpResponse response) { String message;/* w w w.j a v a2s . co m*/ 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.debug(message); if (new Integer(HttpStatus.SC_UNAUTHORIZED).equals(statusLine.getStatusCode())) { return new JiraClientException("Invalid credentials provided."); } else if (new Integer(HttpStatus.SC_NOT_FOUND).equals(statusLine.getStatusCode())) { return new JiraClientException("JIRA: Request URL not found."); } else if (new Integer(HttpStatus.SC_BAD_REQUEST).equals(statusLine.getStatusCode())) { return new JiraClientException("JIRA: Bad request. " + responsePayload); } } catch (IOException e) { return new JiraClientException("JIRA: Can't read response"); } return new JiraClientException(message); }
From source file:com.zimbra.cs.store.triton.TritonBlobStoreManager.java
/** * Run SIS operation against remote server. If a blob already exists for the locator the remote ref count is incremented. * @param hash: The content hash of the blob * @return true if blob already exists, false if not * @throws IOException//from w w w . j a va 2 s.com * @throws ServiceException */ private boolean sisCreate(byte[] hash) throws IOException { String locator = getLocator(hash); HttpClient client = ZimbraHttpConnectionManager.getInternalHttpConnMgr().newHttpClient(); PostMethod post = new PostMethod(blobApiUrl + locator); ZimbraLog.store.info("SIS create URL: %s", post.getURI()); try { post.addRequestHeader(TritonHeaders.HASH_TYPE, hashType.toString()); int statusCode = HttpClientUtil.executeMethod(client, post); if (statusCode == HttpStatus.SC_CREATED) { return true; //exists, ref count incremented } else if (statusCode == HttpStatus.SC_NOT_FOUND) { if (emptyLocator.equals(locator)) { //empty file return true; } else { return false; //does not exist } } else if (statusCode == HttpStatus.SC_BAD_REQUEST) { //does not exist, probably wrong hash algorithm ZimbraLog.store.warn("failed with code %d response: %s", statusCode, post.getResponseBodyAsString()); return false; } else { //unexpected condition ZimbraLog.store.error("failed with code %d response: %s", statusCode, post.getResponseBodyAsString()); throw new IOException("unable to SIS create " + statusCode + ":" + post.getStatusText(), null); } } finally { post.releaseConnection(); } }
From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java
private String checkResponse(final HttpMethodBase m, final String errorMessageBase) throws BigSwitchBcfApiException, IllegalArgumentException { String customErrorMsg = null; if (m.getStatusCode() == HttpStatus.SC_OK) { String hash = ""; if (m.getResponseHeader(HASH_MATCH) != null) { hash = m.getResponseHeader(HASH_MATCH).getValue(); set_hash(hash);//from w w w . j a va2 s .co m } return hash; } if (m.getStatusCode() == HttpStatus.SC_CONFLICT) { if (m instanceof GetMethod) { return HASH_CONFLICT; } throw new BigSwitchBcfApiException("BCF topology sync required", true); } if (m.getStatusCode() == HttpStatus.SC_SEE_OTHER) { isMaster = false; set_hash(HASH_IGNORE); return HASH_IGNORE; } if (m.getStatusCode() == HttpStatus.SC_NOT_FOUND) { if (m instanceof DeleteMethod) { return ""; } } if (m.getStatusCode() == HttpStatus.SC_BAD_REQUEST) { customErrorMsg = " Invalid data in BCF request"; throw new IllegalArgumentException(customErrorMsg); } String errorMessage = responseToErrorMessage(m); m.releaseConnection(); S_LOGGER.error(errorMessageBase + errorMessage); throw new BigSwitchBcfApiException(errorMessageBase + errorMessage + customErrorMsg); }
From source file:com.serena.rlc.provider.jenkins.client.JenkinsClient.java
private JenkinsClientException createHttpError(HttpResponse response) { String message;/* w w w. j a v a2 s.c o m*/ 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:$.ManagerService.java
/** * This will give link to generated agent *//from w w w. ja v a 2 s .co m * @param deviceName name of the device which is to be created * @param sketchType name of sketch type * @return link to generated agent */ @Path("manager/device/{sketch_type}/generate_link") @GET public Response generateSketchLink(@QueryParam("deviceName") String deviceName, @PathParam("sketch_type") String sketchType) { try { ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName, sketchType); ResponsePayload responsePayload = new ResponsePayload(); responsePayload.setStatusCode(HttpStatus.SC_OK); responsePayload.setMessageFromServer( "Sending Requested sketch by type: " + sketchType + " and id: " + zipFile.getDeviceId() + "."); responsePayload.setResponseContent(zipFile.getDeviceId()); return Response.status(HttpStatus.SC_OK).entity(responsePayload).build(); } catch (IllegalArgumentException ex) { return Response.status(HttpStatus.SC_BAD_REQUEST).entity(ex.getMessage()).build(); } catch (DeviceManagementException ex) { log.error("Error occurred while creating device with name " + deviceName + "\n", ex); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } catch (AccessTokenException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } catch (DeviceControllerException ex) { log.error(ex.getMessage(), ex); return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build(); } }
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());// w ww. j a v a2 s .c o 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:edu.umd.cs.buildServer.BuildServerDaemon.java
@Override protected ProjectSubmission<?> getProjectSubmission() throws MissingConfigurationPropertyException, IOException { try {//from w w w. j a v a2 s. c om String url = getRequestSubmissionURL(); MultipartPostMethod method = new MultipartPostMethod(url); String supportedCoursePKList = getBuildServerConfiguration().getSupportedCourses(); String specificProjectNum = getConfig().getOptionalProperty(DEBUG_SPECIFIC_PROJECT); String specificCourse = getConfig().getOptionalProperty(DEBUG_SPECIFIC_COURSE); if (specificCourse != null) supportedCoursePKList = specificCourse; String specificSubmission = getConfig().getOptionalProperty(DEBUG_SPECIFIC_SUBMISSION); String specificTestSetup = getConfig().getOptionalProperty(DEBUG_SPECIFIC_TESTSETUP); if (specificSubmission != null) { method.addParameter("submissionPK", specificSubmission); if (!isQuiet()) System.out.printf("Requesting submissionPK %s%n", specificSubmission); } if (specificTestSetup != null) { method.addParameter("testSetupPK", specificTestSetup); if (!isQuiet()) System.out.printf("Requesting testSetupPK %s%n", specificTestSetup); } if (specificProjectNum != null) { method.addParameter("projectNumber", specificProjectNum); } addCommonParameters(method); BuildServer.printURI(getLog(), method); int responseCode = client.executeMethod(method); if (responseCode != HttpStatus.SC_OK) { if (responseCode == HttpStatus.SC_SERVICE_UNAVAILABLE) { getLog().trace("Server returned 503 (no work)"); } else { String msg = "HTTP server returned non-OK response: " + responseCode + ": " + method.getStatusText(); getLog().error(msg); getLog().error(" for URI: " + method.getURI()); getLog().error("Full error message: " + method.getResponseBodyAsString()); if (responseCode == HttpStatus.SC_BAD_REQUEST) { if (!isQuiet()) { System.err.println(msg); System.out.println(msg); } System.exit(1); } } return null; } getLog().debug("content-type: " + method.getResponseHeader("Content-type")); getLog().debug("content-length: " + method.getResponseHeader("content-length")); // Ensure we have a submission PK. String submissionPK = getRequiredHeaderValue(method, HttpHeaders.HTTP_SUBMISSION_PK_HEADER); if (submissionPK == null) { if (specificSubmission != null) getLog().error("Server did not return submission " + specificSubmission); return null; } // Ensure we have a project PK. String testSetupPK = specificTestSetup != null ? specificTestSetup : getTestSetupPK(method); if (testSetupPK == null) return null; // This is a boolean value specifying whether the project jar file // is NEW, meaning that it needs to be tested against the // canonical project solution. The build server doesn't need // to do anything with this value except pass it back to // the submit server when reporting test outcomes. String isNewTestSetup = getIsNewTestSetup(method); if (isNewTestSetup == null) return null; // Opaque boolean value representing whether this was a // "background retest". // The BuildServer doesn't need to do anything with this except pass it // back to the SubmitServer. String isBackgroundRetest = getRequiredHeaderValue(method, HttpHeaders.HTTP_BACKGROUND_RETEST); if (isBackgroundRetest == null) isBackgroundRetest = "no"; ServletAppender servletAppender = (ServletAppender) getLog().getAppender("servletAppender"); if (isBackgroundRetest.equals("yes")) servletAppender.setThreshold(Level.FATAL); else servletAppender.setThreshold(Level.INFO); String kind = method.getResponseHeader(HttpHeaders.HTTP_KIND_HEADER).getValue(); String logMsg = "Got submission " + submissionPK + ", testSetup " + testSetupPK + ", kind: " + kind; getLog().info(logMsg); ProjectSubmission<?> projectSubmission = new ProjectSubmission<TestProperties>( getBuildServerConfiguration(), getLog(), submissionPK, testSetupPK, isNewTestSetup, isBackgroundRetest, kind); projectSubmission.setMethod(method); getCurrentFile().delete(); writeToCurrentFile(submissionPK + "\n" + testSetupPK + "\n" + kind + "\n" + SystemInfo.getSystemLoad() + "\n" + logMsg); return projectSubmission; } catch (ConnectException e) { getLog().warn("Unable to connect to " + getBuildServerConfiguration().getSubmitServerURL()); return null; } }
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());/* w w w . ja v a2 s . c o m*/ dos.close(); } else { response.setStatus(HttpServletResponse.SC_BAD_REQUEST); response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_BAD_REQUEST)); response.getWriter().close(); } return null; }