Example usage for javax.servlet.http HttpServletResponse sendError

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

Introduction

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

Prototype

public void sendError(int sc, String msg) throws IOException;

Source Link

Document

Sends an error response to the client using the specified status and clears the buffer.

Usage

From source file:net.navasoft.madcoin.backend.services.security.CustomAuthenticationEntryPoint.java

/**
 * Commence./*from www .  ja v a2 s . c  om*/
 * 
 * @param request
 *            the request
 * @param response
 *            the response
 * @param authException
 *            the auth exception
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws ServletException
 *             the servlet exception
 * @since 27/07/2014, 06:48:55 PM
 */
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    System.out.println("Entra...");
    System.out.println(request.getParameterMap());
    response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
            "Unauthorized: Authentication token was either missing or invalid.");
}

From source file:com.sammyun.filter.AccessDeniedFilter.java

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletResponse response = (HttpServletResponse) servletResponse;
    response.addHeader(new String(Base64.decodeBase64("UG93ZXJlZEJ5"), "utf-8"),
            new String(Base64.decodeBase64("U2hvcHh4Lm5ldA=="), "utf-8"));
    response.sendError(HttpServletResponse.SC_FORBIDDEN, ERROR_MESSAGE);
}

From source file:org.fenixedu.bennu.spring.resolvers.BennuSpringExceptionResolver.java

@Override
protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response,
        Object handler, Exception ex) {
    if (ex instanceof DomainException) {
        try {/*from w ww .  ja va2s  .  com*/
            DomainException domainException = (DomainException) ex;
            response.sendError(domainException.getResponseStatus().getStatusCode(),
                    domainException.getLocalizedMessage());
            return new ModelAndView();
        } catch (IOException e) {
            logger.warn("Exception ocurred while handling BennuSpringException", e);
        }
    }
    return null;
}

From source file:grails.plugin.springsecurity.web.authentication.AjaxAwareAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    if (StringUtils.equalsIgnoreCase(request.getHeader("nopage"), "true")) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized: The requested URL is protected");
        return;/* w w  w.ja v a  2 s  . c  o m*/
    }
    super.commence(request, response, authException);
}

From source file:org.sventon.web.ctrl.RSSController.java

private void handleError(HttpServletResponse response, String errorMessage) throws IOException {
    logger.error(errorMessage);/*from  w w w .j a v a 2  s.c  om*/
    response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, errorMessage);
}

From source file:org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationEntryPoint.java

protected void commenceUnauthorizedResponse(HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    response.addHeader(HttpHeaders.WWW_AUTHENTICATE, String.format("Bearer realm=\"%s\"", realm));
    response.sendError(HttpStatus.UNAUTHORIZED.value(), HttpStatus.UNAUTHORIZED.getReasonPhrase());
}

From source file:com.natpryce.piazza.BuildMonitorController.java

private ModelAndView showProject(String projectId, boolean showFeatureBranchBuildsOnly,
        HttpServletResponse response) throws IOException {
    SProject project = projectManager.findProjectByExternalId(projectId);
    if (project == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "no project with id " + projectId);
        return null;
    }//www  . j a  va  2s.c o m

    PiazzaProjectSettings projectSettings = (PiazzaProjectSettings) projectSettingsManager
            .getSettings(projectId, PiazzaProjectSettings.PROJECT_SETTINGS_NAME);

    SUser associatedUser = getAssociatedUser();
    String view = showFeatureBranchBuildsOnly ? "piazza-project-monitor-feature-branches.jsp"
            : "piazza-project-monitor.jsp";

    return modelWithView(view).addObject("project", new ProjectMonitorViewState(project, piazza.userGroup(),
            piazza.getConfiguration(), projectSettings, associatedUser));
}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

private void writeProxyErrorResponse(HttpServletResponse response, IOException exception) {
    try {//  w w  w  .  j  a v a2 s  .  co  m
        response.sendError(SC_INTERNAL_SERVER_ERROR, exception.getMessage());
    } catch (IOException e) {
        throw new UncheckedIOException(exception);
    }
}

From source file:io.apiman.manager.ui.server.servlets.UrlFetchProxyServlet.java

/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from ww w  .j a va2s. com*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String url = req.getHeader("X-Apiman-Url"); //$NON-NLS-1$
    if (url == null) {
        resp.sendError(500, "No URL specified in X-Apiman-Url"); //$NON-NLS-1$
        return;
    }

    URL remoteUrl = new URL(url);
    HttpURLConnection remoteConn = (HttpURLConnection) remoteUrl.openConnection();
    InputStream remoteIS = null;
    OutputStream responseOS = null;
    try {
        remoteConn.connect();
        Map<String, List<String>> headerFields = remoteConn.getHeaderFields();
        for (String headerName : headerFields.keySet()) {
            if (headerName == null) {
                continue;
            }
            if (EXCLUDE_HEADERS.contains(headerName)) {
                continue;
            }
            String headerValue = remoteConn.getHeaderField(headerName);
            resp.setHeader(headerName, headerValue);
        }
        resp.setHeader("Cache-control", "no-cache, no-store, must-revalidate"); //$NON-NLS-1$ //$NON-NLS-2$
        remoteIS = remoteConn.getInputStream();
        responseOS = resp.getOutputStream();
        IOUtils.copy(remoteIS, responseOS);
        resp.flushBuffer();
    } catch (Exception e) {
        resp.sendError(500, e.getMessage());
    } finally {
        IOUtils.closeQuietly(responseOS);
        IOUtils.closeQuietly(remoteIS);
    }
}

From source file:com.natpryce.piazza.BuildMonitorController.java

private ModelAndView showBuildType(String buildTypeId, HttpServletResponse response) throws IOException {
    SBuildType buildType = projectManager.findBuildTypeByExternalId(buildTypeId);
    if (buildType == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "no build type with id " + buildTypeId);
        return null;
    }//  w ww.j  ava  2 s .  co m
    return modelWithView("piazza-build-type-monitor.jsp").addObject("build",
            new BuildTypeMonitorViewState(buildType, piazza.userGroup(), piazza.isShowOnFailureOnly()));
}