List of usage examples for org.apache.commons.httpclient HttpStatus SC_SERVICE_UNAVAILABLE
int SC_SERVICE_UNAVAILABLE
To view the source code for org.apache.commons.httpclient HttpStatus SC_SERVICE_UNAVAILABLE.
Click Source Link
From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java
private void checkServerStatus(int code) throws IOException { switch (code) { case HttpStatus.SC_SERVICE_UNAVAILABLE: throw new IOException("Web services aren't activated on your project..."); case HttpStatus.SC_UNAUTHORIZED: throw new IOException("Wrong login/pass..."); case HttpStatus.SC_FORBIDDEN: throw new IOException("You haven't access to this project..."); case HttpStatus.SC_NOT_FOUND: throw new IOException("No project or iceScrum server found..."); default://from w w w . ja va 2 s . com throw new IOException("Server error (" + HttpStatus.getStatusText(code) + ")"); } }
From source file:ke.go.moh.oec.adt.Daemon.java
private static boolean sendMessage(String url, String filename) { int returnStatus = HttpStatus.SC_CREATED; HttpClient httpclient = new HttpClient(); HttpConnectionManager connectionManager = httpclient.getHttpConnectionManager(); connectionManager.getParams().setSoTimeout(120000); PostMethod httpPost = new PostMethod(url); RequestEntity requestEntity;/*from w w w . j a v a2 s . c om*/ try { FileInputStream message = new FileInputStream(filename); Base64InputStream message64 = new Base64InputStream(message, true, -1, null); requestEntity = new InputStreamRequestEntity(message64, "application/octet-stream"); } catch (FileNotFoundException e) { Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "File not found.", e); return false; } httpPost.setRequestEntity(requestEntity); try { httpclient.executeMethod(httpPost); returnStatus = httpPost.getStatusCode(); } catch (SocketTimeoutException e) { returnStatus = HttpStatus.SC_REQUEST_TIMEOUT; Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Request timed out. Not retrying.", e); } catch (HttpException e) { returnStatus = HttpStatus.SC_INTERNAL_SERVER_ERROR; Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "HTTP exception. Not retrying.", e); } catch (ConnectException e) { returnStatus = HttpStatus.SC_SERVICE_UNAVAILABLE; Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Service unavailable. Not retrying.", e); } catch (UnknownHostException e) { returnStatus = HttpStatus.SC_NOT_FOUND; Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "Not found. Not retrying.", e); } catch (IOException e) { returnStatus = HttpStatus.SC_GATEWAY_TIMEOUT; Logger.getLogger(Daemon.class.getName()).log(Level.SEVERE, "IO exception. Not retrying.", e); } finally { httpPost.releaseConnection(); } return returnStatus == HttpStatus.SC_OK; }
From source file:com.kagilum.plugins.icescrum.IceScrumSession.java
private void checkServerStatus(int code) throws IOException { switch (code) { case HttpStatus.SC_SERVICE_UNAVAILABLE: throw new IOException(Messages.IceScrumSession_icescrum_http_unavailable()); case HttpStatus.SC_UNAUTHORIZED: throw new IOException(Messages.IceScrumSession_icescrum_http_unauthorized()); case HttpStatus.SC_FORBIDDEN: throw new IOException(Messages.IceScrumSession_icescrum_http_forbidden()); case HttpStatus.SC_NOT_FOUND: throw new IOException(Messages.IceScrumSession_icescrum_http_notfound()); default://from w ww .ja v a2 s . c om throw new IOException( Messages.IceScrumSession_icescrum_http_error() + " (" + HttpStatus.getStatusText(code) + ")"); } }
From source file:it.geosolutions.httpproxy.service.impl.ProxyServiceImpl.java
/** * Performs an HTTP request. Read <code>httpServletRequest</code> method. Default method is HTTP GET. * /*from w ww. j ava 2 s. co m*/ * @param httpServletRequest The {@link HttpServletRequest} object passed in by the servlet engine representing the client request to be proxied * @param httpServletResponse The {@link HttpServletResponse} object by which we can send a proxied response to the client */ public void execute(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException, ServletException { try { this.doMethod(httpServletRequest, httpServletResponse); } catch (HttpErrorException ex) { httpServletResponse.sendError(ex.getCode(), ex.getMessage()); } catch (Exception e) { httpServletResponse.sendError(HttpStatus.SC_SERVICE_UNAVAILABLE, e.getMessage()); } finally { onFinish(); } }
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://from w w w . j ava 2 s . co m line = "HTTP/1.1 " + HttpStatus.SC_BAD_REQUEST + " BAD REQUEST"; } waitForHttpStatus = false; return line; } throw new RuntimeException("readLine(String)"); }
From source file:API.amazon.mws.feeds.actions.SubmitFeedProcess.java
private void processCheckForResult(String feedSubmissionId, String feedProcessingStatus) throws InterruptedException, JAXBException, MarketplaceWebServiceException, NoSuchAlgorithmException, IOException {//from w w w.j a v a 2s .c om boolean keepGoing = true; while (keepGoing) {//infinite loop! try { GetFeedSubmissionListRequest request = new GetFeedSubmissionListRequest(); request.setMerchant(FeedsConfig.SELLER_ID); request.setFeedSubmissionIdList(new IdList(Arrays.asList(new String[] { feedSubmissionId }))); GetFeedSubmissionListResponse response = service.getFeedSubmissionList(request); if (response.getGetFeedSubmissionListResult().getFeedSubmissionInfoList().isEmpty()) throw new IllegalStateException("Infinite While loop avoided - CHECK WHY ISSUE CAUSED!"); for (FeedSubmissionInfo obj : response.getGetFeedSubmissionListResult() .getFeedSubmissionInfoList()) {//Will be size of 1; but just in case loop through all if (obj.getFeedProcessingStatus().equals("_DONE_")) { keepGoing = false; } } if (keepGoing) Thread.sleep(PERIODIC_CHECK); } catch (MarketplaceWebServiceException e) { if (e.getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE && "RequestThrottled".equals(e.getErrorCode())) requestThrottledExceptionHandler(THREAD_LIMIT); } } //End of Infinite loop check if (processReportResults(feedSubmissionId)) throw new IllegalStateException("Bad upload to Amazon!\nPush May have not been Posted."); }
From source file:edu.umd.cs.buildServer.BuildServerDaemon.java
@Override protected ProjectSubmission<?> getProjectSubmission() throws MissingConfigurationPropertyException, IOException { try {/*from w w w . ja v a2s . 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:com.amazonaws.elasticmapreduce.AmazonElasticMapReduceClient.java
/** * Invokes request using parameters from parameters map. * Returns response of the T type passed to this method *///from w w w . ja va 2 s .c o m private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonElasticMapReduceException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; PostMethod method = new PostMethod(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); addRequiredParametersToRequest(method, parameters); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ status = httpClient.executeMethod(method); /* Consume response stream */ responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream()); /* Successful response. Attempting to unmarshal into the <Action>Response type */ if (status == HttpStatus.SC_OK) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if (responseBodyString != null && responseBodyString.trim().endsWith(actionName + "Response>")) { log.debug("Attempting to transform " + actionName + "Response type..."); responseBodyString = ResponseTransformer.transform(responseBodyString); log.debug("Transformed response to: " + responseBodyString); } log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* Unsucessful response. Attempting to unmarshall into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonaws.elasticmapreduce.model.Error error = errorResponse.getError().get(0); throw new AmazonElasticMapReduceException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } catch (JAXBException je) { /* Response cannot be unmarshalled neither as <Action>Response or ErrorResponse types. Checking for other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); AmazonElasticMapReduceException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new AmazonElasticMapReduceException("Internal Error", ioe); } catch (Exception e) { log.debug("Caught Exception", e); throw new AmazonElasticMapReduceException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (AmazonElasticMapReduceException se) { log.debug("Caught AmazonElasticMapReduceException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new AmazonElasticMapReduceException(t); } return response; }
From source file:ac.elements.io.Signature.java
/** * Gets the XML response as a string.//www . ja v a2s . c o m * * @param keyValues * the keyValues pairs * @param id * the id * @param key * the key * * @return the XML response as a string */ public static String getXMLResponse(final Map<String, String> keyValues, String id, String key) { Map<String, String> parameters; try { parameters = Signature.getParameters(keyValues, id, key); } catch (SignatureException se) { se.printStackTrace(); throw new RuntimeException("CredentialsNotFound: Please make sure " + "that the file " + "'aws.properties' is located in the classpath " + "(usually " + "$TOMCAT_HOME/webapps/mysimpledb/WEB-INF/classes" + ") of the java virtual machine. " + "This file should " + "define your AWSAccessKeyId and SecretAccessKey."); } int status = -1; String response = null; PostMethod method = new PostMethod(SERVICE_URL); for (Entry<String, String> entry : parameters.entrySet()) { method.addParameter(entry.getKey(), entry.getValue()); } String en = null; try { /* Set content type and encoding */ method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); boolean shouldRetry = true; int retries = 0; do { // log.debug("Sending Request to host: " + SERVICE_URL); try { /* Submit request */ status = Signature.httpClient.executeMethod(method); /* Consume response stream */ response = getResponsBodyAsString(method.getResponseBodyAsStream()); if (status == HttpStatus.SC_OK) { shouldRetry = false; // log.debug("Received Response. Status: " + status + ". // " + // "Response Body: " + responseBodyString); } else { // log.debug("Received Response. Status: " + status + ". // " + // "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { shouldRetry = false; } } } catch (ConnectException ce) { shouldRetry = false; en = "ConnectException: This webapp is not able to " + "connect, a likely cause is your " + "firewall settings, please double check."; } catch (UnknownHostException uhe) { shouldRetry = false; en = "UnknownHostException: This webapp is not able to " + "connect, to sdb.amazonaws.com " + "please check connection and your " + "firewall settings."; } catch (IOException ioe) { ++retries; log.error("Caught IOException: ", ioe); ioe.printStackTrace(); } catch (Exception e) { ++retries; log.error("Caught Exception: ", e); e.printStackTrace(); } finally { method.releaseConnection(); } // if (shouldRetry && retries == 1) { // concurrentRetries++; // log.warn("concurrentRetries: " + concurrentRetries); // } // if (concurrentRetries >= 1) { // StatementAsync.throttleDown(); // } else { // StatementAsync.throttleUp(); // } } while (shouldRetry); // if (retries > 0 && concurrentRetries > 0) // concurrentRetries--; } catch (Exception e) { log.error("Caught Exception: ", e); e.printStackTrace(); } if (en != null) { throw new RuntimeException(en); } if (response.indexOf("<Code>InvalidClientTokenId</Code>") != -1) { throw new RuntimeException("InvalidClientTokenId: The AWS Access Key Id you provided " + "does not exist in Amazons records. The file " + "aws.properties should define your " + "AWSAccessKeyId and SecretAccessKey."); } else if (response.indexOf("<Code>SignatureDoesNotMatch</Code>") != -1) { throw new RuntimeException("SignatureDoesNotMatch: The request signature we " + "calculated does not match the signature you " + "provided. Check your Secret Access Key " + "and signing method. Consult the service " + "documentation for details."); } else if (response.indexOf("<Code>AuthFailure</Code>") != -1) { throw new RuntimeException("AuthFailure: AWS was not able to validate the provided " + "access credentials. This usually means you do " + "not have a simple db account. " + "Go to <a href=\"" + "http://aws.amazon.com/simpledb/\">Amazon's " + "Simple DB</a> page and create an account, if " + "you do not have one at this moment."); } else if (response.indexOf("<Errors>") != -1) { log.error("Found keyword error in response:\n" + response); log.error("Key value pairs sent:\n" + keyValues); } return response; }
From source file:com.amazonaws.fps.AmazonFPSClient.java
/** * Invokes request using parameters from parameters map. Returns response of * the T type passed to this method/*from ww w . jav a 2s . c o m*/ */ private <T> T invoke(Class<T> clazz, Map<String, String> parameters) throws AmazonFPSException { String actionName = parameters.get("Action"); T response = null; String responseBodyString = null; PostMethod method = new PostMethod(config.getServiceURL()); int status = -1; log.debug("Invoking" + actionName + " request. Current parameters: " + parameters); try { /* Set content type and encoding */ log.debug("Setting content-type to application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=" + DEFAULT_ENCODING.toLowerCase()); /* Add required request parameters and set request body */ log.debug("Adding required parameters..."); addRequiredParametersToRequest(method, parameters); System.out.println(parameters); log.debug("Done adding additional required parameteres. Parameters now: " + parameters); boolean shouldRetry = true; int retries = 0; do { log.debug("Sending Request to host: " + config.getServiceURL()); try { /* Submit request */ status = httpClient.executeMethod(method); /* Consume response stream */ responseBodyString = getResponsBodyAsString(method.getResponseBodyAsStream()); /* * Successful response. Attempting to unmarshal into the * <Action>Response type */ if (status == HttpStatus.SC_OK) { shouldRetry = false; log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); log.debug("Attempting to unmarshal into the " + actionName + "Response type..."); response = clazz.cast(getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString)))); log.debug("Unmarshalled response into " + actionName + "Response type."); } else { /* * Unsucessful response. Attempting to unmarshall * into ErrorResponse type */ log.debug("Received Response. Status: " + status + ". " + "Response Body: " + responseBodyString); if ((status == HttpStatus.SC_INTERNAL_SERVER_ERROR || status == HttpStatus.SC_SERVICE_UNAVAILABLE) && pauseIfRetryNeeded(++retries)) { shouldRetry = true; } else { log.debug("Attempting to unmarshal into the ErrorResponse type..."); ErrorResponse errorResponse = (ErrorResponse) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(responseBodyString))); log.debug("Unmarshalled response into the ErrorResponse type."); com.amazonaws.fps.model.Error error = errorResponse.getError().get(0); throw new AmazonFPSException(error.getMessage(), status, error.getCode(), error.getType(), errorResponse.getRequestId(), errorResponse.toXML()); } } } catch (JAXBException je) { /* * Response cannot be unmarshalled neither as * <Action>Response or ErrorResponse types. Checking for * other possible errors. */ log.debug("Caught JAXBException", je); log.debug("Response cannot be unmarshalled neither as " + actionName + "Response or ErrorResponse types." + "Checking for other possible errors."); AmazonFPSException awse = processErrors(responseBodyString, status); throw awse; } catch (IOException ioe) { log.debug("Caught IOException exception", ioe); throw new AmazonFPSException("Internal Error", ioe); } catch (Exception e) { log.debug("Caught Exception", e); throw new AmazonFPSException(e); } finally { method.releaseConnection(); } } while (shouldRetry); } catch (AmazonFPSException se) { log.debug("Caught AmazonFPSException", se); throw se; } catch (Throwable t) { log.debug("Caught Exception", t); throw new AmazonFPSException(t); } return response; }