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.AdminApiImpl.java
@Override public void resetUserPassword(CallingContext context, String userName, String newHashPassword) { checkParameter("User", userName); //$NON-NLS-1$ checkParameter("Password", newHashPassword); //$NON-NLS-1$ // Set a new password for this user RaptureUser usr = getUser(context, userName); if (usr != null) { usr.setInactive(false);//ww w . j a v a2 s . c om usr.setHashPassword(newHashPassword); RaptureUserStorage.add(usr, context.getUser(), adminMessageCatalog.getMessage("PasswordChange", userName).toString()); //$NON-NLS-1$ } else { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, adminMessageCatalog.getMessage("NoExistUser", userName)); //$NON-NLS-1$ } }
From source file:org.eclipse.orion.server.tests.servlets.git.GitCloneTest.java
@Test public void testCloneMissingUserInfo() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String workspaceId = workspaceIdFromLocation(workspaceLocation); JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null); IPath clonePath = getClonePath(workspaceId, project); // see bug 369282 WebRequest request = new PostGitCloneRequest() .setURIish("ssh://git.eclipse.org/gitroot/platform/eclipse.platform.news.git") .setFilePath(clonePath).getWebRequest(); setAuthentication(request);//w w w . j a v a 2 s .c o m WebResponse response = webConversation.getResponse(request); ServerStatus status = waitForTask(response); assertFalse(status.toString(), status.isOK()); assertEquals(status.toString(), HttpURLConnection.HTTP_BAD_REQUEST, status.getHttpCode()); assertEquals("ssh://git.eclipse.org/gitroot/platform/eclipse.platform.news.git: username must not be null.", status.getMessage()); assertNotNull(status.getJsonData()); assertTrue(status.getJsonData().toString(), status.getException().getMessage().contains("username must not be null")); }
From source file:i5.las2peer.services.gamificationApplicationService.GamificationApplicationService.java
/** * Get an app data with specified ID//from w ww. j av a 2s. c o m * @param appId applicationId * @return Application data in JSON */ @GET @Path("/data/{appId}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation(value = "getApplicationDetails", notes = "Get an application data with specific ID") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Return application data with specific ID"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Method not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "App not found"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Cannot connect to database"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Database Error"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Failed to process JSON") }) public HttpResponse getApplicationDetails( @ApiParam(value = "Application ID", required = true) @PathParam("appId") String appId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/applications/data/" + appId); 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(); if (!applicationAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get Application detail. App not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } // Add Member to App ApplicationModel app = applicationAccess.getApplicationWithId(conn, appId); ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String appString = objectMapper.writeValueAsString(app); return new HttpResponse(appString, HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get Application detail. Database Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (JsonProcessingException e) { e.printStackTrace(); objResponse.put("message", "Cannot get Application detail. Failed to process 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.AdminApiImpl.java
@Override public String createPasswordResetToken(CallingContext context, String userName) { checkParameter("User", userName); RaptureUser user = getUser(context, userName); if (user == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, adminMessageCatalog.getMessage("NoExistUser", userName)); //$NON-NLS-1$ }/*from www . ja v a 2s . com*/ String token = generateSecureToken(); user.setPasswordResetToken(token); user.setTokenExpirationTime(DateTime.now().plusDays(1).getMillis()); RaptureUserStorage.add(user, context.getUser(), adminMessageCatalog.getMessage("GenReset", userName).toString()); //$NON-NLS-1$ return token; }
From source file:com.googlecode.batchfb.impl.Batch.java
/** * Constructs the batch query and executes it, possibly asynchronously. * @return an asynchronous handle to the raw batch result, whatever it may be. */// ww w .ja v a 2 s .co m private Later<JsonNode> createFetcher() { final RequestBuilder call = new GraphRequestBuilder(getGraphEndpoint(), HttpMethod.POST, this.timeout, this.retries); // This actually creates the correct JSON structure as an array String batchValue = JSONUtils.toJSON(this.graphRequests, this.mapper); if (log.isLoggable(Level.FINEST)) log.finest("Batch request is: " + batchValue); this.addParams(call, new Param[] { new Param("batch", batchValue) }); final HttpResponse response; try { response = call.execute(); } catch (IOException ex) { throw new IOFacebookException(ex); } return new Later<JsonNode>() { @Override public JsonNode get() throws FacebookException { try { if (response.getResponseCode() == HttpURLConnection.HTTP_OK || response.getResponseCode() == HttpURLConnection.HTTP_BAD_REQUEST || response.getResponseCode() == HttpURLConnection.HTTP_UNAUTHORIZED) { // If it was an error, we will recognize it in the content later. // It's possible we should capture all 4XX codes here. JsonNode result = mapper.readTree(response.getContentStream()); if (log.isLoggable(Level.FINEST)) log.finest("Response is: " + result); return result; } else { throw new IOFacebookException("Unrecognized error " + response.getResponseCode() + " from " + call + " :: " + StringUtils.read(response.getContentStream())); } } catch (IOException e) { throw new IOFacebookException("Error calling " + call, e); } } }; }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java
@PUT @Path("/{taxonomyIdOrName: " + CmsConstants.UUID_OR_SYSTEM_NAME_REG_EXP_FOR_RESTEASY + "}") public Response putTaxonomyByIdOrName(@PathParam("taxonomyIdOrName") String taxonomyIdOrName, String requestContent) {/*from www. j a va 2 s. co m*/ if (StringUtils.isBlank(taxonomyIdOrName)) { logger.warn("Use HTTP PUT to save taxonomy {} but no id or name was provided ", requestContent); throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST); } return saveTaxonomyByIdOrName(taxonomyIdOrName, requestContent, HttpMethod.PUT); }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Update the tags for a given job./* w ww .j a v a2s. co m*/ * * @param id The id of the job to update the tags for. * Not null/empty/blank. * @param tags The tags to replace existing configuration * files with. Not null/empty/blank. * @return The new set of job tags. * @throws GenieException For any error */ @PUT @Path("/{id}/tags") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation(value = "Update tags for a job", notes = "Replace the existing tags for job with given 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> updateTagsForJob( @ApiParam(value = "Id of the job to update tags for.", required = true) @PathParam("id") final String id, @ApiParam(value = "The tags to replace existing with.", required = true) final Set<String> tags) throws GenieException { LOG.info("Called with id " + id + " and tags " + tags); return this.jobService.updateTagsForJob(id, tags); }
From source file:rapture.kernel.BlobApiImpl.java
@Override @SuppressWarnings("unchecked") public Map<String, String> getBlobMetaData(CallingContext context, String blobMetaUri) { RaptureURI interimUri = new RaptureURI(blobMetaUri, BLOB); BlobRepo repo = getRepoFromCache(interimUri.getAuthority()); if (repo == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", interimUri.toAuthString())); //$NON-NLS-1$ }/*from ww w. jav a 2 s . com*/ String attributesString = repo.getMeta(interimUri.getDocPath()); if (attributesString != null) { return JacksonUtil.objectFromJson(attributesString, HashMap.class); } else { return new HashMap<String, String>(); } }
From source file:rapture.kernel.AdminApiImpl.java
@Override public String createRegistrationToken(CallingContext context, String userName) { checkParameter("User", userName); RaptureUser user = getUser(context, userName); if (user == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, adminMessageCatalog.getMessage("NoExistUser", userName)); //$NON-NLS-1$ }/*w ww. j a v a 2 s.c o m*/ String token = generateSecureToken(); user.setRegistrationToken(token); user.setVerified(false); // Registration Token doesn't RaptureUserStorage.add(user, context.getUser(), adminMessageCatalog.getMessage("GenReg", userName).toString()); //$NON-NLS-1$ return token; }
From source file:rapture.kernel.SeriesApiImpl.java
@Override public void addDoublesToSeries(CallingContext context, String seriesURI, List<String> pointKeys, List<Double> pointValues) { checkParameter("URI", seriesURI); checkParameter("pointKeys", pointKeys); checkParameter("pointValues", pointValues); if (pointKeys.size() != pointValues.size()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("ArgSizeNotEqual")); //$NON-NLS-1$ }/*from ww w . j a v a 2 s . c o m*/ for (Double v : pointValues) { if (v == null) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NullEmpty", "pointValue")); //$NON-NLS-1$ } RaptureURI internalURI = new RaptureURI(seriesURI, Scheme.SERIES); getRepoOrFail(internalURI).addDoublesToSeries(internalURI.getDocPath(), pointKeys, pointValues); processSearchUpdate(context, internalURI, pointKeys, pointValues); }