List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:com.novartis.pcs.ontology.rest.servlet.SynonymsServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String mediaType = getExpectedMediaType(request); String pathInfo = StringUtils.trimToNull(request.getPathInfo()); if (mediaType == null || !MEDIA_TYPE_JSON.equals(mediaType)) { response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); response.setContentLength(0);/*www.j a va 2 s . c o m*/ } else if (pathInfo == null || pathInfo.length() == 1) { response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setContentLength(0); } else { String datasourceAcronym = null; String vocabRefId = null; boolean pending = Boolean.parseBoolean(request.getParameter("pending")); int i = pathInfo.indexOf('/', 1); if (i != -1) { datasourceAcronym = pathInfo.substring(1, i); vocabRefId = pathInfo.substring(i + 1); } else { datasourceAcronym = pathInfo.substring(1); } serialize(datasourceAcronym, vocabRefId, pending, response); } }
From source file:se.vgregion.pubsub.loadtesting.LoadtestingServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // ping publish // wait for notification // response//from w w w . jav a 2 s . c om // error if timeout if (req.getPathInfo().equals("/feed")) { // serve ATOM feed resp.getWriter().write(atom(getFragment(req))); } else { // publish UUID id = UUID.randomUUID(); String publicationUrl = "http://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/feed#" + id; String hubUrl = System.getProperty("hub.url"); if (hubUrl == null) { throw new RuntimeException("System properti hub.url missing"); } try { CountDownLatch latch = new CountDownLatch(1); publications.put(id, latch); HttpPost publication = new HttpPost(hubUrl); List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("hub.mode", "publish")); parameters.add(new BasicNameValuePair("hub.url", publicationUrl)); publication.setEntity(new UrlEncodedFormEntity(parameters)); DefaultHttpClient httpClient = new DefaultHttpClient(); HttpResponse publicationResponse = httpClient.execute(publication); if (publicationResponse.getStatusLine().getStatusCode() == 204) { try { if (latch.await(20000, TimeUnit.MILLISECONDS)) { // all happy, return return; } else { // timeout resp.sendError(591); } } catch (InterruptedException e) { // interrupted resp.sendError(592); } } else { // publication failed resp.sendError(publicationResponse.getStatusLine().getStatusCode(), publicationResponse.getStatusLine().getReasonPhrase()); } } finally { // try to prevent memory leaks publications.remove(id); } } }
From source file:com.nn.cfw.web.security.CustomCsrfPreventionFilter.java
protected String getRequestedPath(HttpServletRequest request) { String path = request.getServletPath(); if (request.getPathInfo() != null) { path = path + request.getPathInfo(); }/*from ww w. j a va2s . c om*/ return path; }
From source file:com.carolinarollergirls.scoreboard.jetty.MediaServlet.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.doPost(request, response); if (request.getPathInfo().equals("/upload")) upload(request, response);/*from ww w. jav a2 s . c o m*/ else if (request.getPathInfo().equals("/download")) download(request, response); else if (request.getPathInfo().equals("/remove")) remove(request, response); else response.sendError(response.SC_NOT_FOUND); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTResources.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { // Extract the uri from which list the resources... String uri = restUtils.extractRepositoryUri(req.getPathInfo()); // "resources" is a REST service path if (uri == null || "resources".equals(uri)) uri = "/"; // Extract the criteria String queryString = req.getParameter("q"); if (queryString == null || queryString.length() == 0) { queryString = null;/*from w w w .j ava 2 s . com*/ } List<String> resourceTypes = new ArrayList<String>(); String[] resourceTypesArray = req.getParameterValues("type"); if (resourceTypesArray != null) { resourceTypes.addAll(Arrays.asList(resourceTypesArray)); } Iterator<String> itr = resourceTypes.iterator(); while (itr.hasNext()) { String resourceType = itr.next(); if (!(resourceType != null && resourceType.length() != 0)) { itr.remove(); } } int limit = 0; if (req.getParameter("limit") != null && req.getParameter("limit").length() > 0) { try { limit = Integer.parseInt(req.getParameter("limit")); if (limit < 0) throw new Exception(); } catch (Throwable ex) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid value set for parameter limit."); return; } } int startIndex = 0; if (req.getParameter("startIndex") != null && req.getParameter("startIndex").length() > 0) { try { startIndex = Integer.parseInt(req.getParameter("startIndex")); if (startIndex < 0) throw new Exception(); } catch (Throwable ex) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid value set for parameter startIndex."); return; } } List list = new ArrayList(); // If not a search, just list the content of the specified folder... if (queryString == null && (resourceTypes.size() == 0)) { list = resourcesListRemoteService.listResources(uri, limit); } else { boolean recursive = false; if (req.getParameter("recursive") != null && (req.getParameter("recursive").equals("1") || req.getParameter("recursive").equalsIgnoreCase("true") || req.getParameter("recursive").equalsIgnoreCase("yes"))) { recursive = true; } //list = service.getResources(criteria, limit, resourceTypes == null ? null : Arrays.asList(resourceTypes)); list = resourcesListRemoteService.getResources(uri, queryString, resourceTypes.size() == 0 ? null : resourceTypes, recursive, limit, startIndex); } StringBuilder xml = new StringBuilder(); Marshaller m = new Marshaller(); xml.append("<resourceDescriptors>\n"); if (list != null && !list.isEmpty()) for (Object rd : list) { // we assume the objects are actually resource descriptors... xml.append(m.writeResourceDescriptor((ResourceDescriptor) rd)); } xml.append("</resourceDescriptors>"); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, xml.toString()); }
From source file:org.terasoluna.gfw.functionaltest.app.exceptionhandling.ExceptionLevelResolverFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { // Workaround for application servers that don't provide getServletPath(), eg. WebSphere Liberty Profile 8.5. String path = request.getServletPath(); if (path == null || path.length() == 0) { path = request.getPathInfo(); }//from w ww. ja v a 2 s . co m if (path.equals("/exceptionhandling/5_1")) { throw new BusinessTestException("n.cc.0000", "Error"); } else if (path.equals("/exceptionhandling/5_2")) { throw new BusinessTestException("a.cc.0000", "Error"); } else if (path.equals("/exceptionhandling/5_3")) { throw new BusinessTestException("d.cc.0000", "Error"); } }
From source file:jp.terasoluna.fw.web.struts.actions.DownloadBLogicAction.java
/** * BLogicResultWebwIuWFNgf?s?B// w w w .j a v a2 s . c om * <p> * NX<code>resultObject</code>???A * _E??[h???s?B * <ul> * <li>{@link AbstractDownloadObject}p?NX??</li> * <li>{@link AbstractDownloadObject}p?NXv?peBP???</li> * </ul> * * @param result BLogicResultCX^X * @param request HTTPNGXg * @param response HTTPX|X * @param mappingEx gANV}bsO */ @Override protected void processBLogicResult(BLogicResult result, HttpServletRequest request, HttpServletResponse response, ActionMappingEx mappingEx) { super.processBLogicResult(result, request, response, mappingEx); if (result.getResultString() != null) { if (log.isWarnEnabled()) { log.warn("result string must not be set. path :" + request.getPathInfo()); } result.setResultString(null); } FileDownloadUtil.download(result.getResultObject(), request, response); }
From source file:org.bedework.timezones.server.MethodBase.java
/** Get the decoded and fixed resource URI * * @param req Servlet request object * @return resourceUri fixed up and split uri * @throws ServletException//from w ww . j a v a 2 s .com */ public ResourceUri getResourceUri(final HttpServletRequest req) throws ServletException { String uri = req.getPathInfo(); if ((uri == null) || (uri.length() == 0)) { /* No path specified - set it to root. */ uri = "/"; } if (debug) { trace("uri: " + uri); } final ResourceUri resourceUri = fixPath(uri); if (debug) { trace("resourceUri: " + resourceUri.uri); } return resourceUri; }
From source file:dk.itst.oiosaml.sp.service.LoginHandler.java
private boolean isForceAuthnEnabled(HttpServletRequest servletRequest, Configuration conf) { String[] urls = conf.getStringArray(Constants.PROP_FORCE_AUTHN_URLS); if (urls == null) return false; String path = servletRequest.getPathInfo(); if (path == null) { path = "/"; }/*from w ww. j ava 2s . co m*/ if (log.isDebugEnabled()) log.debug("ForceAuthn urls: " + Arrays.toString(urls) + "; path: " + path); for (String url : urls) { if (path.matches(url.trim())) { if (log.isDebugEnabled()) log.debug("Requested url " + path + " is in forceauthn list " + Arrays.toString(urls)); return true; } } return false; }
From source file:net.fenyo.mail4hotspot.web.YahooOAuthStep1Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { try {/*from w w w. ja v a2s . co m*/ if (request.getPathInfo().equals("/step1")) { // final String uuid = request.getParameter("uuid"); final String nonce = nonce(); final String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); final String base_string = "GET&" + urlEncode("https://api.login.yahoo.com/oauth/v2/get_request_token") + "&" + urlEncode("oauth_callback=" + urlEncode(base + "yoauth/step2") + "&oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0"); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&", base_string))); final String url = "https://api.login.yahoo.com/oauth/v2/get_request_token?oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_version=1.0&oauth_callback=" + urlEncode(base + "yoauth/step2") + "&oauth_signature=" + urlEncode(hmac(consumer_secret + "&", base_string)); final String reply = Browser.getHtml(url, null); // request_token est URL encoded final String request_token = parseReply("oauth_token", reply); // request_token_secret est URL encoded final String request_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); if (request_token == null || request_token_secret == null) { log.error("token error: token=" + request_token + " - token_secret=" + request_token_secret); return; } map_request_token.put(urlDecode(request_token), urlDecode(request_token_secret)); final String xoauth_request_auth_url = parseReply("xoauth_request_auth_url", reply); log.debug("xoauth_request_auth_url=" + xoauth_request_auth_url); response.setContentType("text/html"); response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); response.setHeader("Location", urlDecode(xoauth_request_auth_url)); final PrintWriter out = response.getWriter(); out.println("<html><body>click <a href='" + urlDecode(xoauth_request_auth_url) + "'>here</a></body></html>"); } if (request.getPathInfo().equals("/step2")) { final String verifier = request.getParameter("oauth_verifier"); // request_token n'est pas URL encoded final String request_token = request.getParameter("oauth_token"); // request_token_secret n'est pas URL encoded final String request_token_secret = map_request_token.get(request_token); log.debug("oauthtoken=" + request_token); log.debug("oauthtokensecret=" + request_token_secret); log.debug("verifier=" + verifier); String nonce = nonce(); String now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); String base_string = "GET&" + urlEncode("https://api.login.yahoo.com/oauth/v2/get_token") + "&" + urlEncode("oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0"); log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string))); String url = "https://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key=" + urlEncode( "dj0yJmk9UmZhMmthTU1EcVExJmQ9WVdrOWIxZEZaMWRGTldNbWNHbzlNVGMyTmprME5qSS0mcz1jb25zdW1lcnNlY3JldCZ4PTc2") + "&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + urlEncode(request_token) + "&oauth_verifier=" + urlEncode(verifier) + "&oauth_version=1.0&oauth_signature=" + urlEncode(hmac(consumer_secret + "&" + request_token_secret, base_string)); final String reply = Browser.getHtml(url, null); // access token est URL encoded final String access_token = parseReply("oauth_token", reply); // access_token_secret est URL encoded final String access_token_secret = parseReply("oauth_token_secret", reply); log.debug("oauthaccesstoken=" + access_token); log.debug("oauthaccesstokensecret=" + access_token_secret); final String xoauth_yahoo_guid = parseReply("xoauth_yahoo_guid", reply); log.debug("xoauth_yahoo_guid=" + xoauth_yahoo_guid); nonce = nonce(); now = now(); log.debug("nonce=" + nonce); log.debug("now=" + now); base_string = "GET&" + urlEncode("https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/") + "&" + urlEncode("oauth_consumer_key=www.vpnoverdns.com&oauth_nonce=" + nonce + "&oauth_signature_method=HMAC-SHA1&oauth_timestamp=" + now + "&oauth_token=" + access_token + "&oauth_version=1.0"); // oauth_token=\"$oauthaccesstoken\",oauth_version=\"1.0\",oauth_signature=\"$digestencoded\"" | read URL log.debug("digestencoded=" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string))); url = "GET https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/ oauth_consumer_key=\"www.vpnoverdns.com\",oauth_nonce=\"" + nonce + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + now + "\",oauth_token=\"" + access_token + "\",oauth_version=\"1.0\",oauth_signature=\"" + urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string)) + "\""; log.debug(org.apache.commons.codec.binary.Base64.encodeBase64String(url.getBytes("UTF-8"))); // String url2 = // "GET https://mail.google.com/mail/b/alexandre.fenyo2@gmail.com/imap/ oauth_consumer_key=\"www.vpnoverdns.com\",oauth_nonce=\"" + // nonce + // "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + // now + // "\",oauth_token=\"" + // access_token + // "\",oauth_version=\"1.0\",oauth_signature=\"" + // urlEncode(hmac(consumer_secret + "&" + urlDecode(access_token_secret), base_string)) +"\""; // log.debug(org.apache.commons.codec.binary.Base64.encodeBase64String(url.getBytes("UTF-8"))); } } catch (InvalidKeyException ex) { log.error(ex.toString()); } catch (NoSuchAlgorithmException ex) { log.error(ex.toString()); } }