2016-05-03 16 views
1

У меня есть конфигурация, которая должна обслуживать параметры запроса и возвращать ответ. Вот моя конфигурация. К сожалению, компонент Service Activator не может быть создан весной.Извлечение множества параметров запроса из входящего шлюза

<int-http:inbound-gateway request-channel="inChannel" 
     reply-channel="outChannel" supported-methods="GET" 
     path="/ticket"> 

     <int-http:request-mapping consumes="text/plain" params="param1,param2,param3" 
      produces="text/plain" /> 
</int-http:inbound-gateway> 

<int:service-activator ref="ticketIssuingService" method="processTicket" 
     input-channel="inChannel" output-channel="outChannel"/> 

@MessageEndpoint 
public class TicketIssuingService { 



    public String processTicket(??? payload){ 
     System.out.println("Query Paramter String is "+payload); 
     return null; 
    } 
} 

http://localhost:8080/job/ticket?param1=type&param2=linkstate&param3=duration

Как я могу получить параметры, так что я могу передать обслуживание методу processTicket? Весна жалуется, что не было найдено подходящих методов. Какими должны быть аргументы для метода processTicket? Пожалуйста, помогите

ответ

2

Для GET метода без payload-expressionpayload из Message<?> для inChannel именно этот объект:

MultiValueMap<String, String> requestParams = this.convertParameterMap(servletRequest.getParameterMap()); 

... 

     if (payload == null) { 
      if (requestBody != null) { 
       payload = requestBody; 
      } 
      else { 
       payload = requestParams; 
      } 
     } 

Таким образом, это должно быть ответом на ваш вопрос о payload типа в методе processTicket службы ,

Обратите внимание, пожалуйста, что вы можете настроить, что payload через payload-expression и используя некоторые встроенные SPEL EvaluationContextvariables как:

#requestParams - the MultiValueMap from the ServletRequest parameterMap. 
#pathVariables - the Map from URI Template placeholders and their values; 
#matrixVariables - the Map of MultiValueMap according to Spring MVC Specification. Note, #matrixVariables require Spring MVC 3.2 or higher; 
#requestAttributes - the org.springframework.web.context.request.RequestAttributes associated with the current Request; 
#requestHeaders - the org.springframework.http.HttpHeaders object from the current Request; 
#cookies - the Map<String, Cookie> of javax.servlet.http.Cookie s from the current Request. 

Некоторые пробы, как это, чтобы получить queryString:

payload-expression="T(org.springframework.web.context.request.RequestContextHolder).requestAttributes.request.queryString" 
+0

Спасибо большое Артем! – BreenDeen

Смежные вопросы