Example usage for javax.servlet.http HttpServletRequest getServletContext

List of usage examples for javax.servlet.http HttpServletRequest getServletContext

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Gets the servlet context to which this ServletRequest was last dispatched.

Usage

From source file:cn.vlabs.umt.services.user.utils.ServiceFactory.java

/**
 * ?BeanFactory//w w w .  j  a  v  a 2s  .  c  o m
 * */
public static BeanFactory getBeanFactory(HttpServletRequest request) {
    return (BeanFactory) request.getServletContext().getAttribute(Attributes.APPLICATION_CONTEXT_KEY);
}

From source file:io.lavagna.web.security.SecurityFilter.java

private static String reqUriWithoutContextPath(HttpServletRequest request) {
    return request.getRequestURI().substring(request.getServletContext().getContextPath().length());
}

From source file:org.opensingular.form.wicket.mapper.attachment.upload.servlet.FileUploadServlet.java

public static String getUploadUrl(HttpServletRequest req, AttachmentKey attachmentKey) {
    return req.getServletContext().getContextPath() + UPLOAD_URL + "/" + attachmentKey.asString();
}

From source file:org.keycloak.quickstart.appjee.ServiceClient.java

private static String getServiceUrl(HttpServletRequest req, KeycloakSecurityContext session) {
    String uri = req.getServletContext().getInitParameter(SERVICE_URI_INIT_PARAM_NAME);
    if (uri != null && !uri.contains("localhost"))
        return uri;

    String ip = req.getLocalAddr();

    if (ip != null) {
        ip = "localhost";
        try {/*www.  ja v a2  s .  c  o m*/
            ip = java.net.InetAddress.getLocalHost().getHostAddress();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    return "http://" + ip + ":8080/service";
}

From source file:io.lavagna.web.helper.Redirector.java

public static void sendRedirect(HttpServletRequest req, HttpServletResponse resp, String page,
        Map<String, List<String>> params) throws IOException {
    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(req.getServletContext());
    String baseApplicationUrl = ctx.getBean(ConfigurationRepository.class).getValue(Key.BASE_APPLICATION_URL);

    UriComponents urlToRedirect = UriComponentsBuilder.fromHttpUrl(baseApplicationUrl).path(page)
            .queryParams(new LinkedMultiValueMap<>(params)).build();

    resp.sendRedirect(urlToRedirect.toUriString());
}

From source file:net.officefloor.plugin.servlet.container.WebInfResourceAccessTest.java

/**
 * Asserts the resource./*from   w w  w . ja  v  a  2s  .co  m*/
 * 
 * @param request
 *            {@link HttpServletRequest}.
 * @param resourcePath
 *            Path to the resource.
 * @param expectedResourceContent
 *            Expected content of the resource.
 */
private static void assertResource(HttpServletRequest request, String resourcePath,
        String expectedResourceContent) throws IOException {

    // Validate obtain the resource
    InputStream resource = request.getServletContext().getResourceAsStream(resourcePath);
    assertNotNull("Should have " + resourcePath + " resource", resource);

    // Validate content of resource
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    for (int value = resource.read(); value != -1; value = resource.read()) {
        buffer.write(value);
    }
    String resourceContent = new String(buffer.toByteArray());
    assertEquals("Incorrect content for resource " + resourcePath, expectedResourceContent, resourceContent);
}

From source file:com.framework.demo.web.upload.FileUploadUtils.java

/**
 * ??? // w w w .jav a2  s.  co  m
 *
 * @param request
 * @return
 */
public static final String extractUploadDir(HttpServletRequest request) {

    return request.getServletContext().getRealPath("/");
}

From source file:cn.guoyukun.spring.web.upload.FileUploadUtils.java

/**
 * ??? //from  w  ww  . j  a v  a2 s. com
 *
 * @param request
 * @return
 */
public static final String extractUploadDir(HttpServletRequest request) {
    return request.getServletContext().getRealPath("/");
}

From source file:org.bonitasoft.web.designer.controller.utils.HttpFile.java

public static void writeFileInResponseForVisualization(HttpServletRequest request, HttpServletResponse response,
        Path filePath) throws IOException {
    if (!isExistingFilePath(response, filePath)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from   w w w. j  a va2 s  . c om*/
    }
    String mimeType = request.getServletContext().getMimeType(filePath.getFileName().toString());
    if (mimeType == null || !mimeType.contains("image")) {
        mimeType = MediaType.TEXT_PLAIN_VALUE;
    }
    writeFileInResponse(response, filePath, mimeType, "inline");
}

From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java

public static Writer getOutputWriter(final HttpServletRequest request, final HttpServletResponse response)
        throws IOException {
    return getOutputWriter(request, response, getManagementConfiguration(request.getServletContext()));
}