All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.lightbody.bmp.proxy.jetty.http.handler.RootNotFoundHandler Maven / Gradle / Ivy

// ========================================================================
// $Id: RootNotFoundHandler.java,v 1.11 2005/08/13 00:01:26 gregwilkins Exp $
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at 
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========================================================================

package net.lightbody.bmp.proxy.jetty.http.handler;

import net.lightbody.bmp.proxy.jetty.http.HttpContext;
import net.lightbody.bmp.proxy.jetty.http.HttpFields;
import net.lightbody.bmp.proxy.jetty.http.HttpRequest;
import net.lightbody.bmp.proxy.jetty.http.HttpResponse;
import net.lightbody.bmp.proxy.jetty.util.ByteArrayISO8859Writer;
import net.lightbody.bmp.proxy.jetty.util.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.OutputStream;

/* ------------------------------------------------------------ */

/**
 * @author Greg Wilkins (gregw)
 * @version $Id: RootNotFoundHandler.java,v 1.11 2005/08/13 00:01:26 gregwilkins Exp $
 */
public class RootNotFoundHandler extends NotFoundHandler {
    private final Logger log = LoggerFactory.getLogger(RootNotFoundHandler.class);

    public void handle(String pathInContext, String pathParams, HttpRequest request, HttpResponse response) throws IOException {
        log.debug("Root Not Found");
        String method = request.getMethod();

        if (!method.equals(HttpRequest.__GET) || !request.getPath().equals("/")) {
            // don't bother with fancy format.
            super.handle(pathInContext, pathParams, request, response);
            return;
        }

        response.setStatus(404);
        request.setHandled(true);
        response.setReason("Not Found");
        response.setContentType(HttpFields.__TextHtml);

        ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(1500);

        String uri = request.getPath();
        uri = StringUtil.replace(uri, "<", "<");
        uri = StringUtil.replace(uri, ">", ">");

        writer.write("\n\nError 404 - Not Found");
        writer.write("\n\n

Error 404 - Not Found.

\n"); writer.write("No context on this server matched or handled this request.
"); writer.write("Contexts known to this server are: The links above may not work if a virtual host is configured"); for (int i = 0; i < 10; i++) { writer.write("\n"); } writer.write("\n\n\n"); writer.flush(); response.setContentLength(writer.size()); OutputStream out = response.getOutputStream(); writer.writeTo(out); out.close(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy