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 List<Object> putDocs(CallingContext context, List<String> docUris, List<String> contents) { // For now, implement this as a series of putContentPs - this will be a // bit faster as we are not worrying about the transport costs of this // call./*from www. java2 s . c om*/ if (docUris.size() != contents.size()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("ArgSizeNotEqual")); } List<Object> retList = new ArrayList<Object>(); for (int i = 0; i < docUris.size(); i++) { try { // go back out to wrapper in ordere to verify entitlement // See RAP-3715 retList.add(Kernel.getDoc().putDoc(context, docUris.get(i), contents.get(i))); } catch (RaptureException e) { retList.add(e); } } return retList; }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java
private Response retrieveTaxonomies(String cmsQuery, Integer offset, Integer limit, String orderBy, Output output, String callback, boolean prettyPrint, FetchLevel fetchLevel) { try {/*from w w w .j a va 2 s.c o m*/ if (output == null) { output = Output.XML; } if (fetchLevel == null) { fetchLevel = FetchLevel.ENTITY; } StringBuilder resourceRepresentation = new StringBuilder(); //List<Taxonomy> taxonomies = new ArrayList<Taxonomy>(); if (!StringUtils.isBlank(cmsQuery)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_IMPLEMENTED); } switch (output) { case XML: { String resourceCollectionAsXML = astroboaClient.getTaxonomyService() .getAllTaxonomies(ResourceRepresentationType.XML, fetchLevel, prettyPrint); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(resourceCollectionAsXML); } else { ContentApiUtils.generateXMLP(resourceRepresentation, resourceCollectionAsXML, callback); } break; } case JSON: String resourceCollectionAsJSON = astroboaClient.getTaxonomyService() .getAllTaxonomies(ResourceRepresentationType.JSON, fetchLevel, prettyPrint); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(resourceCollectionAsJSON); } else { ContentApiUtils.generateJSONP(resourceRepresentation, resourceCollectionAsJSON, callback); } break; } return ContentApiUtils.createResponse(resourceRepresentation, output, callback, null); } catch (Exception e) { logger.error("Cms query " + cmsQuery, e); throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST); } }
From source file:org.apache.hadoop.fs.http.server.TestHttpFSServer.java
@Test @TestDir/*from w w w .j a v a 2 s . c om*/ @TestJetty @TestHdfs public void testPutNoOperation() throws Exception { createHttpFSServer(false); String user = HadoopUsersConfTestHelper.getHadoopUsers()[0]; URL url = new URL(TestJettyHelper.getJettyURL(), MessageFormat.format("/webhdfs/v1/foo?user.name={0}", user)); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.setDoOutput(true); conn.setRequestMethod("PUT"); Assert.assertEquals(conn.getResponseCode(), HttpURLConnection.HTTP_BAD_REQUEST); }
From source file:rapture.kernel.DocApiImpl.java
@Override public List<String> renameDocs(CallingContext context, String authority, String comment, List<String> docUris, List<String> toDocUris) { if (docUris.size() != toDocUris.size()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("ArgSizeNotEqual")); }/*from w w w .ja v a 2 s .c o m*/ List<String> ret = new ArrayList<String>(); for (int i = 0; i < docUris.size(); i++) { try { // renameDoc now handles its own entitlements since there are // several in play ret.add(renameDoc(context, docUris.get(i), toDocUris.get(i))); } catch (RaptureException e) { log.error("renameDocs failed when renaming " + docUris.get(i) + " to " + toDocUris.get(i) + " with error: " + e.getMessage()); ret.add(null); } } return ret; }
From source file:org.eclipse.orion.server.tests.servlets.xfer.TransferTest.java
@Test public void testImportFilesWithoutOverride() throws CoreException, IOException, SAXException { //create a directory to upload to String directoryPath = "sample/directory/path" + System.currentTimeMillis(); createDirectory(directoryPath);//from w ww. java 2s. c om //create a file that is not overwritten String fileContents = "This is the file contents"; createFile(directoryPath + "/client.zip", fileContents); //start the import URL entry = ServerTestsActivator.getContext().getBundle().getEntry("testData/importTest/client.zip"); File source = new File(FileLocator.toFileURL(entry).getPath()); long length = source.length(); InputStream in = new BufferedInputStream(new FileInputStream(source)); PostMethodWebRequest request = new PostMethodWebRequest(getImportRequestPath(directoryPath), in, "application/zip"); request.setHeaderField("Content-Length", "" + length); request.setHeaderField("Content-Type", "application/octet-stream"); request.setHeaderField("Slug", "client.zip"); request.setHeaderField("X-Xfer-Options", "raw,no-overwrite"); setAuthentication(request); WebResponse postResponse = webConversation.getResponse(request); //assert the server rejects the override assertEquals(HttpURLConnection.HTTP_BAD_REQUEST, postResponse.getResponseCode()); //assert the file is still present in the workspace assertTrue(checkFileExists(directoryPath + "/client.zip")); //assert that imported file was not overwritten assertTrue(checkContentEquals(createTempFile("expectedFile", fileContents), directoryPath + "/client.zip")); }
From source file:rapture.kernel.DecisionApiImpl.java
@Override public Step getWorkflowStep(CallingContext context, String stepURI) { RaptureURI uri = new RaptureURI(stepURI, Scheme.WORKFLOW); String stepName = uri.getElement(); if (stepName == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, String.format( "The Step URI passed in does not contain an 'element' indicating the step, but it requires one: [%s]", uri.toString()));//from w w w . j av a 2s .c o m } Workflow workflow = getWorkflowNotNull(context, stepURI); return getStep(workflow, stepName); }
From source file:rapture.kernel.DocApiImpl.java
private DocWriteHandle saveDocument(CallingContext context, RaptureURI internalUri, String content, boolean mustBeNew, DocumentRepoConfig type, int expectedCurrentVersion, Map<String, String> extraEventContextMap) { Repository repository = getRepoFromCache(internalUri.getAuthority()); if (repository == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoSuchRepo", internalUri.toAuthString())); //$NON-NLS-1$ }//from ww w .j a v a2 s .c o m if (type.getStrictCheck()) { // Validate that the content is a json document try { JacksonUtil.getMapFromJson(content); } catch (RaptureException e) { log.error("Attempt to save non-json content in a strict type - " + e.getMessage()); throw e; } } DocumentWithMeta newDoc = null; if (expectedCurrentVersion == -1) { newDoc = repository.addDocument(internalUri.getDocPathWithElement(), content, context.getUser(), "", mustBeNew); // note: the repository throws an exception when it fails, so // success can be implied by reaching here } else { newDoc = repository.addDocumentWithVersion(internalUri.getDocPathWithElement(), content, context.getUser(), "", mustBeNew, expectedCurrentVersion); } DocWriteHandle handle = new DocWriteHandle(); if (newDoc != null) { // TODO: Ben - this should be in the wrapper Map<String, String> eventContextMap = new HashMap<>(); eventContextMap.put(DocEventConstants.VERSION, "" + expectedCurrentVersion); if (extraEventContextMap != null) { eventContextMap.putAll(extraEventContextMap); } RunEventHandle eventHandle = Kernel.getEvent().getTrusted().runEventWithContext(context, "//" + internalUri.getAuthority() + "/data/update", internalUri.getDocPath(), eventContextMap); handle.setEventHandle(eventHandle); for (IndexScriptPair indexScriptPair : type.getIndexes()) { runIndex(context, indexScriptPair, internalUri.getAuthority(), internalUri.getDocPath(), content); } newDoc.setDisplayName(internalUri.getFullPath()); SearchPublisher.publishCreateMessage(context, type, new DocUpdateObject(internalUri, newDoc)); } handle.setDocumentURI(internalUri.toString()); handle.setIsSuccess(newDoc != null); return handle; }
From source file:i5.las2peer.services.gamificationActionService.GamificationActionService.java
/** * Delete an action data with specified ID * @param appId applicationId/*w w w . jav a 2 s . co m*/ * @param actionId actionId * @return HttpResponse returned as JSON object */ @DELETE @Path("/{appId}/{actionId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Action is deleted"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Action not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "", notes = "delete an action") public HttpResponse deleteAction(@PathParam("appId") String appId, @PathParam("actionId") String actionId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/actions/" + appId + "/" + actionId); long randomLong = new Random().nextLong(); //To be able to match 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(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!actionAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete action. 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 delete action. 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 (!actionAccess.isActionIdExist(conn, appId, actionId)) { objResponse.put("message", "Cannot delete action. Failed to delete the action. Action ID is not exist!"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } actionAccess.deleteAction(conn, appId, actionId); objResponse.put("message", "Action deleted"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_21, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_31, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot delete action. Database error. " + 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.DecisionApiImpl.java
/** * Trusted method to get the workflow and the selected step as a pair. *//*from w w w . j ava2 s . c o m*/ public Pair<Workflow, Step> getWorkflowWithStep(CallingContext context, String stepURI) { RaptureURI uri = new RaptureURI(stepURI, Scheme.WORKFLOW); String stepName = uri.getElement(); if (stepName == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, String.format( "The Step URI passed in does not contain an 'element' indicating the step, but it requires one: [%s]", uri.toString())); } Workflow workflow = getWorkflowNotNull(context, stepURI); return ImmutablePair.of(workflow, getStep(workflow, stepName)); }
From source file:i5.las2peer.services.gamificationLevelService.GamificationLevelService.java
/** * Delete a level data with specified ID * @param appId applicationId/*from w w w .j a v a 2 s . c om*/ * @param levelNum levelNum * @return HttpResponse with the returnString */ @DELETE @Path("/{appId}/{levelNum}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Level Delete Success"), @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Level not found"), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "Bad Request"), }) @ApiOperation(value = "deleteLevel", notes = "delete a level") public HttpResponse deleteLevel( @ApiParam(value = "Application ID to delete a level", required = true) @PathParam("appId") String appId, @ApiParam(value = "Level number that will be deleted", required = true) @PathParam("levelNum") int levelNum) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "DELETE " + "gamification/levels/" + appId + "/" + levelNum); long randomLong = new Random().nextLong(); //To be able to match 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(Event.SERVICE_CUSTOM_MESSAGE_20, "" + randomLong); try { if (!levelAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot delete level. 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 delete level. 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 (!levelAccess.isLevelNumExist(conn, appId, levelNum)) { objResponse.put("message", "Cannot delete level. Level not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } levelAccess.deleteLevel(conn, appId, levelNum); objResponse.put("message", "Level Deleted"); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_21, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_30, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_31, "" + appId); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot delete level. Cannot delete level. " + 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); } } }