Example usage for javax.servlet.http HttpServletResponse SC_NOT_ACCEPTABLE

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

Introduction

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

Prototype

int SC_NOT_ACCEPTABLE

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

Click Source Link

Document

Status code (406) indicating that the resource identified by the request is only capable of generating response entities which have content characteristics not acceptable according to the accept headers sent in the request.

Usage

From source file:com.belajar_filter.config.FilterBeanConfig.java

public static Filter myFilter() {
    Filter filter = new Filter() {

        private ServletContext context;

        @Override/* w w  w.  j  a va2s .  c o m*/
        public void init(FilterConfig filterConfig) throws ServletException {
            log.debug("initiate general filter config");
            this.context = filterConfig.getServletContext();
            this.context.log("AuthenticationFilter initialized");
        }

        @Override
        public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc)
                throws IOException, ServletException {
            log.debug("execute do filter ... ");
            HttpServletResponse response = (HttpServletResponse) res;
            HttpServletRequest request = (HttpServletRequest) req;

            String getParam = request.getParameter("name");
            String urlRequest = request.getRequestURI();
            log.debug("intercept url request : " + urlRequest);
            log.debug("intercept param : " + getParam);

            if ("aji".equals(getParam)) {
                log.debug("is aji");
                fc.doFilter(req, res);
            } else {
                log.debug("is not aji");
                response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
            }

        }

        @Override
        public void destroy() {

        }
    };

    return filter;
}

From source file:org.wso2.carbon.ui.transports.FileDownloadServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
}

From source file:byps.http.HWriteResponseHelper.java

public void writeResponse(ByteBuffer obuf, Throwable e, HttpServletResponse resp, boolean isAsync)
        throws IOException {
    if (log.isDebugEnabled())
        log.debug("writeResponse(" + obuf + ", exception=" + e + ", resp=" + resp);

    if (resp == null) {
        if (log.isDebugEnabled())
            log.debug(")writeResponse timeout");
        return; // timeout
    }/*from  w  w  w  .  ja  v a2 s. c  o  m*/

    if (listener != null) {
        if (log.isDebugEnabled())
            log.debug("call onBefore-listener");
        if (listener.onBeforeWriteHttpResponse(obuf, e, resp, isAsync)) {
            if (log.isDebugEnabled())
                log.debug(")writeResponse, onBefore-listener has written the response.");
        }
    }

    if (e != null) {

        int status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        if (e instanceof BException) {
            BException bex = (BException) e;
            if (bex.code == BExceptionC.CANCELLED) {
                status = HttpServletResponse.SC_NOT_ACCEPTABLE;
            } else if (bex.code == BExceptionC.RESEND_LONG_POLL) {
                status = HttpServletResponse.SC_NO_CONTENT;
            }
        }

        if (status == HttpServletResponse.SC_INTERNAL_SERVER_ERROR) {
            log.warn("Responding server error.", e);
        }

        resp.setStatus(status);

        PrintWriter wr = resp.getWriter();
        String errmsg = e.toString(); // (e instanceof BException) ?
                                      // ((BException)e).msg : e.toString();
        wr.print(errmsg);
        wr.close();

    } else {

        if (log.isDebugEnabled())
            log.debug("copy to servlet output");
        boolean isJson = BMessageHeader.detectProtocol(obuf) == BMessageHeader.MAGIC_JSON;
        resp.setContentType(isJson ? "application/json; charset=UTF-8" : "application/byps");
        resp.setContentLength(obuf.remaining());
        OutputStream os = resp.getOutputStream();

        if (log.isDebugEnabled()) {
            log.debug("buffer: \r\n" + BBuffer.toDetailString(obuf));
        }

        if (isAsync) {

            // Tomcat does not throw an IOException in asynchronous requests, if the
            // client
            // has closed the socket. Somewhere on stackoverflow.com I found a hack
            // to workaround this bug. The workaround splits the message into two
            // parts and calls flush() after each part. The second flush throws the
            // expected exception. But the author of this workaround mentioned, that
            // it does not work in all cases - and I confirm to him.
            // http://stackoverflow.com/questions/7124508/how-to-properly-detect-a-client-disconnect-in-servlet-spec-3
            int pos = obuf.position(), len = obuf.remaining() / 2;
            os.write(obuf.array(), pos, len);
            os.flush();
            os.write(obuf.array(), pos + len, obuf.remaining() - len);
            os.flush();
        } else {
            os.write(obuf.array(), obuf.position(), obuf.remaining());
        }

        os.close();

        if (listener != null) {
            if (log.isDebugEnabled())
                log.debug("call onAfter-listener");
            listener.onAfterWriteHttpResponse(obuf.remaining());
        }

    }
    if (log.isDebugEnabled())
        log.debug(")writeResponse");
}

From source file:org.nuxeo.wss.handlers.fprpc.OWSSvrHandler.java

