Example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

List of usage examples for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Prototype

int SC_NOT_FOUND

To view the source code for org.apache.commons.httpclient HttpStatus SC_NOT_FOUND.

Click Source Link

Document

<tt>404 Not Found</tt> (HTTP/1.0 - RFC 1945)

Usage

From source file:com.thoughtworks.go.agent.launcher.ServerCall.java

public static ServerResponseWrapper invoke(HttpMethod method) throws Exception {
    HashMap<String, String> headers = new HashMap<String, String>();
    HttpClient httpClient = new HttpClient();
    httpClient.setConnectionTimeout(HTTP_TIMEOUT_IN_MILLISECONDS);
    try {//from   ww  w .ja  v a2s .c  o  m
        final int status = httpClient.executeMethod(method);
        if (status == HttpStatus.SC_NOT_FOUND) {
            StringWriter sw = new StringWriter();
            PrintWriter out = new PrintWriter(sw);
            out.println("Return Code: " + status);
            out.println("Few Possible Causes: ");
            out.println("1. Your Go Server is down or not accessible.");
            out.println(
                    "2. This agent might be incompatible with your Go Server.Please fix the version mismatch between Go Server and Go Agent.");
            out.close();
            throw new Exception(sw.toString());
        }
        if (status != HttpStatus.SC_OK) {
            throw new Exception("Got status " + status + " " + method.getStatusText() + " from server");
        }
        for (Header header : method.getResponseHeaders()) {
            headers.put(header.getName(), header.getValue());
        }
        return new ServerResponseWrapper(headers, method.getResponseBodyAsStream());
    } catch (Exception e) {
        String message = "Couldn't access Go Server with base url: " + method.getURI() + ": " + e.toString();
        LOG.error(message);
        throw new Exception(message, e);
    } finally {
        method.releaseConnection();
    }
}

From source file:atg.taglib.json.Helper.java

/**
 * Get a response from the server for a test
 *
 * @param pTestUrl The test url, relative to the tests context root
 * @return the <code>ResponseData</code> object for this test
 * @throws IOException /*  w  ww  .  ja va 2  s  .  co  m*/
 * @throws HttpException 
 * @throws JSONException 
 */
public static ResponseData getData(String pType, int pTestNum)
        throws HttpException, IOException, JSONException {
    // Setup HTTP client
    HttpClient client = new HttpClient();
    HttpMethod method = new GetMethod(getTestUrl(pType, pTestNum));

    // Execute the GET request, capturing response status
    int statusCode = client.executeMethod(method);
    String responseBody = method.getResponseBodyAsString();
    method.releaseConnection();

    // Create response data object
    ResponseData data = new ResponseData();
    data.body = responseBody.trim();
    data.statusCode = statusCode;
    if (statusCode == HttpStatus.SC_OK) {
        // Parse the JSON response
        data.json = parseJsonTextToObject(responseBody);
    }

    // Get the expected result
    method = new GetMethod(getStatus200ResultUrl(pType, pTestNum));
    data.expectedStatusCode = HttpStatus.SC_OK;

    // Execute the GET request, capturing response status
    statusCode = client.executeMethod(method);

    if (statusCode == HttpStatus.SC_NOT_FOUND) {
        // Test result wasn't found - we must be expecting an error for this test
        method.releaseConnection();
        method = new GetMethod(getStatus500ResultUrl(pType, pTestNum));
        statusCode = client.executeMethod(method);
        data.expectedStatusCode = HttpStatus.SC_INTERNAL_SERVER_ERROR;
    }

    responseBody = method.getResponseBodyAsString().trim();
    method.releaseConnection();

    // Parse the expected data   
    if (data.expectedStatusCode == HttpStatus.SC_OK) {
        // Parse body into JSON object
        data.expectedJson = parseJsonTextToObject(responseBody);
    } else {
        // Exception is expected, set the expected key
        data.expectedMsgKey = responseBody.trim();
    }

    return data;
}

From source file:eu.alefzero.owncloud.authenticator.AuthenticationRunnable.java

@Override
public void run() {
    Uri uri;//from   w ww .  j  a  v a  2  s. c o  m
    uri = Uri.parse(mUrl.toString());
    int login_result = WebdavClient.tryToLogin(uri, mUsername, mPassword);
    switch (login_result) {
    case HttpStatus.SC_OK:
        postResult(true, uri.toString());
        break;
    case HttpStatus.SC_UNAUTHORIZED:
        postResult(false, "Invalid login or/and password");
        break;
    case HttpStatus.SC_NOT_FOUND:
        postResult(false, "Wrong path given");
        break;
    default:
        postResult(false, "Internal server error, code: " + login_result);
    }
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.FriendController.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    try {/*from   ww  w. j  a  v  a 2 s.  c  o m*/
        if (fileContentsAreAcceptable()) {
            writeWarningToTheLog(req);
            loginAsRootUser(req);
            redirectToHomePage(resp);
        }
    } catch (Exception e) {
        log.debug("problem: " + e.getMessage());
        resp.sendError(HttpStatus.SC_NOT_FOUND);
    }
}

From source file:com.owncloud.android.authenticator.AuthenticationRunnable.java

