List of usage examples for java.net HttpURLConnection HTTP_BAD_REQUEST
int HTTP_BAD_REQUEST
To view the source code for java.net HttpURLConnection HTTP_BAD_REQUEST.
Click Source Link
From source file:rapture.kernel.DocApiImpl.java
@Override public DocumentRepoConfig getDocRepoConfig(CallingContext context, String docRepoUri) { RaptureURI uri = new RaptureURI(docRepoUri, Scheme.DOCUMENT); if (uri.hasDocPath()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoDocPath", docRepoUri)); //$NON-NLS-1$ }/* ww w.j a va2s. c om*/ DocumentRepoConfig documentRepo = DocumentRepoConfigStorage.readByAddress(uri); if ((documentRepo != null) && documentRepo.getDeleted()) return null; return documentRepo; }
From source file:co.cask.cdap.client.rest.RestStreamClientTest.java
@Test public void testBadRequestTruncate() throws IOException { try {/*from www . j av a2s . c o m*/ streamClient.truncate(TestUtils.BAD_REQUEST_STREAM_NAME); Assert.fail("Expected HttpFailureException"); } catch (HttpFailureException e) { Assert.assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, e.getStatusCode()); } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test /**/* ww w . j a v a 2s. c om*/ * Test for a bad scp-like git repository URI. * @throws Exception */ public void testCloneBadUrlBadScpUri() throws Exception { testUriCheck("host.xz/path/to/repo.git", HttpURLConnection.HTTP_BAD_REQUEST); }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Add new tags to a given job./* ww w . ja v a2s. com*/ * * @param id The id of the job to add the tags to. Not * null/empty/blank. * @param tags The tags to add. Not null/empty/blank. * @return The active tags for this job. * @throws GenieException For any error */ @POST @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Add new tags to a job", notes = "Add the supplied tags to the job with the supplied id.", response = String.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job for id does not exist."), @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid id supplied"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public Set<String> addTagsForJob( @ApiParam(value = "Id of the job to add configuration to.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to add.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.jobService.addTagsForJob(id, tags); }
From source file:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java
/** * Post a new quest/*from w w w .j a v a2s . c om*/ * @param appId applicationId * @param contentB content JSON * @return HttpResponse with the returnString */ @POST @Path("/{appId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_CREATED, message = "{\"status\": 3, \"message\": \"Quests upload success ( (questid) )\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": 3, \"message\": \"Failed to upload (questid)\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": 1, \"message\": \"Failed to add the quest. Quest ID already exist!\"}"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "{\"status\": =, \"message\": \"Quest ID cannot be null!\"}"), }) @ApiOperation(value = "createNewQuest", notes = "A method to store a new quest with details") public HttpResponse createNewQuest( @ApiParam(value = "Application ID to store a new quest", required = true) @PathParam("appId") String appId, @ApiParam(value = "Quest detail in JSON", required = true) @ContentParam byte[] contentB) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "POST " + "gamification/quests/" + appId); long randomLong = new Random().nextLong(); //To be able to match // parse given multipart form data JSONObject objResponse = new JSONObject(); UserAgent userAgent = (UserAgent) getContext().getMainAgent(); String name = userAgent.getLoginName(); if (name.equals("anonymous")) { return unauthorizedMessage(); } String questid = null; String questname; String questdescription; String queststatus; String questachievementid; boolean questquestflag = false; String questquestidcompleted = null; boolean questpointflag = false; int questpointvalue = 0; List<Pair<String, Integer>> questactionids = new ArrayList<Pair<String, Integer>>(); boolean questnotifcheck = false; String questnotifmessage = ""; Connection conn = null; try { conn = dbm.getConnection(); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_14, "" + randomLong); String content = new String(contentB); if (content.equals(null)) { objResponse.put("message", "Cannot create quest. Cannot parse json data into string"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } JSONObject obj = (JSONObject) JSONValue.parseWithException(content); try { if (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot create quest. 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 create quest. 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); } questid = stringfromJSON(obj, "questid"); if (questAccess.isQuestIdExist(conn, appId, questid)) { objResponse.put("message", "Cannot create quest. Failed to add the quest. Quest ID already exist! "); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } questname = stringfromJSON(obj, "questname"); queststatus = stringfromJSON(obj, "queststatus"); questachievementid = stringfromJSON(obj, "questachievementid"); questquestflag = boolfromJSON(obj, "questquestflag"); questpointflag = boolfromJSON(obj, "questpointflag"); questpointvalue = intfromJSON(obj, "questpointvalue"); questactionids = listPairfromJSON(obj, "questactionids", "action", "times"); // OK to be null questdescription = (String) obj.get("questdescription"); if (questdescription.equals(null)) { questdescription = ""; } questquestidcompleted = (String) obj.get("questidcompleted"); if (questquestflag) { if (questquestidcompleted.equals(null)) { objResponse.put("message", "Cannot create quest. Completed quest ID cannot be null if it is selected"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } } else { questquestidcompleted = null; } questnotifcheck = boolfromJSON(obj, "questnotificationcheck"); if (questnotifcheck) { questnotifmessage = stringfromJSON(obj, "questnotificationmessage"); } System.out.println(questquestidcompleted); QuestModel model = new QuestModel(questid, questname, questdescription, QuestStatus.valueOf(queststatus), questachievementid, questquestflag, questquestidcompleted, questpointflag, questpointvalue, questnotifcheck, questnotifmessage); model.setActionIds(questactionids); questAccess.addNewQuest(conn, appId, model); objResponse.put("message", "New quest created " + questid); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_15, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_24, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_25, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_CREATED); } catch (MalformedStreamException e) { // the stream failed to follow required syntax objResponse.put("message", "Cannot create quest. MalformedStreamException. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } catch (IOException e) { // a read or write error occurred objResponse.put("message", "Cannot create quest. IO Exception. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. Database error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (NullPointerException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. NullPointerException. Failed to upload " + questid + ". " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (ParseException e) { e.printStackTrace(); objResponse.put("message", "Cannot create quest. ParseException. Failed to parse JSON. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } // always close connections finally { try { conn.close(); } catch (SQLException e) { logger.printStackTrace(e); } } }
From source file:rapture.kernel.SeriesApiImpl.java
/** * Return the {@link SeriesRepo} for this {@link RaptureURI} or throw a {@link RaptureException} with an error message * * @param uri/*from w w w .j ava2 s .com*/ * @return */ private SeriesRepo getRepoOrFail(RaptureURI uri) { SeriesRepo repo = getRepoFromCache(uri.getAuthority()); if (repo == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", uri.toAuthString())); //$NON-NLS-1$ } else { return repo; } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.DefinitionResource.java
private Response getDefinitionInternal(String propertyPath, Output output, String callback, boolean prettyPrint) { try {/* w ww. j a v a 2 s . co m*/ if (StringUtils.isBlank(propertyPath)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } DefinitionService definitionService = astroboaClient.getDefinitionService(); StringBuilder definitionAsXMLOrJSONorXSD = new StringBuilder(); switch (output) { case XML: { String xml = definitionService.getCmsDefinition(propertyPath, ResourceRepresentationType.XML, prettyPrint); if (StringUtils.isBlank(xml)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } if (StringUtils.isBlank(callback)) { definitionAsXMLOrJSONorXSD.append(xml); } else { ContentApiUtils.generateXMLP(definitionAsXMLOrJSONorXSD, xml, callback); } break; } case JSON: String json = definitionService.getCmsDefinition(propertyPath, ResourceRepresentationType.JSON, prettyPrint); if (StringUtils.isBlank(json)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } if (StringUtils.isBlank(callback)) { definitionAsXMLOrJSONorXSD.append(json); } else { ContentApiUtils.generateJSONP(definitionAsXMLOrJSONorXSD, json, callback); } break; case XSD: String xsd = definitionService.getCmsDefinition(propertyPath, ResourceRepresentationType.XSD, prettyPrint); if (StringUtils.isBlank(xsd)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } definitionAsXMLOrJSONorXSD.append(xsd); if (StringUtils.isNotBlank(callback)) { logger.warn("Callback {} is ignored in {} output", callback, output); } break; } return ContentApiUtils.createResponse(definitionAsXMLOrJSONorXSD, output, callback, null); } catch (WebApplicationException e) { throw e; } catch (Exception e) { logger.error("Definition For property path: " + propertyPath, e); throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:rapture.kernel.BlobApiImpl.java
@Override public BlobContainer getBlob(CallingContext context, String blobUri) { BlobContainer retVal = new BlobContainer(); // TODO: Ben - push this up to the wrapper - the this class should // implement the Trusted API. RaptureURI interimUri = new RaptureURI(blobUri, BLOB); if (interimUri.hasAttribute()) { // TODO: Ben - This is messy, and shouldn't really be used, throw an // exception here? ContentEnvelope content = getContent(context, interimUri); try {//from w ww . j ava 2 s .c o m retVal.setContent(content.getContent().toString().getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, apiMessageCatalog.getMessage("ErrorGettingBlob"), e); } return retVal; } else { BlobRepo blobRepo = getRepoFromCache(interimUri.getAuthority()); if (blobRepo == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", interimUri.toAuthString())); //$NON-NLS-1$ } try (InputStream in = blobRepo.getBlob(context, interimUri)) { if (in != null) { retVal.setContent(IOUtils.toByteArray(in)); Map<String, String> metaData = getBlobMetaData(context, blobUri); Map<String, String> headers = new HashMap<>(); headers.put(ContentEnvelope.CONTENT_SIZE, metaData.get(ContentEnvelope.CONTENT_SIZE)); headers.put(ContentEnvelope.CONTENT_TYPE_HEADER, metaData.get(ContentEnvelope.CONTENT_TYPE_HEADER)); retVal.setHeaders(headers); return retVal; } else { return null; } } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, apiMessageCatalog.getMessage("ErrorGettingBlob"), e); } } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test /**// ww w . j a va 2 s . co m * Test for a local file path as the git repository URI. * @throws Exception */ public void testCloneLocalFilePath() throws Exception { testUriCheck("c:/path/to/repo.git", HttpURLConnection.HTTP_BAD_REQUEST); }
From source file:rapture.sheet.file.FileSheetStore.java
@Override public void drop() { if (parentDir != null) { try {//from ww w. j a va 2s .co m FileUtils.deleteDirectory(parentDir); parentDir = null; } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, "Cannot drop sheet store", e); } } }