Example usage for java.net HttpURLConnection HTTP_NOT_FOUND

List of usage examples for java.net HttpURLConnection HTTP_NOT_FOUND

Introduction

In this page you can find the example usage for java.net HttpURLConnection HTTP_NOT_FOUND.

Prototype

int HTTP_NOT_FOUND

To view the source code for java.net HttpURLConnection HTTP_NOT_FOUND.

Click Source Link

Document

HTTP Status-Code 404: Not Found.

Usage

From source file:com.netflix.genie.server.resources.ClusterConfigResource.java

/**
 * Get cluster configuration from unique id.
 *
 * @param id id for the cluster/*from   w  w w  . j av  a2 s .c  o m*/
 * @return the cluster
 * @throws GenieException For any error
 */
@GET
@Path("/{id}")
@ApiOperation(value = "Find a cluster by id", notes = "Get the cluster by id if it exists", response = Cluster.class)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Cluster not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Cluster getCluster(
        @ApiParam(value = "Id of the cluster to get.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id: " + id);
    return this.clusterConfigService.getCluster(id);
}

From source file:com.netflix.genie.server.resources.CommandConfigResource.java

/**
 * Get Command configuration for given id.
 *
 * @param id unique id for command configuration
 * @return The command configuration/*from  ww  w .  java2  s  . c o  m*/
 * @throws GenieException For any error
 */
@GET
@Path("/{id}")
@ApiOperation(value = "Find a command by id", notes = "Get the command by id if it exists", response = Command.class)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Command not found"),
        @ApiResponse(code = HttpURLConnection.HTTP_PRECON_FAILED, message = "Invalid required parameter supplied"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Genie Server Error due to Unknown Exception") })
public Command getCommand(
        @ApiParam(value = "Id of the command to get.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called to get command with id " + id);
    return this.commandConfigService.getCommand(id);
}

From source file:i5.las2peer.services.userManagement.UserManagement.java

/**
 * // ww w .  j  a  va  2s  . c om
 * getUser
 * 
 * 
 * @return HttpResponse
 * 
 */
@GET
@Path("/get")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.TEXT_PLAIN)
@ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "userFound"),
        @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "internal"),
        @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "userNotFound") })
@ApiOperation(value = "getUser", notes = "")
public HttpResponse getUser() {
    // userFound
    boolean userFound_condition = true;
    if (userFound_condition) {
        JSONObject user = new JSONObject();
        HttpResponse userFound = new HttpResponse(user.toJSONString(), HttpURLConnection.HTTP_OK);
        return userFound;
    }
    // internal
    boolean internal_condition = true;
    if (internal_condition) {
        String error = "Some String";
        HttpResponse internal = new HttpResponse(error, HttpURLConnection.HTTP_INTERNAL_ERROR);
        return internal;
    }
    // userNotFound
    boolean userNotFound_condition = true;
    if (userNotFound_condition) {
        String error = "Some String";
        HttpResponse userNotFound = new HttpResponse(error, HttpURLConnection.HTTP_NOT_FOUND);
        return userNotFound;
    }
    return null;
}

From source file:com.netflix.genie.server.resources.ApplicationConfigResource.java

/**
 * Get Application for given id./*from w w w.j  a  va 2 s .c  o  m*/
 *
 * @param id unique id for application configuration
 * @return The application configuration
 * @throws GenieException For any error
 */
