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:org.apache.hadoop.hdfs.tools.offlineImageViewer.TestOfflineImageViewerForXAttr.java
@Test public void testWebImageViewerForGetXAttrsWithParameters() throws Exception { try (WebImageViewer viewer = new WebImageViewer(NetUtils.createSocketAddr("localhost:0"))) { viewer.initServer(originalFsimage.getAbsolutePath()); int port = viewer.getPort(); URL url = new URL("http://localhost:" + port + "/webhdfs/v1/dir1/?op=GETXATTRS&xattr.name=attr8"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect();/*from w w w. j a v a2s .c om*/ assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, connection.getResponseCode()); url = new URL("http://localhost:" + port + "/webhdfs/v1/dir1/?op=GETXATTRS&xattr.name=user.attr1"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); assertEquals(HttpURLConnection.HTTP_OK, connection.getResponseCode()); String content = IOUtils.toString(connection.getInputStream()); assertEquals(attr1JSon, content); } }
From source file:rapture.kernel.BlobApiImpl.java
public void appendToBlobLower(CallingContext context, String blobUri, byte[] content, String contentType) { RaptureURI interimUri = new RaptureURI(blobUri, BLOB); Preconditions.checkNotNull(interimUri); Map<String, String> newMeta = createMetaData(context); BlobRepo blobRepo = getRepoFromCache(interimUri.getAuthority()); if (blobRepo == null) throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", interimUri.toAuthString())); //$NON-NLS-1$ Map<String, String> meta = getBlobMetaData(ContextFactory.getKernelUser(), blobUri); if (meta.isEmpty()) { if (contentType != null) { meta.put(ContentEnvelope.CONTENT_TYPE_HEADER, contentType); }/*from ww w . j a va 2s. c o m*/ meta.put(ContentEnvelope.CONTENT_SIZE, Integer.toString(content.length)); meta.putAll(newMeta); putBlobMetaData(ContextFactory.getKernelUser(), interimUri.toString(), meta); blobRepo.storeBlob(context, interimUri, true, new ByteArrayInputStream(content)); } else { addBlobContent(ContextFactory.getKernelUser(), blobUri, content); } }
From source file:com.netflix.genie.server.resources.JobResource.java
/** * Get job status for give job id.//from ww w .j a va 2 s . c om * * @param id id for job to look up * @return The status of the job * @throws GenieException For any error */ @GET @Path("/{id}/status") @ApiOperation(value = "Get the status of the job ", notes = "Get the status of job whose id is sent", response = String.class) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Job not found"), @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 ObjectNode getJobStatus( @ApiParam(value = "Id of the job.", required = true) @PathParam("id") final String id) throws GenieException { LOG.info("Called for job id:" + id); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); node.put("status", this.jobService.getJobStatus(id).toString()); return node; }
From source file:rapture.kernel.DocApiImpl.java
@Override public Boolean validateDocRepo(CallingContext context, String docRepoUri) { RaptureURI internalUri = new RaptureURI(docRepoUri, Scheme.DOCUMENT); if (internalUri.hasDocPath()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoDocPath", docRepoUri)); //$NON-NLS-1$ }/*w w w . j ava2s .c o m*/ Repository repository = getRepoFromCache(internalUri.getAuthority()); if (repository == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", internalUri.toAuthString())); //$NON-NLS-1$ } return repository.validate(); }
From source file:rapture.repo.google.IdGenGoogleDatastore.java
public boolean isValid() { Key entityKey = datastore.newKeyFactory().setKind(kind).newKey(VALID); Entity entity = datastore.get(entityKey); if (entity != null) { Set<String> names = entity.getNames(); if ((names != null) && (names.size() == 1)) { Value<?> value = entity.getValue(names.iterator().next()); if (value instanceof BooleanValue) return ((BooleanValue) value).get(); }/* w w w. j a va2s. c o m*/ } throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, googleMsgCatalog.getMessage("isValid")); }
From source file:org.eclipse.orion.server.tests.servlets.git.GitResetTest.java
@Test public void testResetBadType() throws Exception { URI workspaceLocation = createWorkspace(getMethodName()); String projectName = getMethodName(); JSONObject project = createProjectOrLink(workspaceLocation, projectName, gitDir.toString()); JSONObject testTxt = getChild(project, "test.txt"); modifyFile(testTxt, "hello"); JSONObject gitSection = project.optJSONObject(GitConstants.KEY_GIT); assertNotNull(gitSection);//from ww w .j a v a 2 s. co m String gitIndexUri = gitSection.getString(GitConstants.KEY_INDEX); WebRequest request = getPostGitIndexRequest(gitIndexUri, null, null, "BAD"); WebResponse response = webConversation.getResponse(request); assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, response.getResponseCode()); }
From source file:au.org.ala.biocache.web.AssertionController.java
/** * Adds a bulk list of assertions./*from w w w. j a va2 s .c om*/ * * This method expects certain request params to be provided * apiKey * userId * userDisplayName * assertions - a json list of assertion maps to be applied. * * @param request * @param response * @throws Exception */ @RequestMapping(value = "/bulk/assertions/add", method = RequestMethod.POST) public void addBulkAssertions(HttpServletRequest request, HttpServletResponse response) throws Exception { ObjectMapper om = new ObjectMapper(); try { String json = request.getParameter("assertions"); String userId = request.getParameter("userId"); String userDisplayName = request.getParameter("userDisplayName"); String apiKey = request.getParameter("apiKey"); //check to see that the assertions have come from a valid source before adding if (shouldPerformOperation(apiKey, response)) { List<java.util.Map<String, String>> assertions = om.readValue(json, new TypeReference<List<java.util.Map<String, String>>>() { }); logger.debug("The assertions in a list of maps: " + assertions); java.util.HashMap<String, QualityAssertion> qas = new java.util.HashMap<String, QualityAssertion>( assertions.size()); for (java.util.Map<String, String> assertion : assertions) { String code = assertion.get("code"); String comment = assertion.get("comment"); String recordUuid = assertion.get("recordUuid"); QualityAssertion qa = au.org.ala.biocache.model.QualityAssertion.apply(Integer.parseInt(code)); qa.setComment(comment); qa.setUserId(userId); qa.setUserDisplayName(userDisplayName); qas.put(recordUuid, qa); } if (qas.size() > 0) { //add the qas in bulk Store.addUserAssertions(qas); } } } catch (Exception e) { logger.error(e.getMessage(), e); response.sendError(HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:rapture.mongodb.MongoDBFactory.java
private MongoDatabase _getMongoDatabase(String instanceName) { if (mongoDatabases.containsKey(instanceName)) { return mongoDatabases.get(instanceName); } else {/* ww w. j a v a 2 s . c om*/ getMongoForInstance(instanceName); if (mongoDatabases.containsKey(instanceName)) { return mongoDatabases.get(instanceName); } else { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, mongoMsgCatalog.getMessage("NotInitialized")); } } }
From source file:com.scvngr.levelup.core.net.LevelUpResponseTest.java
/** * Tests {@link com.scvngr.levelup.core.net.LevelUpResponse#mapStatus(int, String)}. *///from w w w .j av a2s . co m @SmallTest public void testMapStatusHttp_errorCodeClientError() { assertEquals(LevelUpStatus.ERROR_SERVER, LevelUpResponse.mapStatus(HttpURLConnection.HTTP_BAD_REQUEST, SERVER_LEVELUP_PLATFORM)); }
From source file:org.hyperic.hq.plugin.netservices.HTTPCollector.java
private double getAvail(int code) { // There are too many options to list everything that is // successful. So, instead we are going to call out the // things that should be considered failure, everything else // is OK.//from w w w. j a v a2 s .c o m switch (code) { case HttpURLConnection.HTTP_BAD_REQUEST: case HttpURLConnection.HTTP_FORBIDDEN: case HttpURLConnection.HTTP_NOT_FOUND: case HttpURLConnection.HTTP_BAD_METHOD: case HttpURLConnection.HTTP_CLIENT_TIMEOUT: case HttpURLConnection.HTTP_CONFLICT: case HttpURLConnection.HTTP_PRECON_FAILED: case HttpURLConnection.HTTP_ENTITY_TOO_LARGE: case HttpURLConnection.HTTP_REQ_TOO_LONG: case HttpURLConnection.HTTP_INTERNAL_ERROR: case HttpURLConnection.HTTP_NOT_IMPLEMENTED: case HttpURLConnection.HTTP_UNAVAILABLE: case HttpURLConnection.HTTP_VERSION: case HttpURLConnection.HTTP_BAD_GATEWAY: case HttpURLConnection.HTTP_GATEWAY_TIMEOUT: return Metric.AVAIL_DOWN; default: } if (hasCredentials()) { if (code == HttpURLConnection.HTTP_UNAUTHORIZED) { return Metric.AVAIL_DOWN; } } return Metric.AVAIL_UP; }