package org.skywalking.apm.plugin.spring.mvc;

import org.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
import org.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * The <code>ControllerConstructorInterceptor</code> intercepts the Controller's constructor, in order to acquire the
 * mapping annotation, if exist.
 *
 * But, you can see we only use the first mapping value, <B>Why?</B>
 *
 * Right now, we intercept the controller by annotation as you known, so we CAN'T know which uri patten is actually
 * matched. Even we know, that costs a lot.
 *
 * If we want to resolve that, we must intercept the Spring MVC core codes, that is not a good choice for now.
 *
 * Comment by @wu-sheng
 */
public class ControllerConstructorInterceptor implements InstanceConstructorInterceptor {

    @Override
    public void onConstruct(EnhancedInstance objInst, Object[] allArguments) {
        String basePath = "";
        RequestMapping basePathRequestMapping = objInst.getClass().getAnnotation(RequestMapping.class);
        if (basePathRequestMapping != null) {
            basePath = basePathRequestMapping.value()[0];
        }
        PathMappingCache pathMappingCache = new PathMappingCache(basePath);
        objInst.setSkyWalkingDynamicField(pathMappingCache);
    }
}

@@ -1197,53 +1197,260 @@
     
-basePath = basePathRequestMapping.value()%5B0%5D;
+if (basePathRequestMapping.value().length %3E 0) %7B%0A                basePath = basePathRequestMapping.value()%5B0%5D;%0A            %7D else if (basePathRequestMapping.path().length %3E 0) %7B%0A                basePath = basePathRequestMapping.path()%5B0%5D;%0A            %7D
 %0A   

fix the operation name of spring mvc span is incorrect