These are chat archives for spring-cloud/spring-cloud

17th
May 2017
Adam Wang
@Adamyuanyuan
May 17 2017 07:06
hi,can I add a parameter for each request in zuul?
we need generate a uuid for each microservices as a parameter, I want add this uuid in zuul's pre filter, but my microservices could not receive this parameter /(ㄒoㄒ)/~~
Dave Syer
@dsyer
May 17 2017 07:33
You can add a filter (just add a @Bean)
Adam Wang
@Adamyuanyuan
May 17 2017 07:54
@Override
public Object run() {
    RequestContext ctx = RequestContext.getCurrentContext();
    HttpServletRequest request = ctx.getRequest();
    logger.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
    String userId = request.getParameter("uid");
    String requestUrl = request.getRequestURL().toString();
    Long currentTime = System.currentTimeMillis();
    /*
    http://Adam-PC:8201/business/wzfw/roaming-destination
    userId_business_wzfw_roaming-destination_uuid
     */
    String openId = userId + "_" + requestUrl + currentTime;
    logger.info(openId);
    System.out.println(openId);
// ctx.addZuulRequestHeader("id", openId);
request.setAttribute("id", openId);
System.out.println(request);
return null;
}
```
    @Override
    public Object run() {
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        logger.info(String.format("%s request to %s", request.getMethod(), request.getRequestURL().toString()));
        String userId = request.getParameter("uid");
        String requestUrl = request.getRequestURL().toString();
        Long currentTime = System.currentTimeMillis();
        /*
        http://Adam-PC:8201/business/wzfw/roaming-destination
        userId_business_wzfw_roaming-destination_uuid
         */
        String openId = userId + "_" + requestUrl + currentTime;
        logger.info(openId);
        System.out.println(openId);
//        ctx.addZuulRequestHeader("id", openId);
        request.setAttribute("id", openId);
        System.out.println(request);
        return null;
    }
this is my filter , I want add a new parameter for each microservices , but it could't work
Dave Syer
@dsyer
May 17 2017 08:01
What do you mean by "add a new parameter"?
Adam Wang
@Adamyuanyuan
May 17 2017 08:39
such as : my /add?a=2&b=5&id=a12345, and user just send to getway /add?a=2&b=5
id is a new parameter generated by getway
Dave Syer
@dsyer
May 17 2017 08:42
So you need to add a query parameter to the outgoing URL?
Adam Wang
@Adamyuanyuan
May 17 2017 08:44
yes
Dave Syer
@dsyer
May 17 2017 08:45
Maybe look at com.netflix.zuul.context.RequestContext.setRequestQueryParams(Map<String, List<String>>)
Adam Wang
@Adamyuanyuan
May 17 2017 08:46
thank you sincerely, I will have a try~
Adam Wang
@Adamyuanyuan
May 17 2017 09:10
thanks, just use this : ctx.getRequestQueryParams().put("id", Arrays.asList(openId));
Charles Moulliard
@cmoulliard
May 17 2017 16:32
Hi
Does it make sense that we upgrade the versions --> spring-cloud-incubator/spring-cloud-kubernetes#82 ?