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 updateUserEmail(CallingContext context, String userName, String newEmail) { checkParameter("User", userName); //$NON-NLS-1$ RaptureUser user = getUser(context, userName); if (user != null) { user.setEmailAddress(newEmail);//from w w w . ja va 2 s .co m RaptureUserStorage.add(user, context.getUser(), adminMessageCatalog.getMessage("UpdateEmail") + userName); } else { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, adminMessageCatalog.getMessage("NoExistUser", userName)); //$NON-NLS-1$ } }
From source file:org.betaconceptframework.astroboa.resourceapi.resource.TopicResource.java
private Response retrieveTopics(String cmsQuery, Integer offset, Integer limit, String orderBy, Output output, String callback, String prettyPrint) { if (output == null) { output = Output.XML;// ww w . j av a 2s .c o m } boolean prettyPrintEnabled = ContentApiUtils.isPrettyPrintEnabled(prettyPrint); try { //Build Topic criteria TopicCriteria topicCriteria = buildCriteria(cmsQuery, offset, limit, orderBy, prettyPrintEnabled); String queryResult = null; StringBuilder resourceRepresentation = new StringBuilder(); switch (output) { case XML: { queryResult = astroboaClient.getTopicService().searchTopics(topicCriteria, ResourceRepresentationType.XML); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(queryResult); } else { ContentApiUtils.generateXMLP(resourceRepresentation, queryResult, callback); } break; } case JSON: queryResult = astroboaClient.getTopicService().searchTopics(topicCriteria, ResourceRepresentationType.JSON); if (StringUtils.isBlank(callback)) { resourceRepresentation.append(queryResult); } else { ContentApiUtils.generateJSONP(resourceRepresentation, queryResult, callback); } break; /* This functionality is temporarily removed until the resolution of seam resource servlet problems * when multiple wars are deployed case XHTML: { List<ContentObject> contentObjects = searchContentObjects(contentObjectCriteria); Contexts.getEventContext().set("contentObjects", contentObjects); Contexts.getEventContext().set("repositoryId", AstroboaClientContextHolder.getActiveRepositoryId()); Contexts.getEventContext().set("templateObjectIdOrSystemName", templateIdOrSystemName); Contexts.getEventContext().set("templateProperty", "xhtml"); Renderer renderer = Renderer.instance(); String xhtmlOutput = renderer.render("/dynamicPage.xhtml"); if (StringUtils.isNotBlank(xhtmlOutput)) { resourceRepresentation.append(xhtmlOutput); } break; } case PDF: { List<ContentObject> contentObjects = searchContentObjects(contentObjectCriteria); Contexts.getEventContext().set("contentObjects", contentObjects); Contexts.getEventContext().set("repositoryId", AstroboaClientContextHolder.getActiveRepositoryId()); Contexts.getEventContext().set("templateObjectIdOrSystemName", templateIdOrSystemName); Contexts.getEventContext().set("templateProperty", "pdf"); byte[] pdfBytes = createPDF(""); return ContentApiUtils.createBinaryResponse( pdfBytes, "application/pdf", ContentDispositionType.ATTACHMENT, contentObjectCriteria.getXPathQuery() + ".pdf", null); } */ } 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:rapture.kernel.AdminApiImpl.java
@Override public void emailUser(CallingContext context, String userName, String emailTemplate, Map<String, Object> templateValues) { checkParameter("User", userName); //$NON-NLS-1$ RaptureUser user = getUser(context, userName); if (user != null) { templateValues.put("user", user); Mailer.email(context, emailTemplate, templateValues); } else {//from w w w.j av a2s. co m throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, adminMessageCatalog.getMessage("NoExistUser", userName)); //$NON-NLS-1$ } } }
From source file:rapture.kernel.BlobApiImpl.java
@Override public BlobRepoConfig getBlobRepoConfig(CallingContext context, String blobRepoUri) { RaptureURI uri = new RaptureURI(blobRepoUri, BLOB); if (uri.hasDocPath()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("NoDocPath", blobRepoUri)); //$NON-NLS-1$ }/*from w ww .j a v a 2 s.c om*/ return BlobRepoConfigStorage.readByAddress(uri); }
From source file:org.dcm4che3.tool.stowrs.StowRS.java
private static StowRSResponse sendDicomFile(String url, File f) throws IOException { int rspCode = 0; String rspMessage = null;// w w w .j a v a2 s.c o m URL newUrl = new URL(url); HttpURLConnection connection = (HttpURLConnection) newUrl.openConnection(); connection.setDoOutput(true); connection.setDoInput(true); connection.setInstanceFollowRedirects(false); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "multipart/related; type=application/dicom; boundary=" + MULTIPART_BOUNDARY); connection.setRequestProperty("Accept", "application/dicom+xml"); connection.setRequestProperty("charset", "utf-8"); connection.setUseCaches(false); DataOutputStream wr; wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes("\r\n--" + MULTIPART_BOUNDARY + "\r\n"); wr.writeBytes("Content-Disposition: inline; name=\"file[]\"; filename=\"" + f.getName() + "\"\r\n"); wr.writeBytes("Content-Type: application/dicom \r\n"); wr.writeBytes("\r\n"); FileInputStream fis = new FileInputStream(f); StreamUtils.copy(fis, wr); fis.close(); wr.writeBytes("\r\n--" + MULTIPART_BOUNDARY + "--\r\n"); wr.flush(); wr.close(); String response = connection.getResponseMessage(); rspCode = connection.getResponseCode(); rspMessage = connection.getResponseMessage(); LOG.info("response: " + response); Attributes responseAttrs = null; try { InputStream in; boolean isErrorCase = rspCode >= HttpURLConnection.HTTP_BAD_REQUEST; if (!isErrorCase) { in = connection.getInputStream(); } else { in = connection.getErrorStream(); } if (!isErrorCase || rspCode == HttpURLConnection.HTTP_CONFLICT) responseAttrs = SAXReader.parse(in); } catch (SAXException e) { throw new IOException(e); } catch (ParserConfigurationException e) { throw new IOException(e); } connection.disconnect(); return new StowRSResponse(rspCode, rspMessage, responseAttrs); }
From source file:org.eclipse.hono.adapter.mqtt.AbstractVertxBasedMqttProtocolAdapter.java
/** * Uploads a message to Hono Messaging.//from ww w .j av a2 s . com * * @param ctx The context in which the MQTT message has been published. * @param resource The resource that the message should be uploaded to. * @param payload The message payload to send. * @return A future indicating the outcome of the operation. * <p> * The future will succeed if the message has been uploaded successfully. Otherwise the future will fail * with a {@link ServiceInvocationException}. * @throws NullPointerException if any of context, resource or payload is {@code null}. * @throws IllegalArgumentException if the payload is empty. */ public final Future<Void> uploadMessage(final MqttContext ctx, final ResourceIdentifier resource, final Buffer payload) { Objects.requireNonNull(ctx); Objects.requireNonNull(resource); Objects.requireNonNull(payload); switch (EndpointType.fromString(resource.getEndpoint())) { case TELEMETRY: return uploadTelemetryMessage(ctx, resource.getTenantId(), resource.getResourceId(), payload); case EVENT: return uploadEventMessage(ctx, resource.getTenantId(), resource.getResourceId(), payload); default: return Future.failedFuture( new ClientErrorException(HttpURLConnection.HTTP_BAD_REQUEST, "unsupported endpoint")); } }
From source file:rapture.kernel.StructuredApiImpl.java
private void validateTable(String docPath) { if (!validator.isTableValid(docPath)) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, "Invalid table name provided"); }/*from w w w .ja va2 s. co m*/ }
From source file:rapture.kernel.StructuredApiImpl.java
private void validateColumns(Set<String> columns) { for (String column : columns) { if (!validator.isColumnValid(column)) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, "Invalid column name provided"); }// ww w .j a v a2 s . c o m } }
From source file:rapture.kernel.SeriesApiImpl.java
private Hose assemble(String program, List<String> args) { List<HoseArg> decodedArgs = Lists.transform(args, xsf2sv); try {//from w w w . j a va 2 s . c om return HoseProgram.compile(program).make(decodedArgs); } catch (RecognitionException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_BAD_REQUEST, apiMessageCatalog.getMessage("BadHose"), e); } }
From source file:i5.las2peer.services.gamificationQuestService.GamificationQuestService.java
/** * Get a quest data with specific ID from database * @param appId applicationId//from ww w .j a va2 s.com * @param questId quest id * @return HttpResponse returned as JSON object */ @GET @Path("/{appId}/{questId}") @Produces(MediaType.APPLICATION_JSON) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Found a quest"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Error"), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "Unauthorized") }) @ApiOperation(value = "getQuestWithId", notes = "Returns quest detail with specific ID", response = QuestModel.class) public HttpResponse getQuestWithId(@ApiParam(value = "Application ID") @PathParam("appId") String appId, @ApiParam(value = "Quest ID") @PathParam("questId") String questId) { // Request log L2pLogger.logEvent(this, Event.SERVICE_CUSTOM_MESSAGE_99, "GET " + "gamification/quests/" + appId + "/" + questId); long randomLong = new Random().nextLong(); //To be able to match QuestModel quest = null; Connection conn = null; JSONObject objResponse = new JSONObject(); 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_16, "" + randomLong); try { if (!questAccess.isAppIdExist(conn, appId)) { objResponse.put("message", "Cannot get 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 get 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); } if (!questAccess.isQuestIdExist(conn, appId, questId)) { objResponse.put("message", "Cannot get quest. Quest not found"); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_BAD_REQUEST); } quest = questAccess.getQuestWithId(conn, appId, questId); if (quest == null) { objResponse.put("message", "Cannot get quest. Quest Null, Cannot find quest with " + questId); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } ObjectMapper objectMapper = new ObjectMapper(); //Set pretty printing of json objectMapper.enable(SerializationFeature.INDENT_OUTPUT); String questString = objectMapper.writeValueAsString(quest); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_17, "" + randomLong); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_26, "" + name); L2pLogger.logEvent(Event.SERVICE_CUSTOM_MESSAGE_27, "" + appId); return new HttpResponse(questString, HttpURLConnection.HTTP_OK); } catch (SQLException e) { e.printStackTrace(); objResponse.put("message", "Cannot get quest. DB Error. " + e.getMessage()); L2pLogger.logEvent(this, Event.SERVICE_ERROR, (String) objResponse.get("message")); return new HttpResponse(objResponse.toJSONString(), HttpURLConnection.HTTP_INTERNAL_ERROR); } catch (IOException e) { e.printStackTrace(); objResponse.put("message", "Cannot get quest. Problem in the quest model. " + 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); } } }