@GET
@Path("/{id}")
@ApiOperation(value = "Find an application by id", notes = "Get the application by id if it exists", response = Application.class)
@ApiResponses(value = {
        @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "OK", response = Application.class),
        @ApiResponse(code = HttpURLConnection.HTTP_NOT_FOUND, message = "Application 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 Application getApplication(
        @ApiParam(value = "Id of the application to get.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called to get Application for id " + id);
    return this.applicationConfigService.getApplication(id);
}

From source file:com.utest.webservice.interceptors.UtestRestFaultOutInterceptor.java

public String buildResponse(final Message message) {
    final StringBuffer sb = new StringBuffer();
    final Fault fault = (Fault) message.getContent(Exception.class);
    final String accept = (String) message.getExchange().getInMessage().get(Message.ACCEPT_CONTENT_TYPE);
    int type = TYPE_TEXT;
    int responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
    if (accept.contains(MediaType.APPLICATION_XML)) {
        type = TYPE_XML;//from www. j  av a  2  s.c o  m
        message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_XML);
    } else if (accept.contains(MediaType.APPLICATION_JSON)) {
        type = TYPE_JSON;
        message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
    } else {
        message.put(Message.CONTENT_TYPE, MediaType.TEXT_PLAIN);
    }
    sb.append(getStart(type));
    if (fault.getCause() instanceof ValidationException) {
        final ValidationException ve = (ValidationException) fault.getCause();
        for (final String errmsg : ve.getMessageKeys()) {
            sb.append(createError(type, fault.getCause(), errmsg));
        }
    } else {
        sb.append(createError(type, fault.getCause(), fault.getCause().getMessage()));
    }

    if ((fault.getCause() instanceof org.apache.cxf.interceptor.security.AccessDeniedException)
            || (fault.getCause() instanceof org.springframework.security.access.AccessDeniedException)) {
        responseCode = HttpURLConnection.HTTP_FORBIDDEN;// Access deny
    } else if (fault.getCause() instanceof NotFoundException) {
        responseCode = HttpURLConnection.HTTP_NOT_FOUND;// Not found
    } else if ((fault.getCause() instanceof StaleObjectStateException)
            || (fault.getCause() instanceof StaleStateException)) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof EmailInUseException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof ScreenNameInUseException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof InvalidParentChildEnvironmentException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof DuplicateTestCaseStepException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof DuplicateNameException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof DeletingActivatedEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof DeletingUsedEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof ActivatingIncompleteEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof UnsupportedEnvironmentSelectionException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof ApprovingIncompleteEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof ActivatingNotApprovedEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof ChangingActivatedEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof IncludingMultileVersionsOfSameEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// not allowed
    } else if (fault.getCause() instanceof AssigningMultileVersionsOfSameEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof IncludingNotActivatedEntityException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// Not allowed
    } else if (fault.getCause() instanceof TestCaseExecutionBlockedException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// Not allowed
    } else if (fault.getCause() instanceof TestCaseExecutionWithoutRestartException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// Not allowed
    } else if (fault.getCause() instanceof InvalidParentChildEnvironmentException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof UnsupportedTeamSelectionException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof NoTeamDefinitionException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof InvalidTeamMemberException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    } else if (fault.getCause() instanceof TestCycleClosedException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    }
    // this is here to catch all business exceptions if this interceptor
    // wasn't updated properly
    else if (fault.getCause() instanceof DomainException) {
        responseCode = HttpURLConnection.HTTP_CONFLICT;// conflict
    }

    message.put(Message.RESPONSE_CODE, responseCode);
    sb.append(getEnd(type));
    return sb.toString();
}

From source file:org.wso2.msf4j.deployer.MSF4JDeployerTest.java

@Test(dependsOnMethods = "testJarArtifactDeployment")
public void testJarArtifactUndeployment() throws Exception {
    Optional<Path> path = getSampleJarFile(Paths.get(stockqoutesSamplesFile, "deployable-jar", "target"));
    assertTrue("Sample artifact doesn't found in output directory : "
            + Paths.get(stockqoutesSamplesFile, "deployable-jar", "target"), path.isPresent());
    File file = path.get().toFile();
    deployer.undeploy(file.getAbsolutePath());
    HttpURLConnection urlConn = request("/stockquote/IBM", HttpMethod.GET);
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, urlConn.getResponseCode());
}

From source file:play.modules.resteasy.crud.RESTResource.java

/**
 * Returns a NOT_FOUND response
 */
