List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:org.osiam.resources.controller.UserController.java
private User setLocationUriAndCreateUserForOutput(HttpServletRequest request, HttpServletResponse response, User createdUser) {/*from www . j av a 2 s . c o m*/ String requestUrl = request.getRequestURL().toString(); response.setHeader("Location", requestUrl); Meta newMeta = new Meta.Builder(createdUser.getMeta()).setLocation(requestUrl).build(); return new User.Builder(createdUser).setMeta(newMeta).build(); }
From source file:nl.surfnet.coin.shared.log.ApiCallLogContextListener.java
@Override public void requestInitialized(ServletRequestEvent requestEvent) { ApiCallLog apiCallLog = new ApiCallLog(); HttpServletRequest request = (HttpServletRequest) requestEvent.getServletRequest(); String queryString = request.getQueryString(); StringBuffer requestURL = request.getRequestURL(); if (StringUtils.hasText(queryString)) { requestURL.append("?").append(queryString); }//from ww w .j a va2 s . c o m try { apiCallLog.setResourceUrl(URLEncoder.encode(requestURL.toString(), "utf-8")); apiCallLog.setIpAddress(request.getRemoteAddr()); } catch (UnsupportedEncodingException e) { // will never happen as utf-8 is the encoding } apiCallLogHolder.set(apiCallLog); }
From source file:com.thoughtworks.go.server.controller.PipelineStatusController.java
String getFullContextPath(HttpServletRequest request) throws URIException { String contextPath = request.getContextPath(); StringBuffer url = request.getRequestURL(); URI uri = new URI(url.toString()); uri.setPath(contextPath);//from w ww. j a va 2 s.c om return uri.toString(); }
From source file:net.ljcomputing.core.controler.GlobalExceptionController.java
/** * Handle all no entity found exceptions. * * @param req the req//w w w . ja v a2 s . c o m * @param exception the exception * @return the error info */ @Order(Ordered.HIGHEST_PRECEDENCE) @ExceptionHandler(NoEntityFoundException.class) @ResponseStatus(HttpStatus.NOT_FOUND) public @ResponseBody ErrorInfo handleAllNoEntityFoundExceptions(HttpServletRequest req, Exception exception) { logger.warn("No entity found : {}:", req.getRequestURL().toString()); return new ErrorInfo(getCurrentTimestamp(), HttpStatus.NOT_FOUND, req.getRequestURL().toString(), exception); }
From source file:com.razorfish.controllers.misc.StoreSessionController.java
protected String getReturnRedirectUrlWithoutReferer(final HttpServletRequest request) { final String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath()); if (referer != null && !referer.isEmpty()) { return REDIRECT_PREFIX + referer; }/* w w w .j a va2s . com*/ return REDIRECT_PREFIX + '/'; }
From source file:org.n52.aviation.aviationfx.spring.ExceptionHandlerImpl.java
private ModelAndView createModelAndView(Exception e, HttpServletRequest req) { LOG.warn("Returning exception", e); ModelAndView mav = new ModelAndView(); mav.addObject(DEFAULT_ERROR_VIEW, e.getMessage()); mav.addObject(BACKLINK, req.getRequestURL()); mav.setViewName(DEFAULT_ERROR_VIEW); return mav;/*from w w w . j a va 2 s .co m*/ }
From source file:org.openwms.core.http.AbstractWebController.java
/** * Append the ID of the object that was created to the original request URL and return it. * * @param req The HttpServletRequest object * @param objId The ID to append/* w ww. j av a 2 s .c o m*/ * @return The complete appended URL */ protected String getLocationForCreatedResource(HttpServletRequest req, String objId) { StringBuffer url = req.getRequestURL(); UriTemplate template = new UriTemplate(url.append("/{objId}/").toString()); return template.expand(objId).toASCIIString(); }
From source file:things.view.rest.ThingRestExceptionHandler.java
@ExceptionHandler(NoSuchThingException.class) @ResponseStatus(HttpStatus.NOT_FOUND)//from w w w.j av a 2 s.c o m @ResponseBody public ErrorInfo noSuchThingException(final HttpServletRequest req, final NoSuchThingException ex) { myLogger.debug("NoSuchEntityException: " + ex.getLocalizedMessage(), ex); return new ErrorInfo(req.getRequestURL().toString(), ex); }
From source file:org.apache.hadoop.gateway.hdfs.dispatch.WebHdfsHaHttpClientDispatchTest.java
@Test public void testConnectivityFailover() throws Exception { String serviceName = "WEBHDFS"; HaDescriptor descriptor = HaDescriptorFactory.createDescriptor(); descriptor.addServiceConfig(/*ww w.java 2 s .c o m*/ HaDescriptorFactory.createServiceConfig(serviceName, "true", "1", "1000", "2", "1000")); HaProvider provider = new DefaultHaProvider(descriptor); URI uri1 = new URI("http://unreachable-host"); URI uri2 = new URI("http://reachable-host"); ArrayList<String> urlList = new ArrayList<String>(); urlList.add(uri1.toString()); urlList.add(uri2.toString()); provider.addHaService(serviceName, urlList); FilterConfig filterConfig = EasyMock.createNiceMock(FilterConfig.class); ServletContext servletContext = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(filterConfig.getInitParameter(WebHdfsHaHttpClientDispatch.RESOURCE_ROLE_ATTRIBUTE)) .andReturn(serviceName).anyTimes(); EasyMock.expect(filterConfig.getServletContext()).andReturn(servletContext).anyTimes(); EasyMock.expect(servletContext.getAttribute(HaServletContextListener.PROVIDER_ATTRIBUTE_NAME)) .andReturn(provider).anyTimes(); BasicHttpParams params = new BasicHttpParams(); HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpRequestBase.class); EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes(); EasyMock.expect(outboundRequest.getURI()).andReturn(uri1).anyTimes(); EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes(); HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(inboundRequest.getRequestURL()).andReturn(new StringBuffer(uri2.toString())).once(); EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(0)) .once(); EasyMock.expect(inboundRequest.getAttribute("dispatch.ha.failover.counter")).andReturn(new AtomicInteger(1)) .once(); HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.expect(outboundResponse.getOutputStream()).andAnswer(new IAnswer<ServletOutputStream>() { @Override public ServletOutputStream answer() throws Throwable { return new ServletOutputStream() { @Override public void write(int b) throws IOException { throw new IOException("unreachable-host"); } }; } }).once(); EasyMock.replay(filterConfig, servletContext, outboundRequest, inboundRequest, outboundResponse); Assert.assertEquals(uri1.toString(), provider.getActiveURL(serviceName)); WebHdfsHaHttpClientDispatch dispatch = new WebHdfsHaHttpClientDispatch(); dispatch.init(filterConfig); long startTime = System.currentTimeMillis(); try { dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse); } catch (IOException e) { //this is expected after the failover limit is reached } long elapsedTime = System.currentTimeMillis() - startTime; Assert.assertEquals(uri2.toString(), provider.getActiveURL(serviceName)); //test to make sure the sleep took place Assert.assertTrue(elapsedTime > 1000); }
From source file:nl.dtls.fairdatapoint.api.controller.MetadataController.java
@ApiOperation(value = "Dataset metadata") @RequestMapping(value = "/{catalogID}/{datasetID}", method = RequestMethod.GET, produces = { "text/turtle", "application/ld+json", "application/rdf+xml", "text/n3" }) public String getDatasetMetaData(@PathVariable final String catalogID, @PathVariable final String datasetID, HttpServletRequest request, HttpServletResponse response) { LOGGER.info("Request to get DATASET metadata {}", catalogID); LOGGER.info("GET : " + request.getRequestURL()); String responseBody;//from ww w .j a v a 2 s . c om String contentType = request.getHeader(HttpHeaders.ACCEPT); RDFFormat requesetedContentType = HttpHeadersUtils.getRequestedAcceptHeader(contentType); try { responseBody = fairMetaDataService.retrieveDatasetMetaData(catalogID, datasetID, requesetedContentType); HttpHeadersUtils.set200ResponseHeaders(responseBody, response, requesetedContentType); } catch (FairMetadataServiceException ex) { responseBody = HttpHeadersUtils.set500ResponseHeaders(response, ex); } LoggerUtils.logRequest(LOGGER, request, response); return responseBody; }