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:opendap.threddsHandler.StaticCatalogDispatch.java

public void sendThreddsCatalogResponse(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    String catalogKey = getCatalogKeyFromRelativeUrl(ReqInfo.getLocalUrl(request));
    String requestSuffix = ReqInfo.getRequestSuffix(request);
    String query = request.getQueryString();

    Request orq = new Request(null, request);

    if (redirectRequest(request, response))
        return;//from   w w  w  .  j a  v a  2 s  . c om

    // Are we browsing a remote catalog? a remote dataset?
    if (query != null && query.startsWith("browseCatalog=")) {
        // browseRemoteCatalog(response, query);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else if (query != null && query.startsWith("browseDataset=")) {
        // browseRemoteDataset(response, query);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }

    // Is the request for a presentation view (HTML version) of the catalog?
    else if (requestSuffix != null && requestSuffix.equals("html")) {

        if (query != null) {
            if (query.startsWith("dataset=")) {
                sendDatasetHtmlPage(orq, response, catalogKey, query);
            } else {
                response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED,
                        "Cannot process query: " + Scrub.urlContent(query));
            }

        } else {
            sendCatalogHTML(orq, response, catalogKey);
        }

    } else { // Send the the raw catalog XML.
        sendCatalogXML(orq, response, catalogKey);
    }

}

From source file:de.mpg.escidoc.services.pidcache.web.MainServlet.java

protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "PUT method not supported for this service");
}

From source file:ubiksimdist.UbikSimServlet.java

/**
 * Trata el valor dado para el simulador y genera una respuesta
 *
 * @param response, variable servlet para respuesta
 * @param output, salida dada por el simulador para imprimir (json, o web).
 * @param parameterName, nombre del parmetro: position o control
 * @param parameterValue, valor dado en la URL
 * @param showWeb, salida como WEB o como JSON
 *///from ww w.  j  a va 2  s .  co  m
