Example usage for javax.servlet.http HttpServletResponse SC_NOT_IMPLEMENTED

List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_IMPLEMENTED

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_NOT_IMPLEMENTED.

Prototype

int SC_NOT_IMPLEMENTED

To view the source code for javax.servlet.http HttpServletResponse SC_NOT_IMPLEMENTED.

Click Source Link

Document

Status code (501) indicating the HTTP server does not support the functionality needed to fulfill the request.

Usage

From source file:org.eclipse.orion.server.cf.servlets.AbstractRESTHandler.java

/**
 * Handles an idempotent PUT request. Note this method is meant to be overridden in descendant classes.
 * @param request The PUT request being handled.
 * @param response The response associated with the request.
 * @param path Path suffix required to handle the request.
 * @return A {@link JazzJob} which returns the PUT request result on completion. 
 *//* w  w  w .  j a  v  a  2 s .c o  m*/
protected CFJob handlePut(T resource, final HttpServletRequest request, final HttpServletResponse response,
        final String path) {
    return new CFJob(request, false) {
        @Override
        protected IStatus performJob() {
            String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_IMPLEMENTED, msg, null);
        }
    };
}

From source file:test.StreamServlet.java

/**
 * Handle stream request via servlet interface.
 * //from ww w  .ja v  a2 s. com
 * @param request
 *            HTTP request
 * @param response
 *            HTTP responce
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Request req = null;
    try {
        req = createFromHttpServletRequest(request);
        log.info("doGet [" + request.getRemoteAddr() + "]: request=" + req);

        // debugging info
        if (log.isDebugEnabled()) {
            logHeaders(request);
        }

        // TODO hack around ugly ogg vorbis mime-type
        String outputType = req.getOutputType();
        if (outputType.equals("audio/ogg-vorbis")) {
            outputType = "application/x-ogg";
        }

        // headers
        response.setContentType(outputType);
        if (outputType.startsWith("audio/")) {
            addStreamHeaders(req, response);
        }

        // get stream
        long len = req.getLength();
        InputStream in = req.getStream();

        // winamp vorbis hack, winamp can't handle ogg
        // streaming with unknown length..
        if (req.getOutputType().equals("audio/ogg-vorbis") && len == -1L) {
            log.debug("unknown length vorbis");
            String t = request.getHeader("user-agent");
            if (t != null && t.toLowerCase().indexOf("winamp") != -1) {
                log.debug("hack for winamp");
                response.setContentLength(estimatedLength(req));
            }
        }

        // write data
        try {
            PartialContentHandler.process(request, response, in, len);
        } finally {
            in.close();
        }
    } catch (ScillaNoOutputException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    } catch (ScillaConversionFailedException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    } catch (ScillaOutputIOException ex) {
        log.debug("doGet! ", ex);
        /* probably and broken pipe */
    } catch (ScillaNoInputException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage());
    } catch (ScillaInputIOException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    } catch (ScillaNoConverterException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, ex.getMessage());
    } catch (ScillaIllegalRequestException ex) {
        log.info("doGet! ", ex);
        response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage());
    } catch (ScillaException ex) {
        log.warn("doGet! ", ex);
        throw new ServletException("Scilla FAILED!", ex);
    } catch (Exception ex) {
        log.warn("doGet! ", ex);
        throw new ServletException(ex);
    }
}

From source file:com.homesnap.webserver.AbstractRestApi.java

protected JSONObject deleteRequestJSONObject(String urn, int returnCodeExpected) {
    Client client = Client.create();//from  w  ww.  jav a  2 s.  c o m
    WebResource webResource = client.resource("http://" + server + ":" + port + urn);
    ClientResponse response = webResource.accept("application/json").delete(ClientResponse.class);
    Assert.assertEquals(returnCodeExpected, response.getStatus());
    if (returnCodeExpected == HttpServletResponse.SC_NO_CONTENT
            || returnCodeExpected == HttpServletResponse.SC_NOT_ACCEPTABLE
            || returnCodeExpected == HttpServletResponse.SC_NOT_IMPLEMENTED) {
        return null;
    }

    String json = null;
    try {
        json = response.getEntity(String.class);
        return JSonTools.fromJson(json);
    } catch (JSONException e) {
        e.printStackTrace();
        Assert.fail("Problem with JSON [" + json + "] :" + e.getMessage());
    }
    return null;
}

From source file:org.alfresco.repo.webdav.WebDAVServlet.java

/**
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 *//*from   w ww.j  a  v  a 2 s . c  om*/
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!initParams.getEnabled()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    long startTime = 0;
    if (logger.isTraceEnabled()) {
        startTime = System.currentTimeMillis();
    }

    FileFilterMode.setClient(Client.webdav);

    try {
        // Create the appropriate WebDAV method for the request and execute it
        final WebDAVMethod method = createMethod(request, response);

        if (method == null) {
            if (logger.isErrorEnabled())
                logger.error("WebDAV method not implemented - " + request.getMethod());

            // Return an error status

            response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
            return;
        } else if (method.getRootNodeRef() == null) {
            if (logger.isDebugEnabled()) {
                logger.debug("No root node for request [" + request.getMethod() + " " + request.getRequestURI()
                        + "]");
            }

            // Return an error status
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        // Execute the WebDAV request, which must take care of its own transaction
        method.execute();
    } catch (Throwable e) {
        ExceptionHandler exHandler = new ExceptionHandler(e, request, response);
        exHandler.handle();
    } finally {
        if (logger.isTraceEnabled()) {
            logger.trace(request.getMethod() + " took " + (System.currentTimeMillis() - startTime)
                    + "ms to execute [" + request.getRequestURI() + "]");
        }

        FileFilterMode.clearClient();
    }
}

