List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR
int HTTP_INTERNAL_ERROR
To view the source code for java.net HttpURLConnection HTTP_INTERNAL_ERROR.
Click Source Link
From source file:org.opencastproject.deliver.itunesu.HTTPHelper.java
/** * Throws exception if status code is not 200. *///from w ww . j a v a 2 s. c om private void checkStatusCode() { int statusCode = 0; String errorMessage = ""; try { statusCode = connection.getResponseCode(); errorMessage = connection.getResponseMessage(); } catch (IOException e) { throw new RuntimeException("Error in HTTP connection!"); } if (statusCode != HttpURLConnection.HTTP_OK) { switch (statusCode) { case HttpURLConnection.HTTP_CLIENT_TIMEOUT: errorMessage = "Request Time-Out"; break; case HttpURLConnection.HTTP_INTERNAL_ERROR: errorMessage = "Internal Server Error"; break; case HttpURLConnection.HTTP_UNAVAILABLE: errorMessage = "Service Unavailable"; break; } throw new RuntimeException(errorMessage); } }
From source file:rapture.table.file.FileIndexHandler.java
private void loadIndexData() { log.info("Loading previously saved index data."); Integer numFileLines = 0;/* www.j ava 2 s . c o m*/ try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(persistenceFile)))) { String line; while ((line = br.readLine()) != null) { IndexEntry entry = JacksonUtil.objectFromJson(line, IndexEntry.class); if (entry.getValue() == null || entry.getValue().isEmpty()) { super.removeAll(entry.getKey()); } else { super.updateRow(entry.getKey(), entry.getValue()); } numFileLines++; } } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error reading index file", e); } if (isTimeToConsolidate(numFileLines)) { log.info("Consolidating index file."); persistFullIndex(); } }
From source file:org.eclipse.hono.client.impl.RegistrationClientImpl.java
@Override protected final RegistrationResult getResult(final int status, final String payload, final CacheDirective cacheDirective) { if (payload == null) { return RegistrationResult.from(status); } else {// w ww. j a v a2s . c om try { return RegistrationResult.from(status, new JsonObject(payload), cacheDirective); } catch (final DecodeException e) { LOG.warn("received malformed payload from Device Registration service", e); return RegistrationResult.from(HttpURLConnection.HTTP_INTERNAL_ERROR); } } }
From source file:com.s3auth.rest.TkApp.java
/** * Authenticated./*ww w . j a v a 2 s . c o m*/ * @param takes Take * @return Authenticated takes */ private static Take fallback(final Take takes) { return new TkFallback(takes, new FbChain(new FbStatus(HttpURLConnection.HTTP_NOT_FOUND, new TkNotFound()), // @checkstyle AnonInnerLengthCheck (50 lines) new Fallback() { @Override public Iterator<Response> route(final RqFallback req) throws IOException { final String err = ExceptionUtils.getStackTrace(req.throwable()); return Collections.<Response>singleton(new RsWithStatus(new RsWithType( new RsVelocity(this.getClass().getResource("exception.html.vm"), new RsVelocity.Pair("err", err), new RsVelocity.Pair("rev", TkApp.REV)), "text/html"), HttpURLConnection.HTTP_INTERNAL_ERROR)).iterator(); } })); }
From source file:rapture.mongodb.MongoDBFactory.java
private Mongo getMongoFromSysConfig(String instanceName) { Map<String, ConnectionInfo> map = Kernel.getSys().getConnectionInfo(ContextFactory.getKernelUser(), ConnectionType.MONGODB.toString()); if (!map.containsKey(instanceName)) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, mongoMsgCatalog.getMessage("NoInstance", instanceName)); }//ww w . ja v a 2 s . c o m ConnectionInfo info = map.get(instanceName); log.info("Connection info = " + info); try { MongoClient mongo = new MongoClient(new MongoClientURI(info.getUrl())); mongoDBs.put(instanceName, mongo.getDB(info.getDbName())); mongoDatabases.put(instanceName, mongo.getDatabase(info.getDbName())); mongoInstances.put(instanceName, mongo); return mongo; } catch (MongoException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, new ExceptionToString(e)); } }
From source file:rapture.blob.file.FileBlobStore.java
private Boolean createSymLink(String fromDisplayName, String toFilePath) { try {/*from w ww .j a va2s. c om*/ File fromFile = FileRepoUtils.makeGenericFile(parentDir, fromDisplayName + Parser.COLON_CHAR); Path fromFilePath = Paths.get(fromFile.getAbsolutePath()); Files.deleteIfExists(fromFilePath); FileUtils.forceMkdir(fromFilePath.getParent().toFile()); Files.createSymbolicLink(fromFilePath, Paths.get(toFilePath + Parser.COLON_CHAR)); } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Fail to read blob content", e); } return true; }
From source file:org.jboss.as.test.integration.web.customerrors.CustomErrorsUnitTestCase.java
/** * Test that the custom 500 error page is seen for an exception * * @throws Exception/*ww w .j av a 2 s .com*/ */ @Test @OperateOnDeployment("error-producer.war") public void testExceptionError(@ArquillianResource(ErrorGeneratorServlet.class) URL baseURL) throws Exception { URL url = new URL(baseURL + "/ErrorGeneratorServlet"); testURL(url, HttpURLConnection.HTTP_INTERNAL_ERROR, "500.jsp", "java.lang.IllegalStateException"); }
From source file:rapture.pipeline2.gcp.PubsubPipeline2Handler.java
public Topic getTopic(String topicId) { if (topicId == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Illegal Argument: topic Id is null"); }/* w w w. ja va 2 s . com*/ String topId = (topicId.toLowerCase().startsWith("rapture")) ? topicId : topicId + "rapture"; Topic topic = topics.get(topId); if (topic == null) { try (TopicAdminClient topicAdminClient = topicAdminClientCreate()) { TopicName topicName = TopicName.create(projectId, topId); try { topic = topicAdminClient.getTopic(topicName); } catch (Exception e) { if (topic == null) { topic = topicAdminClient.createTopic(topicName); topics.put(topId, topic); } } } catch (Exception ioe) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Cannot create or get topic " + topicId, ioe); } } return topic; }
From source file:com.stackmob.example.TwilioSMS2.java
@Override public ResponseToProcess execute(ProcessedAPIRequest request, SDKServiceProvider serviceProvider) { int responseCode = 0; String responseBody = ""; LoggerService logger = serviceProvider.getLoggerService(TwilioSMS.class); // TO phonenumber should be YOUR cel phone String toPhoneNumber = request.getParams().get("tophonenumber"); // FROM phonenumber should be one create in the twilio dashboard at twilio.com String fromPhoneNumber = "18572541790"; // text message you want to send String message = request.getParams().get("message"); if (toPhoneNumber == null || toPhoneNumber.isEmpty()) { logger.error("Missing phone number"); }//w w w .ja va 2 s.c o m if (message == null || message.isEmpty()) { logger.error("Missing message"); } StringBuilder body = new StringBuilder(); body.append("To="); body.append(toPhoneNumber); body.append("&From="); body.append(fromPhoneNumber); body.append("&Body="); body.append(message); String url = "https://api.twilio.com/2010-04-01/Accounts/" + accountsid + "/SMS/Messages.json"; String pair = accountsid + ":" + accesstoken; // Base 64 Encode the accountsid/accesstoken String encodedString = new String("utf-8"); try { byte[] b = Base64.encodeBase64(pair.getBytes("utf-8")); encodedString = new String(b); } catch (Exception e) { logger.error(e.getMessage(), e); HashMap<String, String> errParams = new HashMap<String, String>(); errParams.put("error", "the auth header threw an exception: " + e.getMessage()); return new ResponseToProcess(HttpURLConnection.HTTP_BAD_REQUEST, errParams); // http 400 - bad request } Header accept = new Header("Accept-Charset", "utf-8"); Header auth = new Header("Authorization", "Basic " + encodedString); Header content = new Header("Content-Type", "application/x-www-form-urlencoded"); Set<Header> set = new HashSet(); set.add(accept); set.add(content); set.add(auth); try { HttpService http = serviceProvider.getHttpService(); PostRequest req = new PostRequest(url, set, body.toString()); HttpResponse resp = http.post(req); responseCode = resp.getCode(); responseBody = resp.getBody(); } catch (TimeoutException e) { logger.error(e.getMessage(), e); responseCode = HttpURLConnection.HTTP_BAD_GATEWAY; responseBody = e.getMessage(); } catch (AccessDeniedException e) { logger.error(e.getMessage(), e); responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; responseBody = e.getMessage(); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; responseBody = e.getMessage(); } catch (ServiceNotActivatedException e) { logger.error(e.getMessage(), e); responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR; responseBody = e.getMessage(); } Map<String, Object> map = new HashMap<String, Object>(); map.put("response_body", responseBody); return new ResponseToProcess(responseCode, map); }