List of usage examples for org.springframework.http.server ServletServerHttpRequest ServletServerHttpRequest
public ServletServerHttpRequest(HttpServletRequest servletRequest)
From source file:com.epam.ta.reportportal.ws.controller.impl.UserController.java
@Override @RequestMapping(method = POST)/*from w w w. j a v a 2s. c o m*/ @ResponseBody @ResponseStatus(CREATED) @PreAuthorize(ADMIN_ONLY) @ApiOperation("Create specified user") public CreateUserRS createUserByAdmin(@RequestBody @Validated CreateUserRQFull rq, Principal principal, HttpServletRequest request) { String basicURL = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)) .replacePath(null).replaceQuery(null).build().toUriString(); return createUserMessageHandler.createUserByAdmin(rq, principal.getName(), basicURL); }
From source file:com.sybase365.mobiliser.custom.project.channels.HttpChannelEnd.java
@SuppressWarnings("unchecked") @Override/* w w w.j a v a 2 s. co m*/ public void processRequest(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException { LOG.debug("Incoming {} request", request.getMethod()); checkAndPrepare(request, response, false); final MultiValueMap<String, String> result = (MultiValueMap<String, String>) this.converter.read(null, new ServletServerHttpRequest(request)); final List<String> textList = result.get("text"); final List<String> fromList = result.get("from"); final List<String> toList = result.get("to"); final List<String> typeList = result.get("type"); if (textList == null || textList.isEmpty()) { throw new MissingServletRequestParameterException("text", "string"); } if (fromList == null || fromList.isEmpty()) { throw new MissingServletRequestParameterException("from", "string"); } if (toList == null || toList.isEmpty()) { throw new MissingServletRequestParameterException("to", "string"); } final String type; if (null == typeList || typeList.isEmpty()) { type = "sms"; } else { type = typeList.get(0); } final Message req = this.messagingEngine.parseSimpleTextMessage(type, textList.get(0)); req.setSender(fromList.get(0)); req.setRecipient(toList.get(0)); if (LOG.isDebugEnabled()) { LOG.debug("{} message received for {} from {}", new Object[] { type, req.getRecipient(), req.getSender() }); } final Future<Message> responseMessage = this.receiveCallback.receiveAndRespondMessage(req, this.channelId, this.incomingChannelId); if (LOG.isDebugEnabled()) { LOG.debug("Handed off message to {} for {} awaiting response", this.receiveCallback, this.incomingChannelId); } final Message message; try { message = responseMessage.get(); if (message == null) { LOG.warn("Timed out waiting for response from {}", responseMessage); throw new NestedServletException("Timed out waiting for message"); } } catch (final InterruptedException e) { Thread.currentThread().interrupt(); // reset flag throw new NestedServletException("Interrupted during processing", e); } catch (final ExecutionException e) { if (e.getCause() instanceof InterruptedException) { throw new NestedServletException( // NOSONAR "Interrupted during processing", e.getCause()); } throw new NestedServletException("Processing message failed", // NOSONAR e.getCause()); } LOG.debug("Writing response back to client"); final LinkedMultiValueMap<String, Object> responseMap = new LinkedMultiValueMap<String, Object>(); responseMap.add("from", message.getSender().getAddress()); responseMap.add("to", message.getRecipient().getAddress()); if (message instanceof SmsMessage) { responseMap.add("text", new String(((SmsMessage) message).getText().getContent(), ((SmsMessage) message).getText().getCharset())); } else if (message instanceof UssdTextMessage) { responseMap.add("text", new String(((UssdTextMessage) message).getText().getContent(), ((UssdTextMessage) message).getText().getCharset())); } this.converter.write(responseMap, this.mediaType, new ServletServerHttpResponse(response)); }
From source file:org.makersoft.mvc.method.annotation.FormatHandlerMethodReturnValueHandler.java
/** * Creates a new {@link HttpInputMessage} from the given {@link NativeWebRequest}. * * @param webRequest the web request to create an input message from * @return the input message/* www.ja v a 2s . com*/ */ protected ServletServerHttpRequest createInputMessage(NativeWebRequest webRequest) { HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); return new ServletServerHttpRequest(servletRequest); }
From source file:com.epam.ta.reportportal.ws.controller.impl.UserController.java
@Override @RequestMapping(value = "/bid", method = POST) @ResponseBody//from w ww . jav a 2 s . c o m @ResponseStatus(CREATED) @PreAuthorize("hasPermission(#createUserRQ.getDefaultProject(), 'projectLeadPermission')") @ApiOperation("Register invitation for user who will be created") public CreateUserBidRS createUserBid(@RequestBody @Validated CreateUserRQ createUserRQ, Principal principal, HttpServletRequest request) { /* * Use Uri components since they are aware of x-forwarded-host headers */ URI rqUrl = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)).replacePath(null) .replaceQuery(null).build().toUri(); return createUserMessageHandler.createUserBid(createUserRQ, principal, rqUrl.toASCIIString()); }
From source file:com.epam.ta.reportportal.commons.exception.rest.RestExceptionHandler.java
@SuppressWarnings({ "rawtypes", "unchecked", "resource" }) private ModelAndView handleResponseBody(Object body, ServletWebRequest webRequest) throws HttpMessageNotWritableException, IOException { HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest()); List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept(); if (acceptedMediaTypes.isEmpty()) { acceptedMediaTypes = Collections.singletonList(MediaType.ALL); }/*from w ww .j av a 2 s . c o m*/ MediaType.sortByQualityValue(acceptedMediaTypes); HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse()); Class<?> bodyType = body.getClass(); List<HttpMessageConverter<?>> converters = this.messageConverters; if (converters != null) { for (MediaType acceptedMediaType : acceptedMediaTypes) { for (HttpMessageConverter messageConverter : converters) { if (messageConverter.canWrite(bodyType, acceptedMediaType)) { messageConverter.write(body, acceptedMediaType, outputMessage); // return empty model and view to short circuit the // iteration and to let // Spring know that we've rendered the view ourselves: return new ModelAndView(); } } } } if (logger.isWarnEnabled()) { logger.warn("Could not find HttpMessageConverter that supports return type [" + bodyType + "] and " + acceptedMediaTypes); } return null; }
From source file:org.ayfaar.app.spring.handler.RestExceptionHandler.java
@SuppressWarnings("unchecked") protected ModelAndView handleResponseBody(Object body, ServletWebRequest webRequest) throws ServletException, IOException { HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest()); List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept(); if (acceptedMediaTypes.isEmpty()) { acceptedMediaTypes = Collections.singletonList(MediaType.ALL); }/*from w w w . j a v a 2s .co m*/ MediaType.sortByQualityValue(acceptedMediaTypes); HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse()); Class<?> bodyType = body.getClass(); List<HttpMessageConverter<?>> converters = this.allMessageConverters; if (converters != null) { for (MediaType acceptedMediaType : acceptedMediaTypes) { for (HttpMessageConverter messageConverter : converters) { if (messageConverter.canWrite(bodyType, acceptedMediaType)) { messageConverter.write(body, acceptedMediaType, outputMessage); //return empty model and view to short circuit the iteration and to let //Spring know that we've rendered the view ourselves: return new ModelAndView(); } } } } if (logger.isWarnEnabled()) { logger.warn("Could not find HttpMessageConverter that supports return type [" + bodyType + "] and " + acceptedMediaTypes); } return null; }
From source file:org.springframework.data.rest.webmvc.config.PersistentEntityResourceHandlerMethodArgumentResolver.java
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { RootResourceInformation resourceInformation = resourceInformationResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); HttpServletRequest nativeRequest = webRequest.getNativeRequest(HttpServletRequest.class); ServletServerHttpRequest request = new ServletServerHttpRequest(nativeRequest); IncomingRequest incoming = new IncomingRequest(request); Class<?> domainType = resourceInformation.getDomainType(); MediaType contentType = request.getHeaders().getContentType(); for (HttpMessageConverter converter : messageConverters) { if (!converter.canRead(PersistentEntityResource.class, contentType)) { continue; }/*w ww . j a v a 2 s. c om*/ Serializable id = idResolver.resolveArgument(parameter, mavContainer, webRequest, binderFactory); Object objectToUpdate = getObjectToUpdate(id, resourceInformation); boolean forUpdate = false; Object entityIdentifier = null; PersistentEntity<?, ?> entity = resourceInformation.getPersistentEntity(); if (objectToUpdate != null) { forUpdate = true; entityIdentifier = entity.getIdentifierAccessor(objectToUpdate).getIdentifier(); } Object obj = read(resourceInformation, incoming, converter, objectToUpdate); if (obj == null) { throw new HttpMessageNotReadableException(String.format(ERROR_MESSAGE, domainType)); } if (entityIdentifier != null) { entity.getPropertyAccessor(obj).setProperty(entity.getIdProperty(), entityIdentifier); } Builder build = PersistentEntityResource.build(obj, entity); return forUpdate ? build.build() : build.forCreation(); } throw new HttpMessageNotReadableException(String.format(NO_CONVERTER_FOUND, domainType, contentType)); }
From source file:it.unitn.disi.smatch.web.server.api.handlers.ExceptionDetailsExceptionResolver.java
@SuppressWarnings("unchecked") private ModelAndView handleResponseBody(Object body, ServletWebRequest webRequest) throws ServletException, IOException { HttpInputMessage inputMessage = new ServletServerHttpRequest(webRequest.getRequest()); List<MediaType> acceptedMediaTypes = inputMessage.getHeaders().getAccept(); if (acceptedMediaTypes.isEmpty()) { acceptedMediaTypes = Collections.singletonList(MediaType.ALL); }//from w w w . jav a 2 s. c o m MediaType.sortByQualityValue(acceptedMediaTypes); HttpOutputMessage outputMessage = new ServletServerHttpResponse(webRequest.getResponse()); Class<?> bodyType = body.getClass(); List<HttpMessageConverter<?>> converters = this.allMessageConverters; if (converters != null) { for (MediaType acceptedMediaType : acceptedMediaTypes) { for (HttpMessageConverter messageConverter : converters) { if (messageConverter.canWrite(bodyType, acceptedMediaType)) { messageConverter.write(body, acceptedMediaType, outputMessage); //return empty model and view to short circuit the iteration and to let //Spring know that we've rendered the view ourselves: return new ModelAndView(); } } } } if (logger.isWarnEnabled()) { logger.warn("Could not find HttpMessageConverter that supports return type [" + bodyType + "] and " + acceptedMediaTypes); } return null; }
From source file:com.epam.ta.reportportal.ws.controller.impl.UserController.java
@Override @RequestMapping(value = "/password/restore", method = POST) @ResponseStatus(OK)/*from www . j a va 2 s . c o m*/ @ResponseBody @ApiOperation("Create a restore password request") public OperationCompletionRS restorePassword(@RequestBody @Validated RestorePasswordRQ rq, HttpServletRequest request) { /* * Use Uri components since they are aware of x-forwarded-host headers */ String baseUrl = UriComponentsBuilder.fromHttpRequest(new ServletServerHttpRequest(request)) .replacePath(null).replaceQuery(null).build().toUriString(); return createUserMessageHandler.createRestorePasswordBid(rq, baseUrl); }
From source file:com.epam.ta.reportportal.events.handler.LaunchFinishedEventHandler.java
/** * Try to send email when it is needed//from w ww. j a v a2 s .c om * * @param launch Launch to be used * @param project Project to be used * @param emailService Mail Service */ void sendEmailRightNow(Launch launch, Project project, EmailService emailService) { ProjectEmailConfig projectConfig = project.getConfiguration().getEmailConfig(); for (EmailSenderCase one : projectConfig.getEmailCases()) { Optional<SendCase> option = SendCase.findByName(one.getSendCase()); boolean successRate = isSuccessRateEnough(launch, option.get()); boolean matchedNames = isLaunchNameMatched(launch, one); boolean matchedTags = isTagsMatched(launch, one); List<String> recipients = one.getRecipients(); if (successRate && matchedNames && matchedTags) { String[] recipientsArray = findRecipients(launch.getUserRef(), recipients); try { /* Update with static Util resources provider */ String basicURL = UriComponentsBuilder .fromHttpRequest(new ServletServerHttpRequest(currentRequest.get())) .replacePath(String.format("/#%s/launches/all/", project.getName())).build() .toUriString(); emailService.sendLaunchFinishNotification(recipientsArray, basicURL + launch.getId(), launch, project.getConfiguration()); } catch (Exception e) { LOGGER.error("Unable to send email. Error: \n{}", e); } } } }