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.baracuda.piepet.nexusrelease.nexus.StageClient.java

public boolean checkStageForGAV(Stage stage, String group, String artifact, String version)
        throws StageException {
    // do we always know the version???
    // to browse an open repo
    // /service/local/repositories/${stageID}/content/...
    // the stage repos are not listed via a call to
    // /service/local/repositories/ but are in existence!
    boolean found = false;
    try {/*from w w  w . jav a 2s . c  o m*/
        URL url;
        if (version == null) {
            url = new URL(nexusURL, "service/local/repositories/" + stage.getStageID() + "/content/"
                    + group.replace('.', '/') + '/' + artifact + "/?isLocal");
        } else {
            url = new URL(nexusURL, "service/local/repositories/" + stage.getStageID() + "/content/"
                    + group.replace('.', '/') + '/' + artifact + '/' + version + "/?isLocal");
        }
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        addAuthHeader(conn);
        conn.setRequestMethod("HEAD");
        int response = conn.getResponseCode();
        if (response == HttpURLConnection.HTTP_OK) {
            // we found our baby - may be a different version but we don't
            // always have that to hand (if Maven did the auto numbering)
            found = true;
        } else if (response == HttpURLConnection.HTTP_NOT_FOUND) {
            // not this repo
        } else {
            log.warn("Server returned HTTP status {} when we only expected a 200 or 404.",
                    Integer.toString(response));
        }
        conn.disconnect();
    } catch (IOException ex) {
        throw createStageExceptionForIOException(nexusURL, ex);
    }
    return found;
}

From source file:org.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java

private Response saveTaxonomySource(String taxonomySource, String httpMethod, boolean entityIsNew) {

    logger.debug("Want to save a new taxonomy {}", taxonomySource);

    try {// w ww.  j a  v  a2 s. co  m

        ImportConfiguration configuration = ImportConfiguration.taxonomy()
                .persist(PersistMode.PERSIST_ENTITY_TREE).build();

        Taxonomy taxonomy = astroboaClient.getImportService().importTaxonomy(taxonomySource, configuration);

        return ContentApiUtils.createResponseForPutOrPostOfACmsEntity(taxonomy, httpMethod, taxonomySource,
                entityIsNew);

    } catch (CmsUnauthorizedAccessException e) {
        throw new WebApplicationException(HttpURLConnection.HTTP_UNAUTHORIZED);
    } catch (Exception e) {
        logger.error("", e);
        throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND);
    }
}

From source file:org.projectbuendia.client.ui.OdkActivityLauncher.java