protected Response notFound() {
    return status(HttpURLConnection.HTTP_NOT_FOUND);
}

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");
    }/*from  ww w.  ja  v  a  2 s .com*/

    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.betaconceptframework.astroboa.resourceapi.resource.DefinitionResource.java

@GET
@Produces(MediaType.APPLICATION_JSON)//w  w  w  .  jav a  2s  .co m
@Path("/{propertyPath: " + CmsConstants.PROPERTY_PATH_REG_EXP_FOR_RESTEASY + "}")
public Response getDefinitionAsJson(@PathParam("propertyPath") String propertyPath,
        @QueryParam("output") String output, @QueryParam("callback") String callback,
        @QueryParam("prettyPrint") String prettyPrint) {

    boolean prettyPrintEnabled = ContentApiUtils.isPrettyPrintEnabled(prettyPrint);

    // URL-based negotiation overrides any Accept header sent by the client
    //i.e. if the url specifies the desired response type in the "output" parameter this method
    // will return the media type specified in "output" request parameter.
    Output outputEnum = Output.JSON;
    if (StringUtils.isNotBlank(output)) {
        outputEnum = Output.valueOf(output.toUpperCase());

        if (outputEnum != Output.XSD && asrtoboaBuiltInModelIsRequested(propertyPath)) {
            //User has requested astroboa-model or astroboa-api built in schemata
            //but at the same time, the "output" request parameter was not XSD
            //In this case an HTTP NOT FOUND error should be returned.
            throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND);
        }
    }

    return getDefinitionInternal(propertyPath, outputEnum, callback, prettyPrintEnabled);
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitTagTest.java

@Test
public void testListDeleteTags() throws Exception {
    URI workspaceLocation = createWorkspace(getMethodName());
    IPath[] clonePaths = createTestProjects(workspaceLocation);

    for (IPath clonePath : clonePaths) {
        // clone a  repo
        JSONObject clone = clone(clonePath);
        String cloneContentLocation = clone.getString(ProtocolConstants.KEY_CONTENT_LOCATION);

        // get project/folder metadata
        WebRequest request = getGetRequest(cloneContentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject folder = new JSONObject(response.getText());

        JSONObject gitSection = folder.getJSONObject(GitConstants.KEY_GIT);
        String gitHeadUri = gitSection.getString(GitConstants.KEY_HEAD);
        String gitTagUri = gitSection.getString(GitConstants.KEY_TAG);

        JSONArray tags = listTags(gitTagUri);
        assertEquals(0, tags.length());//from w  ww. j  a  v  a 2 s .com

        // log
        JSONArray commitsArray = log(gitHeadUri);
        assertEquals(1, commitsArray.length());

        JSONObject commit = commitsArray.getJSONObject(0);
        String commitId = commit.getString(ProtocolConstants.KEY_NAME);
        String commitLocation = commit.getString(ProtocolConstants.KEY_LOCATION);

        tag(gitTagUri, "tag1", commitId);

        tags = listTags(gitTagUri);
        assertEquals(1, tags.length());
        assertEquals("tag1", tags.getJSONObject(0).get(ProtocolConstants.KEY_NAME));

        // update commit with tag
        tag(commitLocation, "tag2");

        tags = listTags(gitTagUri);
        assertEquals(2, tags.length());
        assertEquals("tag2", tags.getJSONObject(0).get(ProtocolConstants.KEY_NAME));

        // delete 'tag1'
        JSONObject tag1 = tags.getJSONObject(1);
        assertEquals("tag1", tag1.get(ProtocolConstants.KEY_NAME));
        String tag1Uri = tag1.getString(ProtocolConstants.KEY_LOCATION);
        deleteTag(tag1Uri);

        tags = listTags(gitTagUri);
        assertEquals(1, tags.length());
        assertEquals("tag2", tags.getJSONObject(0).get(ProtocolConstants.KEY_NAME));

        // check if the deleted tag is gone
        request = getGetGitTagRequest(tag1Uri);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
    }
}