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:com.google.wave.api.AbstractRobot.java
/** * Serializes the given outgoing operations into a JSON string, and put it in * the given response object.//from w w w . j a v a 2 s. c o m * * @param operations the operations to be serialized. * @param resp the response object to flush the output string into. */ private static void serializeOperations(List<OperationRequest> operations, HttpServletResponse resp) { try { String json = SERIALIZER.toJson(operations, new TypeToken<List<OperationRequest>>() { }.getType()); LOG.info("Outgoing operations: " + json); resp.setContentType(JSON_MIME_TYPE); resp.setCharacterEncoding(UTF_8); resp.getWriter().write(json); resp.setStatus(HttpURLConnection.HTTP_OK); } catch (IOException iox) { resp.setStatus(HttpURLConnection.HTTP_INTERNAL_ERROR); } }
From source file:i5.las2peer.services.gamificationBadgeService.GamificationBadgeService.java
/** * Fetch a badge image with specified ID * @param appId application id/*from w w w .ja v a2 s . co m*/ * @param badgeId badge id * @return HttpResponse and return the image */ @GET @Path("/{appId}/{badgeId}/img") @Produces(MediaType.APPLICATION_OCTET_STREAM) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Badges Entry"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot found image") }) @ApiOperation(value = "", notes = "list of stored badges") public HttpResponse getBadgeImage(@PathParam("appId") String appId, @PathParam("badgeId") String badgeId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/badges/" + appId + "/" + badgeId + "/img"); JSONObject objResponse = new JSONObject(); Connection conn = null; UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } try { conn = dbm.getConnection(); L2pLogger.logEvent(this, Event.AGENT_GET_STARTED, "Get Badge Image"); L2pLogger.logEvent(this, Event.ARTIFACT_FETCH_STARTED, "Get Badge Image"); try { if (!badgeAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get badge image. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } } catch (SQLException e1) { e1.printStackTrace(); objResponse.put("message", "Cannot get badge image. Cannot check whether application ID exist or not. Database error. " + e1.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } if (!badgeAccess.isBadgeIdExist(conn, appId, badgeId)) { objResponse.put("message", "Cannot get badge image. Badge not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } byte[] filecontent = getBadgeImageMethod(appId, badgeId); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_25, "Badge image fetched : " + badgeId + " : " + appId + " : " + userAgent); L2pLogger.logEvent(this, Event.ARTIFACT_RECEIVED, "Badge image fetched : " + badgeId + " : " + appId + " : " + userAgent); return new HttpResponse(filecontent, HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get badge image. Database error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:eionet.web.action.VocabularyFolderActionBean.java
/** * Imports CSV contents into vocabulary. * * @return resolution/* www . j a va 2 s . c om*/ * @throws ServiceException * when an error occurs */ public Resolution uploadCsv() throws ServiceException { try { vocabularyFolder = vocabularyService.getVocabularyFolder(vocabularyFolder.getFolderName(), vocabularyFolder.getIdentifier(), vocabularyFolder.isWorkingCopy()); validateView(); if (!vocabularyFolder.isWorkingCopy()) { throw new ServiceException("Vocabulary should be in working copy status"); } if (this.uploadedFileToImport == null) { throw new ServiceException("You should upload a file"); } String fileName = this.uploadedFileToImport.getFileName(); if (StringUtils.isEmpty(fileName) || !fileName.toLowerCase().endsWith(VocabularyFolderActionBean.CSV_FILE_EXTENSION)) { throw new ServiceException("File should be a CSV file"); } // consume stupid bom first!! if it exists! InputStream is = this.uploadedFileToImport.getInputStream(); byte[] firstBomBytes = new byte[VocabularyOutputHelper.BOM_BYTE_ARRAY_LENGTH]; int readBytes = is.read(firstBomBytes); if (readBytes != VocabularyOutputHelper.BOM_BYTE_ARRAY_LENGTH) { is.close(); throw new ServiceException("Input stream cannot be read"); } if (!Arrays.equals(firstBomBytes, VocabularyOutputHelper.getBomByteArray())) { is.close(); is = this.uploadedFileToImport.getInputStream(); } Reader csvFileReader = new InputStreamReader(is, CharEncoding.UTF_8); List<String> systemMessages = this.vocabularyCsvImportService.importCsvIntoVocabulary(csvFileReader, vocabularyFolder, purgeVocabularyData, purgeBoundElements); for (String systemMessage : systemMessages) { addSystemMessage(systemMessage); } RedirectResolution resolution = new RedirectResolution(VocabularyFolderActionBean.class, "edit"); resolution.addParameter("vocabularyFolder.folderName", vocabularyFolder.getFolderName()); resolution.addParameter("vocabularyFolder.identifier", vocabularyFolder.getIdentifier()); resolution.addParameter("vocabularyFolder.workingCopy", vocabularyFolder.isWorkingCopy()); // navigate back to edit return resolution; } catch (ServiceException e) { LOGGER.error("Failed to import vocabulary CSV into db", e); e.setErrorParameter(ErrorActionBean.ERROR_TYPE_KEY, ErrorActionBean.ErrorType.INVALID_INPUT); throw e; } catch (Exception e) { LOGGER.error("Failed to import vocabulary CSV into db, unexpected exception: ", e); ErrorResolution error = new ErrorResolution(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setErrorMessage(e.getMessage()); return error; } }
From source file:eionet.web.action.VocabularyFolderActionBean.java
/** * Imports RDF contents into vocabulary. * * @return resolution/*from w w w . j av a 2s .c o m*/ * @throws ServiceException * when an error occurs */ public Resolution uploadRdf() throws ServiceException { try { vocabularyFolder = vocabularyService.getVocabularyFolder(vocabularyFolder.getFolderName(), vocabularyFolder.getIdentifier(), vocabularyFolder.isWorkingCopy()); validateView(); if (!vocabularyFolder.isWorkingCopy()) { throw new ServiceException("Vocabulary should be in working copy status"); } if (this.uploadedFileToImport == null) { throw new ServiceException("You should upload a file"); } String fileName = this.uploadedFileToImport.getFileName(); if (StringUtils.isEmpty(fileName) || !fileName.toLowerCase().endsWith(VocabularyFolderActionBean.RDF_FILE_EXTENSION)) { throw new ServiceException("File should be a RDF file"); } LOGGER.debug("Starting RDF import operation"); Reader rdfFileReader = new InputStreamReader(this.uploadedFileToImport.getInputStream(), CharEncoding.UTF_8); // TODO use enum instead for rdf purge option List<String> systemMessages = this.vocabularyRdfImportService.importRdfIntoVocabulary(rdfFileReader, vocabularyFolder, this.rdfPurgeOption == 3, this.rdfPurgeOption == 2); for (String systemMessage : systemMessages) { addSystemMessage(systemMessage); LOGGER.info(systemMessage); } LOGGER.debug("RDF import completed"); RedirectResolution resolution = new RedirectResolution(VocabularyFolderActionBean.class, "edit"); resolution.addParameter("vocabularyFolder.folderName", vocabularyFolder.getFolderName()); resolution.addParameter("vocabularyFolder.identifier", vocabularyFolder.getIdentifier()); resolution.addParameter("vocabularyFolder.workingCopy", vocabularyFolder.isWorkingCopy()); // navigate back to edit return resolution; } catch (ServiceException e) { LOGGER.error("Failed to import vocabulary RDF into db", e); e.setErrorParameter(ErrorActionBean.ERROR_TYPE_KEY, ErrorActionBean.ErrorType.INVALID_INPUT); throw e; } catch (Exception e) { LOGGER.error("Failed to import vocabulary RDF into db, unexpected exception: ", e); ErrorResolution error = new ErrorResolution(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setErrorMessage(e.getMessage()); return error; } }
From source file:eionet.web.action.VocabularyFolderActionBean.java
/** * Returns vocabulary concepts json.//from w ww . j av a2s . c o m * * @return resolution */ public Resolution json() { try { vocabularyFolder = vocabularyService.getVocabularyFolder(vocabularyFolder.getFolderName(), vocabularyFolder.getIdentifier(), vocabularyFolder.isWorkingCopy()); if (vocabularyFolder.isDraftStatus()) { throw new RuntimeException("Vocabulary is not in released or public draft status."); } if (StringUtils.isBlank(format)) { format = JSON_DEFAULT_OUTPUT_FORMAT; } if (!SUPPORTED_JSON_FORMATS.contains(format)) { throw new RuntimeException("Unsupported JSON output format"); } lang = StringUtils.trimToNull(lang); id = StringUtils.trimToNull(id); label = StringUtils.trimToNull(label); LOGGER.info("JSON CALL RECEIVED FOR: " + vocabularyFolder.getIdentifier() + ", with parameters: lang = " + lang); final List<VocabularyConcept> concepts = vocabularyService.getValidConceptsWithAttributes( vocabularyFolder.getId(), id, label, null, null, VocabularyJSONOutputHelper.DEFAULT_LANGUAGE); StreamingResolution result = new StreamingResolution(format) { @Override public void stream(HttpServletResponse response) throws Exception { VocabularyJSONOutputHelper.writeJSON(response.getOutputStream(), vocabularyFolder, concepts, lang); } }; return result; } catch (Exception e) { LOGGER.error("Failed to output vocabulary as JSON-LD", e); ErrorResolution error = new ErrorResolution(HttpURLConnection.HTTP_INTERNAL_ERROR); error.setErrorMessage(e.getMessage()); return error; } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.ContentObjectResource.java
private Response saveContentObject(ContentObject contentObject, String httpMethod, String requestContent, boolean entityIsNew, boolean updateLastModificationTime) { try {// w w w . j a v a2s. c om contentObject = astroboaClient.getContentService().save(contentObject, false, updateLastModificationTime, null); return ContentApiUtils.createResponseForPutOrPostOfACmsEntity(contentObject, httpMethod, requestContent, entityIsNew); } catch (CmsUnauthorizedAccessException e) { throw new WebApplicationException(HttpURLConnection.HTTP_UNAUTHORIZED); } catch (Exception e) { logger.error("", e); throw new WebApplicationException(e, HttpURLConnection.HTTP_INTERNAL_ERROR); } }