List of usage examples for java.net URLDecoder decode
public static String decode(String s, Charset charset)
From source file:com.surevine.alfresco.webscript.gsa.canuserseeitems.CanUserSeeItemsCommandWebscriptImpl.java
@Override public void execute(WebScriptRequest request, WebScriptResponse response) throws IOException { if (_logger.isDebugEnabled()) { _logger.debug("Beginning canUserSeeItems Webscript"); }//from www . j a v a 2 s . c o m PrintStream ps = null; try { ps = new PrintStream(response.getOutputStream()); InputStream payloadInputStream = request.getContent().getInputStream(); StringWriter writer = new StringWriter(); IOUtils.copy(payloadInputStream, writer, "UTF-8"); String requestXMLString = writer.toString(); requestXMLString = URLDecoder.decode(requestXMLString, "UTF-8"); if (_logger.isDebugEnabled()) { _logger.debug("Request: " + requestXMLString); } //String requestXMLString = request.getParameter(""); if (null == requestXMLString) { throw new GSAInvalidParameterException("Request payload XML is empty", null, 500177); } Map<Integer, Object> parsedRequestDataMap = this.requestToNodeRefCollection(requestXMLString); Collection<NodeRef> nodeRefs = (Collection<NodeRef>) parsedRequestDataMap.get(NODE_REFS_KEY); String runAsUser = (String) parsedRequestDataMap.get(RUN_AS_USER_KEY); String XMLResponseString = this.getXMLResponse(nodeRefs, runAsUser); if (_logger.isDebugEnabled()) { _logger.debug("Response: " + XMLResponseString); } ps.println(XMLResponseString); //Write the response to the target OutputStream } //If we catch an exception, return an appropriate HTTP response code and a summary of the exception, then dump the full //details of the exception to the logs. Non-GSA Exceptions are wrapped, non-Exception Throwables are left to percolate upward catch (GSAInvalidParameterException e) { response.setStatus(400); //Something wrong with the parameters so we use Bad Request ps.println(e); _logger.error(e.getMessage(), e); } catch (GSAProcessingException exx) { response.setStatus(500); //Internal Server Error ps.println(exx); _logger.error(exx.getMessage(), exx); } catch (Exception ex) { response.setStatus(500); ps.println(new GSAProcessingException("Exception occured processing the commanmd: " + ex, ex, 1000)); _logger.error(ex.getMessage(), ex); } finally { if (ps != null) { ps.close(); } } }
From source file:org.runway.utils.StringEncryptDecryptUtil.java
public static String urlDecrypt(String value) throws RunwaySecurityException { String enc = null;//from w w w. j a v a 2s . c o m try { enc = URLDecoder.decode(value, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RunwaySecurityException(e); } return decrypt(enc); }
From source file:net.duckling.ddl.web.controller.LynxSearchController.java
@RequestMapping @WebLog(method = "quickSearch", params = KEYWORD) public void quickSearch(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException { //Step 1: Load Team information String keyword = URLDecoder.decode(request.getParameter(KEYWORD), "UTF-8"); VWBContext context = getVWBContext(request); TeamQuery query = new TeamQuery(); query.setTid(getTeamIdFromRequest(context, request)); query.setKeyword(keyword);//www . j ava 2 s .c o m doTeamSearch(response, context, query); }
From source file:com.android.cts.browser.BrowserBenchTest.java
@Override protected void setUp() throws Exception { super.setUp(); mPackageManager = getInstrumentation().getContext().getPackageManager(); mWebServer = new CtsTestServer(getContext()) { @Override//from w w w . ja v a 2 s.com protected HttpResponse onPost(HttpRequest request) throws Exception { // post uri will look like "cts_report.html?final=1&score=10.1&message=hello" RequestLine requestLine = request.getRequestLine(); String uriString = URLDecoder.decode(requestLine.getUri(), "UTF-8"); if (DEBUG) { Log.i(TAG, "uri:" + uriString); } String resultRe = ".*cts_report.html\\?final=([\\d])&score=([\\d]+\\.?[\\d]*)&message=([\\w][\\w ]*)"; Pattern resultPattern = Pattern.compile(resultRe); Matcher matchResult = resultPattern.matcher(uriString); if (matchResult.find()) { int isFinal = Integer.parseInt(matchResult.group(1)); double score = Double.parseDouble(matchResult.group(2)); String message = matchResult.group(3); Log.i(TAG, message + ":" + score); if (!mResultsMap.containsKey(message)) { mResultsMap.put(message, new double[mNumberRepeat]); } double[] scores = mResultsMap.get(message); scores[mRunIndex] = score; if (isFinal == 1) { String userAgent = request.getFirstHeader(HTTP_USER_AGENT).getValue(); getReportLog().printValue(HTTP_USER_AGENT + "=" + userAgent, 0, ResultType.NEUTRAL, ResultUnit.NONE); mLatch.countDown(); } mWatchDog.reset(); } return null; // default response is OK as it will be ignored by client anyway. } }; mResultsMap = new LinkedHashMap<String, double[]>(); mWatchDog = new WatchDog(BROWSER_POST_TIMEOUT_IN_MS); mWatchDog.start(); }
From source file:com.jaspersoft.jasperserver.rest.RESTLoginAuthenticationFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String username = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY); String password = EncryptionRequestUtils.getValue(request, AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY); if (!StringUtils.isEmpty(username)) { // decoding since | is not http safe username = URLDecoder.decode(username, CharEncoding.UTF_8); UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username, password);/*from ww w. j a va 2 s . com*/ authRequest.setDetails(new WebAuthenticationDetails(httpRequest)); Authentication authResult; try { authResult = authenticationManager.authenticate(authRequest); } catch (AuthenticationException e) { if (log.isDebugEnabled()) { log.debug("User " + username + " failed to authenticate: " + e.toString()); } if (log.isWarnEnabled()) { log.warn("User " + username + " failed to authenticate: " + e.toString() + " " + e, e.getRootCause()); } SecurityContextHolder.getContext().setAuthentication(null); // Send an error message in the form of OperationResult... httpResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED); //OperationResult or = servicesUtils.createOperationResult(1, "Invalid username " + username); PrintWriter pw = httpResponse.getWriter(); pw.print("Unauthorized"); return; } if (log.isDebugEnabled()) { log.debug("User " + username + " authenticated: " + authResult); } SecurityContextHolder.getContext().setAuthentication(authResult); chain.doFilter(request, response); } else { if (log.isDebugEnabled()) { log.debug("Failed to authenticate: Bad request. Username and password must be specified."); } if (log.isWarnEnabled()) { log.warn("Failed to authenticate: Bad request. Username and password must be specified."); } httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); PrintWriter pw = httpResponse.getWriter(); pw.print("Bad request." + (StringUtils.isEmpty(username) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_USERNAME_KEY + " not found." : "") + (StringUtils.isEmpty(password) ? " Parameter " + AuthenticationProcessingFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + " not found." : "")); } }
From source file:com.gargoylesoftware.htmlunit.html.HtmlFileInputTest.java
/** * @throws Exception if the test fails/*from ww w.j a va 2 s . co m*/ */ @Test public void testFileInput() throws Exception { String path = getClass().getClassLoader().getResource("testfiles/" + "tiny-png.img").toExternalForm(); testFileInput(path); final File file = new File(new URI(path)); testFileInput(file.getCanonicalPath()); if (path.startsWith("file:")) { path = path.substring("file:".length()); } while (path.startsWith("/")) { path = path.substring(1); } if (System.getProperty("os.name").toLowerCase(Locale.ROOT).contains("windows")) { testFileInput(URLDecoder.decode(path.replace('/', '\\'), "UTF-8")); } testFileInput("file:/" + path); testFileInput("file://" + path); testFileInput("file:///" + path); }
From source file:com.thoughtworks.go.server.web.TabInterceptor.java
String decode(String url) { try {//w w w . ja v a 2 s . c o m return URLDecoder.decode(url, "UTF-8"); } catch (UnsupportedEncodingException e) { return url; } }
From source file:com.wx.CoacherWXServlet.java
/** * Handles the HTTP <code>GET</code> method. * * @param request servlet request/*from w w w . j a v a 2s . c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //processRequest(request, response); //? response.setContentType("text/html;charset=utf-8"); //response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); //???? String sToken = "testToken1"; String sCorpID = "wxe706b25abb1216c0"; String sEncodingAESKey = "R5zQRNXirEIQsSGL5Hs5ydZdSuu7EkRLWLViul1P7si"; try { WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(sToken, sEncodingAESKey, sCorpID); // ?url? //URLDecoder.decode(request.getParameter("echostr"),"utf-8"); String sVerifyMsgSig = URLDecoder.decode(request.getParameter("msg_signature"), "utf-8"); String sVerifyTimeStamp = URLDecoder.decode(request.getParameter("timestamp"), "utf-8"); String sVerifyNonce = URLDecoder.decode(request.getParameter("nonce"), "utf-8"); String sVerifyEchoStr = URLDecoder.decode(request.getParameter("echostr"), "utf-8"); PrintWriter out = response.getWriter(); String sEchoStr; //? try { sEchoStr = wxcpt.VerifyURL(sVerifyMsgSig, sVerifyTimeStamp, sVerifyNonce, sVerifyEchoStr); System.out.println("verifyurl echostr: " + sEchoStr); // ?URL?sEchoStr out.print(sEchoStr); out.close(); out = null; } catch (Exception e) { //?URL e.printStackTrace(); } } catch (AesException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:edu.asu.cse564.samples.crud.io.GradebookIO.java
public String getPath(String fileName) { String reponsePath = ""; try {//from ww w.j a va 2s.com String path = this.getClass().getClassLoader().getResource("").getPath(); String fullPath = URLDecoder.decode(path, "UTF-8"); System.out.println(fullPath); // to read a file from webcontent String[] pathElements = fullPath.split("/"); for (String ele : pathElements) { if (!ele.equals("CSE564_CRUD_RESTws")) { if (ele.length() > 1) { reponsePath += ele + File.separatorChar; } } else { break; } } reponsePath += "CSE564_CRUD_RESTws" + File.separatorChar + fileName; } catch (UnsupportedEncodingException ex) { Logger.getLogger(GradebookIO.class.getName()).log(Level.SEVERE, null, ex); } return reponsePath; }
From source file:de.unirostock.sems.cbarchive.web.servlet.DownloadServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // set charset response.setCharacterEncoding(Fields.CHARSET); request.setCharacterEncoding(Fields.CHARSET); // login stuff UserManager user = null;/*w ww . ja v a2 s . c o m*/ try { user = Tools.doLogin(request, response, false); } catch (CombineArchiveWebCriticalException e) { LOGGER.error(e, "Exception while getting User"); response.setStatus(HttpServletResponse.SC_FORBIDDEN); } catch (CombineArchiveWebException e) { LOGGER.warn(e, "Exception while getting User"); response.setStatus(HttpServletResponse.SC_NO_CONTENT); return; } // splitting request URL String[] requestUrl = request.getRequestURI().substring(request.getContextPath().length()).split("/"); // check entry points if (requestUrl.length >= 5 && requestUrl[2].equals("archive")) { // request to download an archive from *any* workspace // without necessarily obtained this workspace before UserManager targetUser = null; if (requestUrl[3] != null && !requestUrl[3].isEmpty()) targetUser = new UserManager(requestUrl[3]); else return; if (requestUrl[4] != null && !requestUrl[4].isEmpty() && targetUser != null) downloadArchive(request, response, targetUser, URLDecoder.decode(requestUrl[4], Fields.CHARSET)); } else if (requestUrl.length >= 4 && requestUrl[2].equals("archive")) { // request to download an archive from the workspace if (requestUrl[3] != null && !requestUrl[3].isEmpty()) downloadArchive(request, response, user, URLDecoder.decode(requestUrl[3], Fields.CHARSET)); } else if (requestUrl.length >= 5 && requestUrl[2].equals("file")) { String archive = null; String file = null; if (requestUrl[3] != null && !requestUrl[3].isEmpty()) archive = URLDecoder.decode(requestUrl[3], Fields.CHARSET); else return; StringBuilder filePath = new StringBuilder(); for (int i = 4; i < requestUrl.length; i++) { if (requestUrl[i] != null && !requestUrl[i].isEmpty()) { filePath.append("/"); filePath.append(requestUrl[i]); } } // decode the name file = URLDecoder.decode(filePath.toString(), Fields.CHARSET); if (archive != null && !archive.isEmpty() && file != null && !file.isEmpty()) downloadFile(request, response, user, archive, file); } }