@Override
protected void processCall(FPRPCRequest request, FPRPCResponse fpResponse, int callIndex, WSSBackend backend)
        throws WSSException {

    FPRPCCall call = request.getCalls().get(callIndex);

    fpResponse.addRenderingParameter("siteRoot", request.getSitePath());
    fpResponse.addRenderingParameter("request", request);

    log.debug("Handling FP OWS call on method " + call.getMethodName());

    if ("FileOpen".equals(call.getMethodName())) {
        handleFileDialog(request, fpResponse, call, backend, false);
    } else if ("FileSave".equals(call.getMethodName())) {
        try {/*  ww  w  . j ava 2  s  .  c  o  m*/
            fpResponse.getHttpResponse().sendError(HttpServletResponse.SC_NOT_ACCEPTABLE,
                    "Please use list-document API for save as");
            return;
        } catch (IOException e) {
            throw new WSSException("Error while sending error!", e);
        }
        //handleFileDialog(request, fpResponse, call, backend, true);
    } else if ("SaveForm".equals(call.getMethodName())) {

        if ("HEAD".equals(request.getHttpRequest().getMethod())) {
            fpResponse.setContentType("text/html");
            fpResponse.getHttpResponse().setStatus(HttpServletResponse.SC_GONE);
            return;
        } else {
            fpResponse.setContentType("text/html");
            fpResponse.getHttpResponse().setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
    }
}

From source file:org.wso2.carbon.ui.transports.FileUploadServlet.java

protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    res.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
}

From source file:edu.wisc.doit.tcrypt.controller.EncryptAjaxController.java

@RequestMapping(value = "/encryptAjax", method = RequestMethod.POST)
public @ResponseBody EncryptToken encryptTextAjax(@ModelAttribute(value = "encryptToken") EncryptToken token,
        BindingResult result, HttpServletResponse response) {

    try {//from w  w w  . j  a  v  a  2 s  .  c o  m
        TokenEncrypter tokenEncrypter = getTokenEncrypter(token.getServiceKeyName());
        token.setEncryptedText(tokenEncrypter.encrypt(token.getUnencryptedText()));
    } catch (Exception e) {
        logger.error("Could not encrypt text", e);
        response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
        token.setErrorMessage(
                "There was an issue encrypting the text, please contact an admin if this behavior continues");
    }

    return token;
}

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

@Test
public void test01CreateControllerByGroup() {
    // Test impossible to create an existing controller
    deleteRequestJSONObject("/house", HttpServletResponse.SC_NO_CONTENT);
    postRequestJSONObject(urn_groups + "/group?id=1", createGroup1(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/11", createJsonController11(), HttpServletResponse.SC_CREATED);
    postRequestJSONObject(urn_groups + "/1/12", createJsonController12(), HttpServletResponse.SC_CREATED);

    JSONObject jo = postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_CREATED);
    testController16(jo);// www.j  a  va2 s . c  om
    postRequestJSONObject(urn_groups + "/1/16", createJsonController16(),
            HttpServletResponse.SC_NOT_ACCEPTABLE);

    jo = postRequestJSONObject(urn_groups + "/1/17", createJsonController17(), HttpServletResponse.SC_CREATED);
    testController17(jo);
}

From source file:org.wso2.carbon.analytics.servlet.AnalyticsServiceProcessor.java

/**
 * Destroy the analytics service./*from   w  ww.  j  a  va2  s. c  om*/
 *
 * @param req HttpRequest which has the required parameters to do the operation.
 * @param resp HttpResponse which returns the result of the intended operation.
 * @throws ServletException
 * @throws IOException
 */

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String sessionId = req.getHeader(AnalyticsAPIConstants.SESSION_ID);
    if (sessionId == null || sessionId.trim().isEmpty()) {
        resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "No session id found, Please login first!");
    } else {
        try {
            ServiceHolder.getAuthenticator().validateSessionId(sessionId);
        } catch (AnalyticsAPIAuthenticationException e) {
            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "No session id found, Please login first!");
        }
        String operation = req.getParameter(AnalyticsAPIConstants.OPERATION);
        if (operation != null && operation.trim().equalsIgnoreCase(AnalyticsAPIConstants.DESTROY_OPERATION)) {
            try {
                ServiceHolder.getAnalyticsDataService().destroy();
                resp.setStatus(HttpServletResponse.SC_OK);
            } catch (AnalyticsException e) {
                resp.sendError(HttpServletResponse.SC_EXPECTATION_FAILED, e.getMessage());
            }
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE,
                    "unsupported operation performed with post request!");
            log.error("unsupported operation performed : " + operation + " with post request!");
        }
    }
}

From source file:org.globus.workspace.service.impls.site.PilotNotificationHTTPHandler_v01.java

private static void notok(HttpServletResponse response, String msg) throws IOException {

    response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
    if (msg != null) {
        response.getWriter().println("NOTOK: " + msg);
    } else {//from   w  ww  .ja  v a  2  s  . co m
        response.getWriter().println("NOTOK");
    }
}

From source file:org.onecmdb.web.remote.RemoteController.java

/**
 * Command(s)/*from  w  w  w  . j av a 2s .com*/
 */

/*
 * Auth Command.
 */
public ModelAndView authHandler(HttpServletRequest request, HttpServletResponse resp) throws Exception {
    getLog().info("AuthHandler()");
    AuthCommand command = new AuthCommand(this.onecmdb);
    ServletRequestDataBinder binder = new ServletRequestDataBinder(command);
    binder.bind(request);

    try {
        String token = command.getToken();
        resp.setContentLength(token.length());
        resp.setContentType("text/plain");
        resp.getOutputStream().write(token.getBytes());

    } catch (Exception e) {
        resp.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE, "Authentication Failed!");
    }
    return (null);
}