private static void handleSubmitError(VolleyError error) {
    SubmitXformFailedEvent.Reason reason = SubmitXformFailedEvent.Reason.UNKNOWN;

    if (error instanceof TimeoutError) {
        reason = SubmitXformFailedEvent.Reason.SERVER_TIMEOUT;
    } else if (error.networkResponse != null) {
        switch (error.networkResponse.statusCode) {
        case HttpURLConnection.HTTP_UNAUTHORIZED:
        case HttpURLConnection.HTTP_FORBIDDEN:
            reason = SubmitXformFailedEvent.Reason.SERVER_AUTH;
            break;
        case HttpURLConnection.HTTP_NOT_FOUND:
            reason = SubmitXformFailedEvent.Reason.SERVER_BAD_ENDPOINT;
            break;
        case HttpURLConnection.HTTP_INTERNAL_ERROR:
            if (error.networkResponse.data == null) {
                LOG.e("Server error, but no internal error stack trace available.");
            } else {
                LOG.e(new String(error.networkResponse.data, Charsets.UTF_8));
                LOG.e("Server error. Internal error stack trace:\n");
            }//from w w w.  j a v a  2 s  .  com
            reason = SubmitXformFailedEvent.Reason.SERVER_ERROR;
            break;
        default:
            reason = SubmitXformFailedEvent.Reason.SERVER_ERROR;
            break;
        }
    }

    EventBus.getDefault().post(new SubmitXformFailedEvent(reason, error));
}

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

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

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

        // get project metadata
        WebRequest request = getGetRequest(contentLocation);
        WebResponse response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());
        JSONObject project = new JSONObject(response.getText());
        JSONObject gitSection = project.getJSONObject(GitConstants.KEY_GIT);
        String gitConfigUri = gitSection.getString(GitConstants.KEY_CONFIG);

        // set some dummy value
        final String ENTRY_KEY = "a.b.c";
        final String ENTRY_VALUE = "v";

        request = getPostGitConfigRequest(gitConfigUri, ENTRY_KEY, ENTRY_VALUE);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_CREATED, response.getResponseCode());

        JSONObject configResponse = new JSONObject(response.getText());
        String entryLocation = configResponse.getString(ProtocolConstants.KEY_LOCATION);

        // check if it exists
        request = getGetGitConfigRequest(entryLocation);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // delete config entry
        request = getDeleteGitConfigRequest(entryLocation);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_OK, response.getResponseCode());

        // it shouldn't exist
        request = getGetGitConfigRequest(entryLocation);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());

        // so next delete operation should fail
        request = getDeleteGitConfigRequest(entryLocation);
        response = webConversation.getResponse(request);
        assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
    }//from w  ww.j a va 2  s . co  m
}

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

/**
 * Update the jar files for a given application.
 *
 * @param id   The id of the application to update the jar files for. Not
 *             null/empty/blank.//from   w w  w . j  a  v  a  2s .c  o m
 * @param jars The jar files to replace existing jar files with. Not
 *             null/empty/blank.
 * @return The active set of application jars
 * @throws GenieException For any error
 */
