List of usage examples for javax.servlet.http HttpServletRequest getServletContext
public ServletContext getServletContext();
From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java
public static OutputStream getOutputStream(final HttpServletRequest request, final HttpServletResponse response) throws IOException { return getOutputStream(request, response, getManagementConfiguration(request.getServletContext())); }
From source file:org.bonitasoft.web.designer.controller.utils.HttpFile.java
public static void writeFileInResponse(HttpServletRequest request, HttpServletResponse response, Path filePath) throws IOException { if (!isExistingFilePath(response, filePath)) { response.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*from w ww . j a v a 2s. c o m*/ } writeFileInResponse(response, filePath, request.getServletContext().getMimeType(filePath.getFileName().toString()), "inline"); }
From source file:io.lavagna.web.security.PathConfiguration.java
private static Map<String, LoginHandler> findActiveLoginHandlers(HttpServletRequest req) { Map<String, LoginHandler> res = new HashMap<String, LoginHandler>(); WebApplicationContext ctx = getWebApplicationContext(req.getServletContext()); LoginHandlerType[] authMethods = Json.GSON.fromJson( ctx.getBean(ConfigurationRepository.class).getValue(Key.AUTHENTICATION_METHOD), LoginHandlerType[].class); for (LoginHandlerType m : authMethods) { res.put(m.pathAfterLogin, ctx.getBean(m.classHandler)); }// w w w . j av a2 s.c om return res; }
From source file:fiftyone.mobile.detection.webapp.JavascriptProvider.java
/** * Responds with the JavaScript listing the featured properties and values. * @param request//from w ww . j a va 2 s . c o m * @param response * @throws IOException */ static void sendFeatureJavaScript(HttpServletRequest request, HttpServletResponse response) throws IOException { StringBuilder javascript = new StringBuilder("// Copyright 51 Degrees Mobile Experts Limited\r\n"); Dataset dataSet = WebProvider.getActiveProvider(request.getServletContext()).dataSet; final Map<String, String[]> results = WebProvider.getResult(request); List<String> features = new ArrayList<String>(); String query = request.getQueryString(); if (query == null) { for (Property property : dataSet.properties) { if (property.valueType != PropertyValueType.JAVASCRIPT) { getFeatureJavaScript(results, features, property); } } } else { Set<String> requestedProperties = new HashSet<String>(Arrays.asList(query.split("&"))); for (Property property : dataSet.properties) { if (property.valueType != PropertyValueType.JAVASCRIPT) { for (String name : requestedProperties) { if (name.equalsIgnoreCase(property.getName())) { getFeatureJavaScript(results, features, property); } } } } } javascript.append(String.format("var FODF={%s};", stringJoin(",", features))); sendJavaScript(request, response, WebProvider.getActiveProvider(request.getServletContext()).dataSet, javascript); }
From source file:br.eb.ime.pfc.domain.GeoServerCommunication.java
public static void redirectStreamFromRequest(HttpServletRequest request, HttpServletResponse response) { final String urlName = GEOSERVER_URL + request.getRequestURI().replace(request.getContextPath() + "/geoserver", "") + "?" + request.getQueryString();/*from ww w .j a v a2 s . c o m*/ request.getServletContext().log("URL" + urlName); request.getServletContext().log("CONTEXT" + request.getContextPath()); request.getServletContext().log("URL" + request.getRequestURI()); redirectStream(urlName, request, response); }
From source file:io.lavagna.web.helper.UserSession.java
private static void addRememberMeCookie(int userId, HttpServletRequest req, HttpServletResponse resp, UserRepository userRepository) { String token = userRepository.createRememberMeToken(userId); ///* w w w . j av a2s . c om*/ Cookie c = new Cookie("LAVAGNA_REMEMBER_ME", userId + "," + token); c.setPath(req.getContextPath() + "/"); c.setHttpOnly(true); c.setMaxAge(60 * 60 * 24 * 365); // 1 year if (req.getServletContext().getSessionCookieConfig().isSecure()) { c.setSecure(true); } resp.addCookie(c); }
From source file:org.dd4t.mvc.utils.RenderUtils.java
/** * Dispatch a url to a request dispatcher while buffering the output in a string * (and not directly to the response's writer). */// ww w . j a v a 2 s . co m public static String dispatchBufferedRequest(final HttpServletRequest request, final HttpServletResponse response, final String url) throws ServletException, IOException { long time = System.currentTimeMillis(); final RequestDispatcher dispatcher = request.getServletContext().getRequestDispatcher(url); final HttpServletResponse responseWrapper = new HttpServletResponseWrapper(response) { private CharArrayWriter output = new CharArrayWriter(); @Override public String toString() { return output.toString(); } @Override public PrintWriter getWriter() { return new PrintWriter(output); } }; dispatcher.include(request, responseWrapper); time = System.currentTimeMillis() - time; LOG.debug("dispatchBufferedRequest {}, takes: {} ms.", url, time); return responseWrapper.toString(); }
From source file:org.keycloak.example.oauth.ProductDatabaseClient.java
public static AccessTokenResponse getTokenResponse(HttpServletRequest request) { // The ServletOAuthClient is obtained by getting a context attribute // that is set in the Bootstrap context listener in this project. // You really should come up with a better way to initialize // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code // and take a look how it works. You can also take a look at third-party-cdi example ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext() .getAttribute(ServletOAuthClient.class.getName()); try {//from w w w .j a va 2 s. c om return oAuthClient.getBearerToken(request); } catch (IOException e) { throw new RuntimeException(e); } catch (ServerRequest.HttpFailure failure) { throw new RuntimeException(failure); } }
From source file:be.fedict.eid.idp.webapp.ProtocolEntryServlet.java
public static IdentityProviderProtocolService findProtocolService(HttpServletRequest request) throws ServletException { String contextPath = getProtocolServiceContextPath(request); ServletContext servletContext = request.getServletContext(); Map<String, IdentityProviderProtocolService> protocolServices = getProtocolServices(servletContext); if (null != protocolServices) { return protocolServices.get(contextPath); }/*w w w . j a va 2 s .c om*/ return null; }
From source file:org.keycloak.example.oauth.ProductDatabaseClient.java
public static void redirect(HttpServletRequest request, HttpServletResponse response) { // The ServletOAuthClient is obtained by getting a context attribute // that is set in the Bootstrap context listener in this project. // You really should come up with a better way to initialize // and obtain the ServletOAuthClient. I actually suggest downloading the ServletOAuthClient code // and take a look how it works. You can also take a look at third-party-cdi example ServletOAuthClient oAuthClient = (ServletOAuthClient) request.getServletContext() .getAttribute(ServletOAuthClient.class.getName()); try {/*from w w w . j a va 2 s.c o m*/ oAuthClient.redirectRelative("pull_data.jsp", request, response); } catch (IOException e) { throw new RuntimeException(e); } }