From source file:org.purl.sword.server.DepositServlet.java

/**
 * Process the Get request. This will return an unimplemented response.
 *///from  w w w. j  a v a2 s.  c o  m
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Send a '501 Not Implemented'
    response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
}

From source file:org.jahia.bin.Find.java

private Query getQuery(HttpServletRequest request, HttpServletResponse response, String workspace,
        Locale locale) throws IOException, RepositoryException {

    QueryManager qm = JCRSessionFactory.getInstance().getCurrentUserSession(workspace, locale).getWorkspace()
            .getQueryManager();/*w w  w .  j  a v  a 2 s  .c  o  m*/
    if (qm == null) {
        response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
        return null;
    }

    String query = request.getParameter("query");
    if (StringUtils.isEmpty(query)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                "Mandatory parameter 'query' is not found in the request");
        return null;
    }

    // now let's parse the query to see if it references any other request parameters, and replace the reference with
    // the actual value.

    query = expandRequestMarkers(request, query, true,
            StringUtils.defaultIfEmpty(request.getParameter("language"), Query.JCR_SQL2), false);
    logger.debug("Using expanded query=[{}]", query);

    Query q = qm.createQuery(query,
            StringUtils.defaultIfEmpty(request.getParameter("language"), Query.JCR_SQL2));

    int limit = getInt("limit", defaultLimit, request);
    if (limit <= 0 || limit > hardLimit) {
        limit = hardLimit;
    }

    int offset = getInt("offset", 0, request);

    if (limit > 0) {
        q.setLimit(limit);
    }
    if (offset > 0) {
        q.setOffset(offset);
    }

    return q;
}

From source file:org.efaps.webdav4vfs.WebDAVServlet.java

@Override()
public void service(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    //    String auth = request.getHeader("Authorization");
    //    String login = "", password = "";
    ///*  w ww  . j a  v  a 2s .  com*/
    //    if (auth != null) {
    //      auth = new String(Base64.decodeBase64(auth.substring(auth.indexOf(' ') + 1).getBytes()));
    //      login = auth.substring(0, auth.indexOf(':'));
    //      password = auth.substring(auth.indexOf(':') + 1);
    //    }
    //
    //    AWSCredentials credentials = AWSCredentials.load(password,  ))
    //    if (user == null) {
    //      response.setHeader("WWW-Authenticate", "Basic realm=\"Moxo\"");
    //      response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    //      return;
    //    }

    // show we are doing the litmus test
    String litmusTest = request.getHeader("X-Litmus");
    if (null == litmusTest) {
        litmusTest = request.getHeader("X-Litmus-Second");
    }
    if (litmusTest != null) {
        LOG.info(String.format("WebDAV Litmus Test: %s", litmusTest));
    }

    String method = request.getMethod();
    LOG.debug(String.format(">> %s %s", request.getMethod(), request.getPathInfo()));
    if (handlers.containsKey(method)) {
        handlers.get(method).service(request, response);
    } else {
        response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
    }
    LOG.debug(
            String.format("<< %s (%s)", request.getMethod(), response.toString().replaceAll("[\\r\\n]+", "")));
}

From source file:com.kurento.kmf.content.internal.base.AbstractContentHandlerServlet.java

@Override
protected final void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {

    if (useControlProtocol) {
        ServletUtils.sendHttpError(req, resp, HttpServletResponse.SC_NOT_IMPLEMENTED,
                "Only POST request are supported for this service. You can enable GET requests "
                        + " by setting useControlProtocol to false on the appropriate handler annotation");
        return;/*  w  w w .j  a  v a  2 s. co  m*/
    }

    getLogger().info("GET request received: " + req.getRequestURI());

    if (!req.isAsyncSupported()) {
        // Async context could not be created. It is not necessary to
        // complete it. Just send error message to
        ServletUtils.sendHttpError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "AsyncContext could not be started. The application should add \"asyncSupported = true\" in all "
                        + this.getClass().getName() + " instances and in all filters in the associated chain");
        return;
    }
    if (handler == null) {
        ServletUtils.sendHttpError(req, resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                handler.getClass().getSimpleName() + " is null. This error means that you "
                        + "need to provide a valid implementation of interface "
                        + handler.getClass().getSimpleName());
        return;
    }

    String contentId = req.getPathInfo();
    if (contentId != null) {
        contentId = contentId.substring(1);
    }

    AsyncContext asyncCtx = req.startAsync();

    // Add listener for managing error conditions
    asyncCtx.addListener(new ContentAsyncListener());

    doRequest4SimpleHttpProtocol(asyncCtx, contentId, resp);

}

From source file:org.purl.sword.server.ServiceDocumentServlet.java

/**
 * Process the post request. This will return an unimplemented response.
 *///from  w  w  w . j a  va 2  s .c  om
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Send a '501 Not Implemented'
    response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
}

From source file:org.eclipse.orion.server.cf.servlets.AbstractRESTHandler.java

/**
 * Handles a POST request. Note this method is meant to be overridden in descendant classes.
 * The POST request is not idempotent as PUT, although it may handle similar operations.
 * @param request The POST request being handled.
 * @param response The response associated with the request.
 * @param path Path suffix required to handle the request.
 * @return A {@link JazzJob} which returns the POST request result on completion.
 *///from   w ww  .  j  a va 2 s. com
protected CFJob handlePost(final T resource, final HttpServletRequest request,
        final HttpServletResponse response, final String path) {
    return new CFJob(request, false) {
        @Override
        protected IStatus performJob() {
            String msg = NLS.bind("Failed to handle request for {0}", path); //$NON-NLS-1$
            return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_IMPLEMENTED, msg, null);
        }
    };
}