@Override
public void run() {
    Uri uri;/*from  w  w  w .  j av  a  2  s .c o m*/
    uri = Uri.parse(mUrl.toString());
    WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(uri, mUsername, mPassword, mContext);
    int login_result = wdc.tryToLogin();
    switch (login_result) {
    case HttpStatus.SC_OK:
        postResult(true, uri.toString());
        break;
    case HttpStatus.SC_UNAUTHORIZED:
        postResult(false, mContext.getString(R.string.auth_unauthorized));
        break;
    case HttpStatus.SC_NOT_FOUND:
        postResult(false, mContext.getString(R.string.auth_not_found));
        break;
    default:
        postResult(false, String.format(mContext.getString(R.string.auth_internal), login_result));
    }
}

From source file:com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult.java

public void notFound(Localizable message, HealthStateType healthStateType) {
    this.message = message;
    this.healthStateType = healthStateType;
    httpCode = HttpStatus.SC_NOT_FOUND;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.rss.InformaRSSAction.java

@Override
public ActionForward execute(final ActionMapping mapping, final ActionForm form,
        final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String encoding = System.getProperty("file.encoding", Charset.defaultCharset().name());
    final ChannelIF channel = getRSSChannel(request);
    if (channel != null) {
        response.setContentType("text/xml; charset=" + encoding);
        final PrintWriter writer = response.getWriter();
        final ChannelExporterIF exporter = new RSS_2_0_Exporter(writer, encoding);
        exporter.write(channel);//from  ww  w.ja va  2s . co m
        response.flushBuffer();
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_NOT_FOUND));
        response.getWriter().close();
    }
    return null;
}

From source file:com.owncloud.android.oc_framework.operations.remote.RemoveRemoteFileOperation.java

/**
 * Performs the rename operation./* w w w. j  a v a2s . com*/
 * 
 * @param client   Client object to communicate with the remote ownCloud server.
 */
@Override
protected RemoteOperationResult run(WebdavClient client) {
    RemoteOperationResult result = null;
    DeleteMethod delete = null;

    try {
        delete = new DeleteMethod(client.getBaseUri() + WebdavUtils.encodePath(mRemotePath));
        int status = client.executeMethod(delete, REMOVE_READ_TIMEOUT, REMOVE_CONNECTION_TIMEOUT);

        delete.getResponseBodyAsString(); // exhaust the response, although not interesting
        result = new RemoteOperationResult((delete.succeeded() || status == HttpStatus.SC_NOT_FOUND), status,
                delete.getResponseHeaders());
        Log.i(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage());

    } catch (Exception e) {
        result = new RemoteOperationResult(e);
        Log.e(TAG, "Remove " + mRemotePath + ": " + result.getLogMessage(), e);

    } finally {
        if (delete != null)
            delete.releaseConnection();
    }

    return result;
}

From source file:jetbrains.buildServer.staticUIExtensions.web.StaticContentController.java

@Override
protected ModelAndView doHandle(@NotNull final HttpServletRequest request,
        @NotNull final HttpServletResponse response) throws Exception {

    final String token = request.getParameter(myPaths.getTokenParameter());
    if (!myConfig.getAccessToken().equals(token)) {
        response.sendError(HttpStatus.SC_NOT_FOUND, "Path not found. Invalid access token");
        return null;
    }// w w  w .j  a  v  a  2s . c om

    if (request.getParameter(myPaths.getEmptyContentParameter()) != null) {
        return null;
    }

    //TODO: allow directories, may use Util from TeamCity for that
    final String file = request.getParameter(myPaths.getIncludeFileParameter());
    if (StringUtil.isEmptyOrSpaces(file) || file.contains("/") || file.contains("\\") || file.contains("..")) {
        final String message = "Failed to open file to include by invalid path: "
                + (file == null ? "no file specified" : file) + ".";
        LOG.warn(message);
        return sendError(request, response, message);
    }

    final File includeFile = myConfig.mapIncludeFilePath(file);
    if (includeFile == null || !includeFile.isFile()) {
        LOG.warn("Failed to open file to include: " + (includeFile != null ? includeFile : file) + ".");
        return sendError(request, response, "Path not found: " + file);
    }

    final char[] data;
    try {
        data = myCache.getContent(includeFile);
    } catch (IOException e) {
        LOG.warn("Failed to open file to include: " + includeFile + ". " + e.getMessage(), e);
        return sendError(request, response, "Failed to open file: " + includeFile.getName());
    }

    response.getWriter().write(data);
    return null;
}

From source file:cn.vlabs.duckling.vwb.ui.action.ViewPageAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {/* ww  w . ja v a  2  s  .com*/
    DPage page = (DPage) getSavedViewPort(request);
    VWBContext context = VWBContext.createContext(request, DPageCommand.VIEW, page);
    if (context.hasAccess(response)) {
        int version = getRequestVersion(request);
        ActionForward forward = null;
        if (VWBContext.LATEST_VERSION != version && page.getVersion() != version) {
            DPageService dpageService = VWBContext.getContainer().getDpageService();
            DPage versionPage = dpageService.getDpageVersionContent(context.getSite().getId(),
                    page.getResourceId(), version);
            if (versionPage != null) {
                context.targetCommand(versionPage);
                forward = layout(context,
                        new DPageRendable(versionPage.getResourceId(), versionPage.getVersion()));
            } else {
                log.warn(String.format("Page's conent id=%d, version=%d is not found.", page.getResourceId(),
                        version));
                try {
                    response.sendError(HttpStatus.SC_NOT_FOUND);
                } catch (IOException e) {
                    log.error("forward to not found page failed.", e);
                }
                return null;
            }
        } else {
            forward = layout(context);
        }
        return forward;
    }
    return null;
}