@PUT
@Path("/{id}/jars")
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(value = "Update jar files for an application", notes = "Replace the existing jar files for application with given id.", response = String.class, responseContainer = "List")
@ApiResponses(value = {
        @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 Set<String> updateJarsForApplication(
        @ApiParam(value = "Id of the application to update configurations for.", required = true) @PathParam("id") final String id,
        @ApiParam(value = "The jar files to replace existing with.", required = true) final Set<String> jars)
        throws GenieException {
    LOG.info("Called with id " + id + " and jars " + jars);
    return this.applicationConfigService.updateJarsForApplication(id, jars);
}

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

@Test
public void testCheckoutEmptyBranchName() throws Exception {
    // clone a repo
    URI workspaceLocation = createWorkspace(getMethodName());
    String workspaceId = workspaceIdFromLocation(workspaceLocation);
    JSONObject project = createProjectOrLink(workspaceLocation, getMethodName(), null);
    IPath clonePath = getClonePath(workspaceId, project);
    JSONObject clone = clone(clonePath);
    String location = clone.getString(ProtocolConstants.KEY_LOCATION);

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

    // checkout/*w  ww. j  a va2s . c om*/
    response = checkoutBranch(location, "");
    assertEquals(HttpURLConnection.HTTP_NOT_FOUND, response.getResponseCode());
}

From source file:org.betaconceptframework.astroboa.resourceapi.resource.TaxonomyResource.java

private Response getTopicInTaxonomyInternal(String taxonomyIdOrName, String topicPathWithIdsOrSystemNames,
        Output output, String callback, boolean prettyPrint) {

    try {//from  www.  j a v  a 2s.  co  m

        Topic topic = findTopicByTaxonomyIdOrNameAndTopicPathWithIdsOrNames(taxonomyIdOrName,
                topicPathWithIdsOrSystemNames);

        if (topic == null) {
            throw new WebApplicationException(HttpURLConnection.HTTP_NOT_FOUND);
        }

        // Lazy load topic children so they will be rendered in XML or JSON response
        topic.getChildren();

        StringBuilder topicAsXMLOrJSON = new StringBuilder();

        switch (output) {
        case XML: {
            if (StringUtils.isBlank(callback)) {
                topicAsXMLOrJSON.append(topic.xml(prettyPrint));
            } else {
                ContentApiUtils.generateXMLP(topicAsXMLOrJSON, topic.xml(prettyPrint), callback);
            }
            break;
        }
        case JSON:
            if (StringUtils.isBlank(callback)) {
                topicAsXMLOrJSON.append(topic.json(prettyPrint));
            } else {
                ContentApiUtils.generateXMLP(topicAsXMLOrJSON, topic.json(prettyPrint), callback);
            }
            break;
        }

        return ContentApiUtils.createResponse(topicAsXMLOrJSON, output, callback, null);

    } catch (Exception e) {
        logger.error("Taxonomy IdOrName: " + taxonomyIdOrName + ", Topic Path with Ids Or Names: "
                + topicPathWithIdsOrSystemNames, e);
        throw new WebApplicationException(HttpURLConnection.HTTP_BAD_REQUEST);
    }
}

From source file:org.apache.axis.transport.http.AxisServlet.java

/**
 * probe for a JWS page and report 'no service' if one is not found there
 * @param request the request that didnt have an edpoint
 * @param response response we are generating
 * @param writer open writer for the request
 *///from w w w  .  j  av a 2  s.c  om
protected void reportCantGetJWSService(HttpServletRequest request, HttpServletResponse response,
        PrintWriter writer) {
    // first look to see if there is a service
    // requestPath is a work around to support serving .jws web services
    // from services URL - see AXIS-843 for more information
    String requestPath = request.getServletPath()
            + ((request.getPathInfo() != null) ? request.getPathInfo() : "");
    String realpath = getServletConfig().getServletContext().getRealPath(requestPath);
    log.debug("JWS real path: " + realpath);
    boolean foundJWSFile = (new File(realpath).exists())
            && (realpath.endsWith(Constants.JWS_DEFAULT_FILE_EXTENSION));
    response.setContentType("text/html; charset=utf-8");
    if (foundJWSFile) {
        response.setStatus(HttpURLConnection.HTTP_OK);
        writer.println(Messages.getMessage("foundJWS00") + "<p>");
        String url = request.getRequestURI();
        String urltext = Messages.getMessage("foundJWS01");
        writer.println("<a href='" + url + "?wsdl'>" + urltext + "</a>");
    } else {
        response.setStatus(HttpURLConnection.HTTP_NOT_FOUND);
        writer.println(Messages.getMessage("noService06"));
    }
}

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

/**
 * Remove the all commands from a given cluster.
 *
 * @param id The id of the cluster to delete the commands from. Not
 *           null/empty/blank.//from   ww  w  .j  av a  2s.c om
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/commands")
@ApiOperation(value = "Remove all commands from an cluster", notes = "Remove all the commands from the cluster with given id.", response = Command.class, responseContainer = "List")
@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 List<Command> removeAllCommandsForCluster(
        @ApiParam(value = "Id of the cluster to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.clusterConfigService.removeAllCommandsForCluster(id);
}

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

/**
 * Delete the all tags from a given command.
 *
 * @param id The id of the command to delete the tags from.
 *           Not null/empty/blank./*from www.  j  ava 2 s .c o m*/
 * @return Empty set if successful
 * @throws GenieException For any error
 */
@DELETE
@Path("/{id}/tags")
@ApiOperation(value = "Remove all tags from a command", notes = "Remove all the tags from the command with given id.  Note that the genie name space tags"
        + "prefixed with genie.id and genie.name cannot be deleted.", response = String.class, responseContainer = "List")
@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 Set<String> removeAllTagsForCommand(
        @ApiParam(value = "Id of the command to delete from.", required = true) @PathParam("id") final String id)
        throws GenieException {
    LOG.info("Called with id " + id);
    return this.commandConfigService.removeAllTagsForCommand(id);
}