List of usage examples for javax.servlet.http HttpServletRequest getQueryString
public String getQueryString();
From source file:org.archive.wayback.webapp.AccessPoint.java
/** * @param httpRequest//from w w w. ja v a2s .com * @param includeQuery * @return the portion of the request following the path to this context * without leading '/' */ private String translateRequest(HttpServletRequest httpRequest, boolean includeQuery) { String origRequestPath = httpRequest.getRequestURI(); if (includeQuery) { String queryString = httpRequest.getQueryString(); if (queryString != null) { origRequestPath += "?" + queryString; } } String contextPath = getContextPath(httpRequest); if (!origRequestPath.startsWith(contextPath)) { if (contextPath.startsWith(origRequestPath)) { // missing trailing '/', just omit: return ""; } return null; } return origRequestPath.substring(contextPath.length()); }
From source file:io.mapzone.controller.vm.http.HttpRequestForwarder.java
/** * Reads the request URI from {@code servletRequest} and rewrites it, considering * targetUri. It's used to make the new request. */// w ww . j av a 2 s . c om protected String rewriteUrlFromRequest(HttpServletRequest servletRequest) { StringBuilder uri = new StringBuilder(500); uri.append(targetUriObj); // Handle the path given to the servlet if (servletRequest.getPathInfo() != null) {// ex: /my/path.html uri.append(encodeUriQuery(rewritePath(servletRequest.getPathInfo()))); } // Handle the query string & fragment String queryString = servletRequest.getQueryString();// ex:(following '?'): // name=value&foo=bar#fragment String fragment = null; // split off fragment from queryString, updating queryString if found if (queryString != null) { int fragIdx = queryString.indexOf('#'); if (fragIdx >= 0) { fragment = queryString.substring(fragIdx + 1); queryString = queryString.substring(0, fragIdx); } } queryString = rewriteQueryString(queryString); if (queryString != null && queryString.length() > 0) { uri.append('?'); uri.append(encodeUriQuery(queryString)); } if (doSendUrlFragment.get() && fragment != null) { uri.append('#'); uri.append(encodeUriQuery(fragment)); } return uri.toString(); }
From source file:com.bosch.cr.integration.helloworld.ProxyServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("Authorization"); if (auth == null) { resp.setHeader("WWW-Authenticate", "BASIC realm=\"Proxy for Bosch IoT Things\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return;/*from w w w.j a v a 2 s.c om*/ } try { long time = System.currentTimeMillis(); CloseableHttpClient c = getHttpClient(); String targetUrl = URL_PREFIX + req.getPathInfo() + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""); BasicHttpRequest targetReq = new BasicHttpRequest(req.getMethod(), targetUrl); String user = ""; if (auth.toUpperCase().startsWith("BASIC ")) { String userpassDecoded = new String( new sun.misc.BASE64Decoder().decodeBuffer(auth.substring("BASIC ".length()))); user = userpassDecoded.substring(0, userpassDecoded.indexOf(':')); String pass = userpassDecoded.substring(userpassDecoded.indexOf(':') + 1); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); targetReq.addHeader(new BasicScheme().authenticate(creds, targetReq, null)); } targetReq.addHeader("x-cr-api-token", req.getHeader("x-cr-api-token")); CloseableHttpResponse targetResp = c.execute(targetHost, targetReq); System.out.println("Request: " + targetHost + targetUrl + ", user " + user + " -> " + (System.currentTimeMillis() - time) + " msec: " + targetResp.getStatusLine()); resp.setStatus(targetResp.getStatusLine().getStatusCode()); targetResp.getEntity().writeTo(resp.getOutputStream()); } catch (IOException | AuthenticationException ex) { throw new RuntimeException(ex); } }
From source file:nl.knmi.adaguc.services.oauth2.OAuth2Handler.java
/** * Endpoint which should directly be called by the servlet. * //from w w w . j a v a 2 s . c om * @param request * @param response * @throws ElementNotFoundException */ public static void doGet(HttpServletRequest request, HttpServletResponse response) throws ElementNotFoundException { // Check if we are dealing with getting JSON request for building up the // login form String makeform = null; try { makeform = HTTPTools.getHTTPParam(request, "makeform"); } catch (Exception e) { } if (makeform != null) { makeForm(request, response); return; } // Check if we are dealing with step1 or step2 in the OAuth process. String code = null; try { code = HTTPTools.getHTTPParam(request, "code"); } catch (Exception e) { } if (code == null) { // Step 1 Debug.println("Step 1: start GetCode request for " + request.getQueryString()); try { getCode(request, response); } catch (OAuthSystemException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } else { // Step 2 Debug.println("Step 2: start makeOauthzResponse for " + request.getQueryString()); makeOauthzResponse(request, response); } }
From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (logger.isMdwDebugEnabled()) { logger.mdwDebug("SOAP Listener GET Request:\n" + request.getRequestURI() + (request.getQueryString() == null ? "" : ("?" + request.getQueryString()))); }/*from w ww .ja v a2 s.co m*/ if (request.getServletPath().endsWith(RPC_SERVICE_PATH) || RPC_SERVICE_PATH.equals(request.getPathInfo())) { Asset rpcWsdlAsset = AssetCache.getAsset(Package.MDW + "/MdwRpcWebService.wsdl", Asset.WSDL); response.setContentType("text/xml"); response.getWriter().print(substituteRuntimeWsdl(rpcWsdlAsset.getStringContent())); } else if (request.getPathInfo() == null || request.getPathInfo().equalsIgnoreCase("mdw.wsdl")) { // forward to general wsdl RequestDispatcher requestDispatcher = request.getRequestDispatcher("/mdw.wsdl"); requestDispatcher.forward(request, response); } else if (request.getPathInfo().toUpperCase().endsWith(Asset.WSDL)) { String wsdlAsset = request.getPathInfo().substring(1); Asset asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); if (asset == null) { // try trimming file extension wsdlAsset = wsdlAsset.substring(0, wsdlAsset.length() - 5); asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); } if (asset == null) { // try with lowercase extension wsdlAsset = wsdlAsset + ".wsdl"; asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL); } if (asset == null) { String message = "No WSDL resource found: " + request.getPathInfo().substring(1); logger.severe(message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.getWriter().print(message); } else { response.setContentType("text/xml"); response.getWriter().print(substituteRuntimeWsdl(asset.getStringContent())); } } else { ServletException ex = new ServletException( "HTTP GET not supported for URL: " + request.getRequestURL()); logger.severeException(ex.getMessage(), ex); throw ex; } }
From source file:com.bosch.cr.integration.hello_world_ui.ProxyServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("Authorization"); if (auth == null) { resp.setHeader("WWW-Authenticate", "BASIC realm=\"Proxy for CR\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return;//from w w w . j a v a2 s .co m } try { long time = System.currentTimeMillis(); CloseableHttpClient c = getHttpClient(); String targetUrl = URL_PREFIX + req.getPathInfo() + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""); BasicHttpRequest targetReq = new BasicHttpRequest(req.getMethod(), targetUrl); String user = ""; if (auth.toUpperCase().startsWith("BASIC ")) { String userpassDecoded = new String( new sun.misc.BASE64Decoder().decodeBuffer(auth.substring("BASIC ".length()))); user = userpassDecoded.substring(0, userpassDecoded.indexOf(':')); String pass = userpassDecoded.substring(userpassDecoded.indexOf(':') + 1); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); targetReq.addHeader(new BasicScheme().authenticate(creds, targetReq, null)); } targetReq.addHeader("x-cr-api-token", req.getHeader("x-cr-api-token")); CloseableHttpResponse targetResp = c.execute(targetHost, targetReq); System.out.println("Request: " + targetHost + targetUrl + ", user " + user + " -> " + (System.currentTimeMillis() - time) + " msec: " + targetResp.getStatusLine()); resp.setStatus(targetResp.getStatusLine().getStatusCode()); targetResp.getEntity().writeTo(resp.getOutputStream()); } catch (IOException | AuthenticationException ex) { throw new RuntimeException(ex); } }
From source file:com.bosch.cr.examples.inventorybrowser.server.ProxyServlet.java
@Override protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String auth = req.getHeader("Authorization"); if (auth == null) { resp.setHeader("WWW-Authenticate", "BASIC realm=\"Proxy for Bosch IoT Things\""); resp.sendError(HttpServletResponse.SC_UNAUTHORIZED); return;//from www.ja va 2s . c o m } try { long time = System.currentTimeMillis(); CloseableHttpClient c = getHttpClient(); String targetUrl = URL_PREFIX + req.getPathInfo() + (req.getQueryString() != null ? ("?" + req.getQueryString()) : ""); BasicHttpRequest targetReq = new BasicHttpRequest(req.getMethod(), targetUrl); String user = ""; if (auth.toUpperCase().startsWith("BASIC ")) { String userpassDecoded = new String( new sun.misc.BASE64Decoder().decodeBuffer(auth.substring("BASIC ".length()))); user = userpassDecoded.substring(0, userpassDecoded.indexOf(':')); String pass = userpassDecoded.substring(userpassDecoded.indexOf(':') + 1); UsernamePasswordCredentials creds = new UsernamePasswordCredentials(user, pass); targetReq.addHeader(new BasicScheme().authenticate(creds, targetReq, null)); } targetReq.addHeader("x-cr-api-token", props.getProperty("apiToken")); CloseableHttpResponse targetResp = c.execute(targetHost, targetReq); System.out.println("Request: " + targetHost + targetUrl + ", user " + user + " -> " + (System.currentTimeMillis() - time) + " msec: " + targetResp.getStatusLine()); resp.setStatus(targetResp.getStatusLine().getStatusCode()); targetResp.getEntity().writeTo(resp.getOutputStream()); } catch (IOException | AuthenticationException ex) { throw new RuntimeException(ex); } }
From source file:se.inera.certificate.proxy.mappings.remote.RemoteDispatcher.java
private URI buildNewURL(HttpServletRequest httpRequest, RemoteMapping mapping) { checkNotNull(httpRequest, "Argument httpRequest is null!"); checkNotNull(mapping, "Argument mapping is null!"); String requestUrl = getPath(httpRequest); String newUri = joinFragments(mapping.getMappedPath(), substringAfter(requestUrl, mapping.getContext())); URI result = null;//from w w w . jav a2s.c om try { result = new URIBuilder().setScheme(mapping.getMappedProtocol()).setHost(mapping.getMappedHost()) .setPort(mapping.getMappedPort()).setPath(newUri).setQuery(httpRequest.getQueryString()) .build(); } catch (URISyntaxException e) { Throwables.propagate(e); } return result; }
From source file:com.openmeap.services.ServiceManagementServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { Result result = null;/*from www . ja v a 2 s .c o m*/ PrintWriter os = new PrintWriter(response.getOutputStream()); logger.debug("Request uri: {}", request.getRequestURI()); logger.debug("Request url: {}", request.getRequestURL()); logger.debug("Query string: {}", request.getQueryString()); if (logger.isDebugEnabled()) { logger.debug("Parameter map: {}", ParameterMapUtils.toString(request.getParameterMap())); } String action = request.getParameter(UrlParamConstants.ACTION); if (action == null) { action = ""; } if (!authenticates(request)) { logger.error("Request failed to authenticate ", request); result = new Result(Result.Status.FAILURE, "Authentication failed"); sendResult(response, os, result); return; } if (action.equals(ModelEntityEventAction.MODEL_REFRESH.getActionName())) { logger.trace("Processing refresh"); result = refresh(request, response); sendResult(response, os, result); return; } else if (action.equals(ClusterNodeRequest.HEALTH_CHECK)) { logger.trace("Cluster node health check"); result = healthCheck(request, response); sendResult(response, os, result); return; } GlobalSettings settings = modelManager.getGlobalSettings(); ClusterNode clusterNode = modelManager.getClusterNode(); if (clusterNode == null) { throw new RuntimeException( "openmeap-services-web needs to be configured as a cluster node in the settings of the admin interface."); } Map<Method, String> validationErrors = clusterNode.validate(); if (validationErrors != null) { throw new RuntimeException(new InvalidPropertiesException(clusterNode, validationErrors)); } if (request.getParameter("clearPersistenceContext") != null && context instanceof AbstractApplicationContext) { logger.trace("Clearing persistence context"); clearPersistenceContext(); } else if (action.equals(ModelEntityEventAction.ARCHIVE_UPLOAD.getActionName())) { logger.trace("Processing archive upload - max file size: {}, storage path prefix: {}", settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix()); archiveUploadHandler.setFileSystemStoragePathPrefix(clusterNode.getFileSystemStoragePathPrefix()); Map<Object, Object> paramMap = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix(), request); result = handleArchiveEvent(archiveUploadHandler, new MapPayloadEvent(paramMap), paramMap); } else if (action.equals(ModelEntityEventAction.ARCHIVE_DELETE.getActionName())) { logger.trace("Processing archive delete - max file size: {}, storage path prefix: {}", settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix()); archiveDeleteHandler.setFileSystemStoragePathPrefix(clusterNode.getFileSystemStoragePathPrefix()); Map<Object, Object> paramMap = ServletUtils.cloneParameterMap(settings.getMaxFileUploadSize(), clusterNode.getFileSystemStoragePathPrefix(), request); result = handleArchiveEvent(archiveDeleteHandler, new MapPayloadEvent(paramMap), paramMap); } sendResult(response, os, result); }