private void treatParameterOutput(HttpServletResponse response, String output, String parameterName,
        String parameterValue, boolean showWeb) {
    if (output == null) {
        try {
            response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED,
                    "No " + parameterName + " action for: " + parameterValue);
        } catch (IOException ex) {
            Logger.getLogger(UbikSimServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    } else {
        if (!showWeb) {
            try {
                PrintWriter out = response.getWriter();
                response.setContentType("application/json");
                out.println(output);
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else {
            printWeb(response, output);
        }

    }

}

From source file:com.tomtom.speedtools.rest.GeneralExceptionMapper.java

/**
 * Static function to map an exception to a proper (asynchronous) response.
 *
 * @param log       Logger to log information, warning or error message to.
 * @param exception Exception to be processed.
 * @return Status response.// w  w  w .j ava2s  .  co m
 */
@SuppressWarnings("deprecation")
@Nonnull
public static Response toResponse(@Nonnull final Logger log, @Nonnull final Throwable exception) {
    assert log != null;
    assert exception != null;

    //noinspection SuspiciousMethodCalls
    final Tuple<Boolean, Status> tuple = customExceptionsMap.get(exception.getClass());
    if (tuple != null) {
        if (tuple.getValue1()) {

            // Internal server error.
            return toResponseApiException(Level.ERROR, log, exception);
        } else {

            // Bad API call.
            return toResponseBadApiCall(log, tuple.getValue2(), exception);
        }
    }
    /**
     * Don't always throw an Error. This exception may be caused by asking for a wrong URL.
     * We need to catch those properly and log them as Informational, or Warnings, at most.
     *
     * Exceptions as a result of the way the call was issued (external cause, usually
     * a bad API call). These are never errors, just informational.
     */
    if (exception instanceof ApiBadRequestException) {
        return toResponseApiValidationError(log, (ApiBadRequestException) exception);
    }

    /**
     * Api exceptions other than bad request.
     */
    else if (exception instanceof ApiForbiddenException) {
        return toResponseBadApiCall(log, Status.FORBIDDEN, exception);
    } else if (exception instanceof ApiInternalException) {
        return toResponseBadApiCall(log, Status.INTERNAL_SERVER_ERROR, exception);
    } else if (exception instanceof ApiNotFoundException) {
        return toResponseBadApiCall(log, Status.NOT_FOUND, exception);
    } else if (exception instanceof ApiNotImplementedException) {
        return toResponseBadApiCall(log, HttpServletResponse.SC_NOT_IMPLEMENTED, exception);
    } else if (exception instanceof ApiConflictException) {
        return toResponseBadApiCall(log, Status.CONFLICT, exception);
    } else if (exception instanceof ApiUnauthorizedException) {
        return toResponseBadApiCall(log, Status.UNAUTHORIZED, exception);
    }

    /**
     * Rest-easy exceptions (deprecated).
     */
    else if (exception instanceof org.jboss.resteasy.spi.BadRequestException) {
        return toResponseBadApiCall(log, Status.BAD_REQUEST, exception);
    } else if (exception instanceof org.jboss.resteasy.spi.NotFoundException) {
        return toResponseBadApiCall(log, Status.NOT_FOUND, exception);
    } else if (exception instanceof org.jboss.resteasy.spi.NotAcceptableException) {
        return toResponseBadApiCall(log, Status.NOT_ACCEPTABLE, exception);
    } else if (exception instanceof org.jboss.resteasy.spi.MethodNotAllowedException) {
        return toResponseBadApiCall(log, Status.FORBIDDEN, exception);
    } else if (exception instanceof org.jboss.resteasy.spi.UnauthorizedException) {
        return toResponseBadApiCall(log, Status.UNAUTHORIZED, exception);
    } else if (exception instanceof org.jboss.resteasy.spi.UnsupportedMediaTypeException) {
        return toResponseBadApiCall(log, Status.UNSUPPORTED_MEDIA_TYPE, exception);
    }

    /**
     * Javax exceptions.
     */
    else if (exception instanceof javax.ws.rs.BadRequestException) {
        return toResponseBadApiCall(log, Status.BAD_REQUEST, exception);
    } else if (exception instanceof javax.ws.rs.NotFoundException) {
        return toResponseBadApiCall(log, Status.NOT_FOUND, exception);
    } else if (exception instanceof javax.ws.rs.NotAcceptableException) {
        return toResponseBadApiCall(log, Status.NOT_ACCEPTABLE, exception);
    } else if ((exception instanceof javax.ws.rs.NotAllowedException)
            || (exception instanceof javax.ws.rs.ForbiddenException)) {
        return toResponseBadApiCall(log, Status.FORBIDDEN, exception);
    } else if (exception instanceof javax.ws.rs.NotAuthorizedException) {
        return toResponseBadApiCall(log, Status.UNAUTHORIZED, exception);
    } else if (exception instanceof javax.ws.rs.NotSupportedException) {
        return toResponseBadApiCall(log, Status.UNSUPPORTED_MEDIA_TYPE, exception);
    }

    /**
     * System specific exception, such as "entity not found". These are not
     * always errors, either, but some are. Inspect on case-by-case!
     */
    else if (exception instanceof AskTimeoutException) {
        return toResponseApiException(Level.WARN, log, exception);
    } else if (exception instanceof BSONException) {
        return toResponseApiException(Level.ERROR, log, exception);
    }

    /**
     * Jackson unmarshall exceptions typically thrown from a {@link XmlAdapter} wrap a more specific exception.
     */
    else //noinspection ObjectEquality
    if ((exception instanceof JsonMappingException) && (exception.getCause() != null)
            && (exception.getCause() != exception)) {

        /**
         * Call toResponse again, with the cause of the exception.
         */
        //noinspection TailRecursion
        return toResponse(log, exception.getCause());
    }

    /**
     * Some other system failure.
     */
    else {
        return toResponseApiException(Level.ERROR, log, exception);
    }
}

From source file:edu.northwestern.bioinformatics.studycalendar.security.internal.ApiAuthenticationFilter.java

private boolean verifyCredentials(Authentication request, HttpServletResponse servletResponse,
        String schemeName) throws IOException {
    if (request != null) {
        try {//w w  w .  j  av  a  2 s .  co  m
            Authentication auth = getAuthenticationSystem().authenticationManager().authenticate(request);
            setAuthentic(auth);
        } catch (AuthenticationException e) {
            log.debug("Failure encountered when processing authentication for API; failure deferred to guard.",
                    e);
        }
        return true;
    } else {
        servletResponse.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, String.format(
                "%s credentials are not supported with the configured authentication system", schemeName));
        return false;
    }
}

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

protected JSONObject putRequestJSONObject(String urn, String body, int returnCodeExpected) {
    Client client = Client.create();/*  www . j av  a 2  s  . com*/
    WebResource webResource = client.resource("http://" + server + ":" + port + urn);

    String json = null;
    try {
        ClientResponse response = webResource.accept("application/json").put(ClientResponse.class, body);
        Assert.assertEquals(returnCodeExpected, response.getStatus());
        if (returnCodeExpected == HttpServletResponse.SC_NOT_IMPLEMENTED
                || returnCodeExpected == HttpServletResponse.SC_NOT_ACCEPTABLE
                || returnCodeExpected == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            return null;
        }
        json = response.getEntity(String.class);
        return JSonTools.fromJson(json);
    } catch (JSONException e) {
        e.printStackTrace();
        Assert.fail("Problem with JSON [" + json + "] :" + e.getMessage());
    }
    Assert.fail("Problem when call [" + urn + "].");
    return null;
}

From source file:com.flexive.war.servlet.TestRunnerServlet.java

/**
 * {@inheritDoc}/*from   ww  w  .j a  v a2 s . c  om*/
 */
@Override
public void service(ServletRequest servletRequest, ServletResponse servletResponse)
        throws ServletException, IOException {
    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    String cmd = URLDecoder.decode(request.getRequestURI(), "UTF8");
    if (cmd != null && cmd.lastIndexOf('/') > 0)
        cmd = cmd.substring(cmd.lastIndexOf('/') + 1);
    if (CMD_AVAILABLE.equals(cmd)) {
        boolean available = false;
        try {
            Class.forName("com.flexive.testRunner.FxTestRunner");
            available = true;
        } catch (Exception e) {
            LOG.error(e);
        }
        response.setStatus(available ? HttpServletResponse.SC_OK : HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        response.getWriter().write(String.valueOf(available));
    } else if (CMD_RUN.equals(cmd)) {
        String outputPath = request.getParameter(PARAM_OUTPUTPATH);
        try {
            Class runner = Class.forName("com.flexive.testRunner.FxTestRunner");
            Method check = runner.getMethod("checkTestConditions", String.class, Boolean.class);
            Boolean status = false;
            if (!StringUtils.isEmpty(outputPath))
                status = (Boolean) check.invoke(null, String.valueOf(outputPath), Boolean.FALSE);
            if (!status) {
                response.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
                response.getWriter()
                        .write("Invalid output path, assertations not enabled or test division not definied!");
                return;
            }
            Method exec = runner.getMethod("runTests", String.class);
            exec.invoke(null, outputPath);
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().write("Tests started.");
        } catch (Exception e) {
            LOG.error(e);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            response.getWriter().write("Error: " + e.getMessage());
        }
    } else if (CMD_RUNNING.equals(cmd)) {
        try {
            Class runner = Class.forName("com.flexive.testRunner.FxTestRunner");
            Method check = runner.getMethod("isTestInProgress");
            Boolean status = (Boolean) check.invoke(null);
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().write(String.valueOf(status));
        } catch (Exception e) {
            LOG.error(e);
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            response.getWriter().write("Error: " + e.getMessage());
        }
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
        response.getWriter().write("Unknown command: " + cmd);
    }
}

From source file:bbdn.lti2.LTI2Servlet.java

@SuppressWarnings("unused")
protected void doRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    System.out.println("getServiceURL=" + getServiceURL(request));

    String ipAddress = request.getRemoteAddr();
    System.out.println("LTI Service request from IP=" + ipAddress);

    String rpi = request.getPathInfo();
    String uri = request.getRequestURI();
    String[] parts = uri.split("/");
    if (parts.length < 5) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        doErrorJSON(request, response, null, "Incorrect url format", null);
        return;/*from   w  w w.j  a v a  2 s .  co  m*/
    }
    String controller = parts[4];
    if ("register".equals(controller)) {
        doRegister(request, response);
        return;
    } else if ("launch".equals(controller)) {
        doLaunch(request, response);
        return;
    } else if (SVC_tc_profile.equals(controller) && parts.length == 6) {
        String profile_id = parts[5];
        getToolConsumerProfile(request, response, profile_id);
        return;
    } else if (SVC_tc_registration.equals(controller) && parts.length == 6) {
        String profile_id = parts[5];
        registerToolProviderProfile(request, response, profile_id);
        return;
    } else if (SVC_Result.equals(controller) && parts.length == 6) {
        String sourcedid = parts[5];
        handleResultRequest(request, response, sourcedid);
        return;
    } else if (SVC_Settings.equals(controller) && parts.length >= 7) {
        handleSettingsRequest(request, response, parts);
        return;
    }

    IMSJSONRequest jsonRequest = new IMSJSONRequest(request);
    if (jsonRequest.valid) {
        System.out.println(jsonRequest.getPostBody());
    }

    response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
    M_log.warn("Unknown request=" + uri);
    doErrorJSON(request, response, null, "Unknown request=" + uri, null);
}

From source file:org.apache.shindig.social.opensocial.hibernate.services.AppDataServiceImpl.java

public Future<Void> updatePersonData(UserId userId, GroupId groupId, String appId, Set<String> fields,
        Map<String, String> values, SecurityToken token) throws ProtocolException {
    if (appId == null) {
        appId = token.getAppId();/*ww w .  j  a  v  a2  s .  c o  m*/
    }
    Type type = groupId.getType();
    if (type.equals(Type.self)) {
        if (userId.getUserId(token).equals(token.getViewerId())) {
            Set<String> keys = fields;
            if (keys.isEmpty()) {
                keys = values.keySet();
            }
            for (String key : keys) {
                Object value = values.get(key);
                setAppData(userId.getUserId(token), key, String.valueOf(value), appId);
            }
            return ImmediateFuture.newInstance(null);
        } else {
            throw new ProtocolException(HttpServletResponse.SC_FORBIDDEN,
                    "The data of the user who is not VIEWER cannot be updated.");
        }
    } else {
        throw new ProtocolException(HttpServletResponse.SC_NOT_IMPLEMENTED,
                "We don't support updating data in batches yet.");
    }
}

From source file:com.portfolio.security.LTIv2Servlet.java

@SuppressWarnings("unused")
protected void doRequest(HttpServletRequest request, HttpServletResponse response, HttpSession session,
        ServletContext application, String toolProxyPath, StringBuffer outTrace)
        throws ServletException, IOException {

    outTraceFormattedMessage(outTrace, "getServiceURL=" + getServiceURL(request));

    String ipAddress = request.getRemoteAddr();
    outTraceFormattedMessage(outTrace, "LTI Service request from IP=" + ipAddress);

    String rpi = request.getPathInfo();
    String uri = request.getRequestURI();
    String[] parts = uri.split("/");
    if (parts.length < 4) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        doErrorJSON(request, response, null, "Incorrect url format", null);
        return;//  w w  w.  j av a  2  s.  c  o m
    }

    Map<String, Object> payload = LTIServletUtils.processRequest(request, outTrace);
    String url = getServiceURL(request);

    String controller = parts[3];
    if ("register".equals(controller)) {
        payload.put("base_url", url);
        payload.put("launch_url", url + "register");
        doRegister(response, payload, application, toolProxyPath, outTrace);
        return;
    } else if ("launch".equals(controller)) {
        doLaunch(request, response, session, payload, application, outTrace);
        return;
    }

    // Check if json request if valid
    IMSJSONRequest jsonRequest = new IMSJSONRequest(request);
    if (jsonRequest.valid) {
        outTraceFormattedMessage(outTrace, jsonRequest.getPostBody());
    }

    response.setStatus(HttpServletResponse.SC_NOT_IMPLEMENTED);
    M_log.warn("Unknown request=" + uri);
    doErrorJSON(request, response, null, "Unknown request=" + uri, null);
}