List of usage examples for java.net HttpURLConnection HTTP_INTERNAL_ERROR
int HTTP_INTERNAL_ERROR
To view the source code for java.net HttpURLConnection HTTP_INTERNAL_ERROR.
Click Source Link
From source file:rapture.kernel.AuditApiImpl.java
@Override public List<AuditLogEntry> getRecentUserActivity(CallingContext context, String user, int count) { if (count == 0) { return new ArrayList<>(); }//ww w. j ava 2s. com RaptureURI internalURI = new RaptureURI(RaptureConstants.DEFAULT_AUDIT_URI, Scheme.LOG); AuditLog ilog = Kernel.getKernel().getLog(context, internalURI); if (ilog == null) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, auditMsgCatalog.getMessage("KernelLogInvalid")); } return ilog.getRecentUserActivity(user, count); }
From source file:org.codinjutsu.tools.jenkins.security.DefaultSecurityClient.java
protected void checkResponse(int statusCode, String responseBody) throws AuthenticationException { if (statusCode == HttpURLConnection.HTTP_NOT_FOUND) { throw new AuthenticationException("Not found"); }// w w w. j a va2 s .c om if (statusCode == HttpURLConnection.HTTP_FORBIDDEN || statusCode == HttpURLConnection.HTTP_UNAUTHORIZED) { if (StringUtils.containsIgnoreCase(responseBody, BAD_CRUMB_DATA)) { throw new AuthenticationException("CSRF enabled -> Missing or bad crumb data"); } throw new AuthenticationException("Unauthorized -> Missing or bad credentials", responseBody); } if (HttpURLConnection.HTTP_INTERNAL_ERROR == statusCode) { throw new AuthenticationException("Server Internal Error: Server unavailable"); } }
From source file:org.eclipse.hono.service.credentials.CredentialsEndpoint.java
private void processRequest(final Message msg) { final JsonObject credentialsMsg = CredentialsConstants.getCredentialsMsg(msg); vertx.eventBus().send(EVENT_BUS_ADDRESS_CREDENTIALS_IN, credentialsMsg, result -> { JsonObject response = null;/* w w w. ja va 2 s .c o m*/ if (result.succeeded()) { // TODO check for correct session here...? response = (JsonObject) result.result().body(); } else { logger.debug("failed to process credentials request [msg ID: {}] due to {}", msg.getMessageId(), result.cause()); // we need to inform client about failure response = CredentialsConstants.getReply(HttpURLConnection.HTTP_INTERNAL_ERROR, MessageHelper.getTenantIdAnnotation(msg), null, null); } addHeadersToResponse(msg, response); vertx.eventBus().send(msg.getReplyTo(), response); }); }
From source file:org.eclipse.hono.service.registration.RegistrationEndpoint.java
private void processRequest(final Message msg) { final JsonObject registrationMsg = RegistrationConstants.getRegistrationMsg(msg); vertx.eventBus().send(EVENT_BUS_ADDRESS_REGISTRATION_IN, registrationMsg, result -> { JsonObject response = null;// www. j a va2 s . c o m if (result.succeeded()) { // TODO check for correct session here...? response = (JsonObject) result.result().body(); } else { logger.debug("failed to process request [msg ID: {}] due to {}", msg.getMessageId(), result.cause()); // we need to inform client about failure response = RegistrationConstants.getReply(HttpURLConnection.HTTP_INTERNAL_ERROR, MessageHelper.getTenantIdAnnotation(msg), MessageHelper.getDeviceIdAnnotation(msg), null); } addHeadersToResponse(msg, response); vertx.eventBus().send(msg.getReplyTo(), response); }); }
From source file:rapture.table.file.FileIndexHandler.java
private void persistIndexEntry(String key, Map<String, Object> value, FileOutputStream stream) { IndexEntry entry = new IndexEntry(); entry.setKey(key);/*from w w w .j av a 2s . c o m*/ entry.setValue(value); String output = JacksonUtil.jsonFromObject(entry) + System.getProperty("line.separator"); try { stream.write(output.getBytes(charsetName)); stream.flush(); } catch (IOException e) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Error writing incremental update to index file", e); } }
From source file:be.cytomine.client.HttpClient.java
public int get(String url, String dest) throws IOException { log.debug("get:" + url); URL URL = new URL(url); HttpHost targetHost = new HttpHost(URL.getHost(), URL.getPort()); log.debug("targetHost:" + targetHost); DefaultHttpClient client = new DefaultHttpClient(); log.debug("client:" + client); // Add AuthCache to the execution context BasicHttpContext localcontext = new BasicHttpContext(); log.debug("localcontext:" + localcontext); headersArray = null;/* w w w . j a v a 2 s.c om*/ authorize("GET", URL.toString(), "", "application/json,*/*"); HttpGet httpGet = new HttpGet(URL.getPath()); httpGet.setHeaders(headersArray); HttpResponse response = client.execute(targetHost, httpGet, localcontext); int code = response.getStatusLine().getStatusCode(); log.info("url=" + url + " is " + code + "(OK=" + HttpURLConnection.HTTP_OK + ",MOVED=" + HttpURLConnection.HTTP_MOVED_TEMP + ")"); boolean isOK = (code == HttpURLConnection.HTTP_OK); boolean isFound = (code == HttpURLConnection.HTTP_MOVED_TEMP); boolean isErrorServer = (code == HttpURLConnection.HTTP_INTERNAL_ERROR); if (!isOK && !isFound & !isErrorServer) { throw new IOException(url + " cannot be read: " + code); } HttpEntity entity = response.getEntity(); if (entity != null) { entity.writeTo(new FileOutputStream(dest)); } return code; }
From source file:org.betaconceptframework.astroboa.console.security.ResourceApiProxy.java
@GET @PUT/*from ww w . ja v a 2 s.c o m*/ @POST @DELETE @Path("{resourceApiPath:.*}") @Produces("*/*") public Response dispatchToAstroboaRepository(@PathParam("resourceApiPath") String resourceApiPath, @Context UriInfo uriInfo, @Context HttpServletRequest httpServletRequest) { try { String repositoryId = AstroboaClientContextHolder.getActiveRepositoryId(); if (StringUtils.isBlank(repositoryId)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } CmsRepository activeCmsRepository = AstroboaClientContextHolder.getActiveCmsRepository(); if (activeCmsRepository == null) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } SecurityContext securityContext = AstroboaClientContextHolder.getActiveSecurityContext(); if (securityContext == null) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } String username = securityContext.getIdentity(); if (StringUtils.isBlank(username)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } String resourceApiBasePath = activeCmsRepository.getRestfulApiBasePath(); if (StringUtils.isBlank(resourceApiBasePath)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } HttpSession httpSession = httpServletRequest.getSession(); String password = (String) httpSession.getAttribute("repositoryPassword"); if (StringUtils.isBlank(password)) { throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND); } String httpMethod = httpServletRequest.getMethod(); String requestPath = uriInfo.getPath(); MultivaluedMap<String, String> queryParameters = uriInfo.getQueryParameters(); ClientRequest request = new ClientRequest( "http://localhost:8080" + resourceApiBasePath + "/" + repositoryId + requestPath); // read the payload if the http method is put or post if (httpMethod.equals("POST") || httpMethod.equals("PUT")) { request.body(httpServletRequest.getContentType(), getBody(httpServletRequest)); } // add authorization header (BASIC AUTH) String basicAuthString = username + ":" + password; String authorization = "BASIC " + Base64.encodeBytes(basicAuthString.getBytes()); request.header(HttpHeaders.AUTHORIZATION, authorization); // add headers Enumeration headerNames = httpServletRequest.getHeaderNames(); while (headerNames.hasMoreElements()) { String headerName = (String) headerNames.nextElement(); request.header(headerName, httpServletRequest.getHeader(headerName)); } // add query parameters for (Map.Entry queryParamEntry : queryParameters.entrySet()) { String parameterValue = ((List<String>) queryParamEntry.getValue()).get(0); //ClientRequest (request) encodes the values before the execution of the request. //Therefore we need to decode the values before we feed them to the ClientRequest instance request.queryParameter((String) queryParamEntry.getKey(), URLDecoder.decode(parameterValue, "UTF-8")); } String uri = request.getUri(); ClientResponse clientResponse = request.httpMethod(httpMethod, new GenericType<InputStream>() { }); return clientResponse; } catch (WebApplicationException e) { throw e; } catch (Exception e) { logger.error("A problem occured while sending request to Astroboa Repository", e); throw new WebApplicationException(HttpURLConnection.HTTP_INTERNAL_ERROR); } }
From source file:org.apache.calcite.avatica.remote.AvaticaCommonsHttpClientImpl.java
public byte[] send(byte[] request) { while (true) { HttpClientContext context = HttpClientContext.create(); context.setTargetHost(host);//from w ww . j av a 2 s .com // Set the credentials if they were provided. if (null != this.credentials) { context.setCredentialsProvider(credentialsProvider); context.setAuthSchemeRegistry(authRegistry); context.setAuthCache(authCache); } ByteArrayEntity entity = new ByteArrayEntity(request, ContentType.APPLICATION_OCTET_STREAM); // Create the client with the AuthSchemeRegistry and manager HttpPost post = new HttpPost(uri); post.setEntity(entity); try (CloseableHttpResponse response = execute(post, context)) { final int statusCode = response.getStatusLine().getStatusCode(); if (HttpURLConnection.HTTP_OK == statusCode || HttpURLConnection.HTTP_INTERNAL_ERROR == statusCode) { return EntityUtils.toByteArray(response.getEntity()); } else if (HttpURLConnection.HTTP_UNAVAILABLE == statusCode) { LOG.debug("Failed to connect to server (HTTP/503), retrying"); continue; } throw new RuntimeException("Failed to execute HTTP Request, got HTTP/" + statusCode); } catch (NoHttpResponseException e) { // This can happen when sitting behind a load balancer and a backend server dies LOG.debug("The server failed to issue an HTTP response, retrying"); continue; } catch (RuntimeException e) { throw e; } catch (Exception e) { LOG.debug("Failed to execute HTTP request", e); throw new RuntimeException(e); } } }
From source file:com.netflix.genie.server.resources.CommandConfigResource.java
/** * Get Command configuration based on user parameters. * * @param name Name for command (optional) * @param userName The user who created the configuration (optional) * @param statuses The statuses of the commands to get (optional) * @param tags The set of tags you want the command for. * @param page The page to start one (optional) * @param limit The max number of results to return per page (optional) * @param descending Whether results returned in descending or ascending order (optional) * @param orderBys The fields to order the results by (optional) * @return All the Commands matching the criteria or all if no criteria * @throws GenieException For any error/*w w w .j a v a 2s .c o m*/ */ @GET @ApiOperation(value = "Find commands", notes = "Find commands by the submitted criteria.", response = Command.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "One of the statuses was invalid"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Command> getCommands( @ApiParam(value = "Name of the command.") @QueryParam("name") final String name, @ApiParam(value = "User who created the command.") @QueryParam("userName") final String userName, @ApiParam(value = "The statuses of the commands to find.", allowableValues = "ACTIVE, DEPRECATED, INACTIVE") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info("Called [name | userName | status | tags | page | limit | descending | orderBys]"); LOG.info(name + " | " + userName + " | " + statuses + " | " + tags + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); Set<CommandStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(CommandStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(CommandStatus.parse(status)); } } } return this.commandConfigService.getCommands(name, userName, enumStatuses, tags, page, limit, descending, orderBys); }
From source file:com.netflix.genie.server.resources.ClusterConfigResource.java
/** * Get cluster config based on user params. If empty strings are passed for * they are treated as nulls (not false). * * @param name cluster name (can be a pattern) * @param statuses valid types - Types.ClusterStatus * @param tags tags for the cluster * @param minUpdateTime min time when cluster configuration was updated * @param maxUpdateTime max time when cluster configuration was updated * @param limit number of entries to return * @param page page number//from w w w . j av a 2 s . c o m * @param descending Whether results returned in descending or ascending order * @param orderBys The fields to order the results by * @return the Clusters found matching the criteria * @throws GenieException For any error */ @GET @ApiOperation(value = "Find clusters", notes = "Find clusters by the submitted criteria.", response = Cluster.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "If one of status is invalid"), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") }) public List<Cluster> getClusters( @ApiParam(value = "Name of the cluster.") @QueryParam("name") final String name, @ApiParam(value = "Status of the cluster.", allowableValues = "UP, OUT_OF_SERVICE, TERMINATED") @QueryParam("status") final Set<String> statuses, @ApiParam(value = "Tags for the cluster.") @QueryParam("tag") final Set<String> tags, @ApiParam(value = "Minimum time threshold for cluster update") @QueryParam("minUpdateTime") final Long minUpdateTime, @ApiParam(value = "Maximum time threshold for cluster update") @QueryParam("maxUpdateTime") final Long maxUpdateTime, @ApiParam(value = "The page to start on.") @QueryParam("page") @DefaultValue("0") final int page, @ApiParam(value = "Max number of results per page.") @QueryParam("limit") @DefaultValue("1024") final int limit, @ApiParam(value = "Whether results should be sorted in descending or ascending order. Defaults to descending") @QueryParam("descending") @DefaultValue("true") final boolean descending, @ApiParam(value = "The fields to order the results by. Must not be collection fields. Default is updated.") @QueryParam("orderBy") final Set<String> orderBys) throws GenieException { LOG.info( "Called [name | statuses | tags | minUpdateTime | maxUpdateTime | page | limit | descending | orderBys]"); LOG.info(name + " | " + statuses + " | " + tags + " | " + minUpdateTime + " | " + maxUpdateTime + " | " + page + " | " + limit + " | " + descending + " | " + orderBys); //Create this conversion internal in case someone uses lower case by accident? Set<ClusterStatus> enumStatuses = null; if (!statuses.isEmpty()) { enumStatuses = EnumSet.noneOf(ClusterStatus.class); for (final String status : statuses) { if (StringUtils.isNotBlank(status)) { enumStatuses.add(ClusterStatus.parse(status)); } } } return this.clusterConfigService.getClusters(name, enumStatuses, tags, minUpdateTime, maxUpdateTime, page, limit, descending, orderBys); }