List of usage examples for javax.servlet.http HttpServletRequestWrapper getParameter
public String getParameter(String name)
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
private static boolean shouldDecodeBase64(@NotNull HttpServletRequestWrapper requestWrapper) { return "1".equals(requestWrapper.getParameter("b64")); }
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
private static String parseAction(HttpServletRequestWrapper requestWrapper) { final String monitorArgs = requestWrapper.getParameter("action"); final Base64 b64 = new Base64(); return monitorArgs == null ? "" : new String(b64.decode(monitorArgs)); }
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
private static String parseArgs(HttpServletRequestWrapper requestWrapper) { final String monitorArgs = requestWrapper.getParameter("args"); final Base64 b64 = new Base64(); return monitorArgs == null ? "" : new String(b64.decode(monitorArgs)); }
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
private static String parseToken(@NotNull HttpServletRequestWrapper requestWrapper) { final String token = requestWrapper.getParameter("token"); return token == null ? "" : token.trim(); }
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
private static GroovyMonitor.RunMode parseMode(@NotNull HttpServletRequestWrapper requestWrapper, @NotNull GroovyMonitor.RunMode defaultMode) { final String param = requestWrapper.getParameter("m"); return param == null ? defaultMode : GroovyMonitor.RunMode.valueOf(param.trim().toUpperCase()); }
From source file:de.zib.gndms.kit.monitor.GroovyMoniServlet.java
@SuppressWarnings({ "BooleanMethodNameMustStartWithQuestion" }) private synchronized boolean contAftOperatingSrvIfRequested(@NotNull HttpServletRequestWrapper requestWrapper, final HttpServletResponse responseParam) throws IOException { final String mode = requestWrapper.getParameter("m"); // refresh == reload config and restart server if config has changed if ("refresh".equalsIgnoreCase(mode)) { try {// ww w. j a v a 2s . c o m moniServer.refresh(); throw new ServletRuntimeException(HttpServletResponse.SC_RESET_CONTENT, "Refreshed", false); } catch (Exception e) { intlError(e); } } // restart server if ("restart".equalsIgnoreCase(mode)) { try { moniServer.restart(); throw new ServletRuntimeException(HttpServletResponse.SC_RESET_CONTENT, "Restarted", false); } catch (Exception e) { intlError(e); } } if ("call".equals(mode)) { doCallAction(requestWrapper, responseParam); return false; } return true; }
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflowTest.java
@Test public void multipleFiles() throws IOException, ServletException { String body = FileUtils.readFileToString( new File("src/test/java/org/primeframework/mvc/servlet/http-test-body-multiple-files.txt")); HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(request.getParameterMap()).andReturn(new HashMap<>()); EasyMock.expect(request.getContentType()).andReturn("multipart/form-data, boundary=AaB03x").times(2); EasyMock.expect(request.getInputStream()).andReturn(new MockServletInputStream(body.getBytes())); EasyMock.expect(request.getCharacterEncoding()).andReturn("UTF-8"); EasyMock.expect(request.getContentLength()).andReturn(body.length()); final Capture<Map<String, List<FileInfo>>> capture = new Capture<>(); request.setAttribute(eq(RequestKeys.FILE_ATTRIBUTE), capture(capture)); EasyMock.replay(request);/*from w w w . j a v a2 s . c om*/ final AtomicBoolean run = new AtomicBoolean(false); MockWorkflowChain chain = new MockWorkflowChain(() -> { Map<String, List<FileInfo>> files = capture.getValue(); assertEquals(files.size(), 1); try { assertEquals(FileUtils.readFileToString(files.get("userfiles").get(0).file), "test"); assertEquals(FileUtils.readFileToString(files.get("userfiles").get(1).file), "test2"); } catch (IOException e) { throw new RuntimeException(e); } run.set(true); }); HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request); RequestBodyWorkflow workflow = new RequestBodyWorkflow(wrapper); workflow.perform(chain); assertTrue(run.get()); assertEquals(wrapper.getParameter("field1"), "value1"); assertEquals(wrapper.getParameter("field2"), "value2"); EasyMock.verify(request); }
From source file:org.primeframework.mvc.parameter.RequestBodyWorkflowTest.java
@Test public void singleFiles() throws IOException, ServletException { String body = FileUtils.readFileToString( new File("src/test/java/org/primeframework/mvc/servlet/http-test-body-single-file.txt")); HttpServletRequest request = EasyMock.createStrictMock(HttpServletRequest.class); EasyMock.expect(request.getParameterMap()).andReturn(new HashMap<>()); EasyMock.expect(request.getContentType()).andReturn("multipart/form-data, boundary=AaB03x").times(2); EasyMock.expect(request.getInputStream()).andReturn(new MockServletInputStream(body.getBytes())); EasyMock.expect(request.getCharacterEncoding()).andReturn("UTF-8"); EasyMock.expect(request.getContentLength()).andReturn(body.length()); final Capture<Map<String, List<FileInfo>>> capture = new Capture<>(); request.setAttribute(eq(RequestKeys.FILE_ATTRIBUTE), capture(capture)); EasyMock.replay(request);//from w ww. j ava2 s .c o m final AtomicBoolean run = new AtomicBoolean(false); MockWorkflowChain chain = new MockWorkflowChain(() -> { Map<String, List<FileInfo>> files = capture.getValue(); assertEquals(files.size(), 1); try { assertEquals(FileUtils.readFileToString(files.get("userfile").get(0).file), "test"); } catch (IOException e) { throw new RuntimeException(e); } run.set(true); }); HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request); RequestBodyWorkflow workflow = new RequestBodyWorkflow(wrapper); workflow.perform(chain); assertTrue(run.get()); assertEquals(wrapper.getParameter("field1"), "value1"); assertEquals(wrapper.getParameter("field2"), "value2"); EasyMock.verify(request); }
From source file:org.wso2.carbon.identity.oauth.endpoint.revoke.OAuthRevocationEndpoint.java
@POST @Path("/") @Consumes("application/x-www-form-urlencoded") public Response revokeAccessToken(@Context HttpServletRequest request, MultivaluedMap<String, String> paramMap) throws OAuthSystemException { try {// w w w. j a v a 2s.c o m PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext carbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); carbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID); carbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); HttpServletRequestWrapper httpRequest = new OAuthRequestWrapper(request, paramMap); if (log.isDebugEnabled()) { logAccessTokenRevocationRequest(httpRequest); } String token = httpRequest.getParameter("token"); if (StringUtils.isBlank(token) && paramMap.get("token") != null && !paramMap.isEmpty()) { token = paramMap.get("token").get(0); } String tokenType = httpRequest.getParameter("token_type_hint"); if (StringUtils.isBlank(tokenType) && paramMap.get("token_type_hint") != null && !paramMap.get("token_type_hint").isEmpty()) { tokenType = paramMap.get("token_type_hint").get(0); } String callback = httpRequest.getParameter("callback"); if (StringUtils.isBlank(callback) && paramMap.get("callback") != null && !paramMap.get("callback").isEmpty()) { callback = paramMap.get("callback").get(0); } // extract the basic auth credentials if present in the request and use for // authentication. if (request.getHeader(OAuthConstants.HTTP_REQ_HEADER_AUTHZ) != null) { try { String[] clientCredentials = EndpointUtil.extractCredentialsFromAuthzHeader( request.getHeader(OAuthConstants.HTTP_REQ_HEADER_AUTHZ)); // The client MUST NOT use more than one authentication method in each request if (paramMap.containsKey(OAuth.OAUTH_CLIENT_ID) && paramMap.containsKey(OAuth.OAUTH_CLIENT_SECRET)) { return handleBasicAuthFailure(callback); } if (clientCredentials.length != 2) { handleBasicAuthFailure(callback); } // add the credentials available in Authorization to the parameter map paramMap.add(OAuth.OAUTH_CLIENT_ID, clientCredentials[0]); paramMap.add(OAuth.OAUTH_CLIENT_SECRET, clientCredentials[1]); } catch (OAuthClientException e) { // malformed credential string is considered as an auth failure. log.error("Error while extracting credentials from authorization header", e); return handleBasicAuthFailure(callback); } } try { OAuthRevocationRequestDTO revokeRequest = new OAuthRevocationRequestDTO(); if (paramMap.get(OAuth.OAUTH_CLIENT_ID) != null) { revokeRequest.setConsumerKey(paramMap.get(OAuth.OAUTH_CLIENT_ID).get(0)); } if (paramMap.get(OAuth.OAUTH_CLIENT_SECRET) != null) { revokeRequest.setConsumerSecret(paramMap.get(OAuth.OAUTH_CLIENT_SECRET).get(0)); } if (StringUtils.isNotEmpty(token)) { revokeRequest.setToken(token); } else { handleClientFailure(callback); } if (StringUtils.isNotEmpty(tokenType)) { revokeRequest.setToken_type(tokenType); } OAuthRevocationResponseDTO oauthRevokeResp = revokeTokens(revokeRequest); // if there BE has returned an error if (oauthRevokeResp.getErrorMsg() != null) { // if there is an auth failure, HTTP 401 Status Code should be sent back to the client. if (OAuth2ErrorCodes.INVALID_CLIENT.equals(oauthRevokeResp.getErrorCode())) { return handleBasicAuthFailure(callback); } else if (OAuth2ErrorCodes.UNAUTHORIZED_CLIENT.equals(oauthRevokeResp.getErrorCode())) { return handleAuthorizationFailure(callback); } // Otherwise send back HTTP 400 Status Code return handleClientFailure(callback, oauthRevokeResp); } else { OAuthResponse response; if (StringUtils.isNotEmpty(callback)) { response = CarbonOAuthASResponse.revokeResponse(HttpServletResponse.SC_OK) .buildBodyMessage(); response.setBody(callback + "();"); } else { response = CarbonOAuthASResponse.revokeResponse(HttpServletResponse.SC_OK) .buildBodyMessage(); } ResponseHeader[] headers = oauthRevokeResp.getResponseHeaders(); ResponseBuilder respBuilder = Response.status(response.getResponseStatus()) .header(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL, OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE) .header(HTTPConstants.HEADER_CONTENT_LENGTH, "0") .header(OAuthConstants.HTTP_RESP_HEADER_PRAGMA, OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE); if (headers != null && headers.length > 0) { for (int i = 0; i < headers.length; i++) { if (headers[i] != null) { respBuilder.header(headers[i].getKey(), headers[i].getValue()); } } } if (StringUtils.isNotEmpty(callback)) { respBuilder.header("Content-Type", "application/javascript"); } else { respBuilder.header("Content-Type", "text/html"); } return respBuilder.entity(response.getBody()).build(); } } catch (OAuthClientException e) { return handleServerFailure(callback, e); } } finally { PrivilegedCarbonContext.endTenantFlow(); } }