package com.alibaba.dubbo.rpc.protocol.resteasy.support;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.annotation.Priority;
import javax.ws.rs.Priorities;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.netty.util.internal.StringUtil;

/**
 * @author sdcuike
 *
 *         Create At 2016年4月13日 下午3:53:38
 */

@PreMatching
@Priority(Priorities.AUTHENTICATION - 100)
public class VersionRequestFilter implements ContainerRequestFilter {
    private final Logger log = LoggerFactory.getLogger(getClass());
    public static final String HEADER_VERSION = "version";

    @Override
    public void filter(ContainerRequestContext requestContext) throws IOException {
        String version = requestContext.getHeaderString(HEADER_VERSION);
        if (StringUtil.isNullOrEmpty(version)) {
            return;
        }

        URI requestUri = requestContext.getUriInfo().getRequestUri();
        try {
            URI newUri = new URI(requestUri.getScheme(), requestUri.getAuthority(), "/" + version + requestUri.getPath(), requestUri.getQuery(), requestUri.getFragment());
            requestContext.setRequestUri(newUri);

        } catch (URISyntaxException e) {
            log.error("requestContext.setRequestUri error:{}=>{}", version, requestUri);
        }

    }

}

@@ -363,42 +363,86 @@
 ort 
-org.slf4j.Logger;%0Aimport org.slf4j
+com.alibaba.dubbo.common.logger.Logger;%0Aimport com.alibaba.dubbo.common.logger
 .Log
@@ -1439,17 +1439,35 @@
     
-log.error
+String info = String.format
 (%22re
@@ -1503,36 +1503,90 @@
 ror:
-%7B%7D=%3E%7B%7D%22, version, requestUri
+ version%5B%25s%5D=%3ErequestUri%5B%25s%5D%22, version, requestUri);%0A            log.error(info, e
 );%0A 

change logger