Search in sources :

Example 1 with ApiDescription

use of com.navercorp.pinpoint.common.util.ApiDescription in project pinpoint by naver.

the class ApiDescriptionParserTest method parseNoArgs.

@Test
public void parseNoArgs() {
    String api = "a.StandardHostValve.invoke()";
    ApiDescription result = apiParser.parse(api);
    Assert.assertEquals("a.StandardHostValve", result.getClassName());
    Assert.assertEquals("StandardHostValve", result.getSimpleClassName());
    Assert.assertEquals("a", result.getPackageNameName());
    Assert.assertEquals("invoke", result.getMethodName());
    Assert.assertEquals("invoke()", result.getSimpleMethodDescription());
    Assert.assertEquals("StandardHostValve", result.getSimpleClassName());
    Assert.assertArrayEquals(new String[] {}, result.getSimpleParameter());
}
Also used : ApiDescription(com.navercorp.pinpoint.common.util.ApiDescription) Test(org.junit.Test)

Example 2 with ApiDescription

use of com.navercorp.pinpoint.common.util.ApiDescription in project pinpoint by naver.

the class ApiDescriptionParserTest method parse.

@Test
public void parse() {
    // org.springframework.web.servlet.FrameworkServlet.doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
    // com.mysql.jdbc.ConnectionImpl.setAutoCommit(boolean autoCommitFlag)
    // com.mysql.jdbc.ConnectionImpl.commit()
    // org.apache.catalina.core.StandardHostValve.invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response):110
    String api = "a.StandardHostValve.invoke(b.Request request, b.Response response)";
    ApiDescription result = apiParser.parse(api);
    Assert.assertEquals("a.StandardHostValve", result.getClassName());
    Assert.assertEquals("StandardHostValve", result.getSimpleClassName());
    Assert.assertEquals("a", result.getPackageNameName());
    Assert.assertEquals("invoke", result.getMethodName());
    Assert.assertEquals("invoke(Request request, Response response)", result.getSimpleMethodDescription());
    Assert.assertEquals("StandardHostValve", result.getSimpleClassName());
    Assert.assertArrayEquals(new String[] { "Request request", "Response response" }, result.getSimpleParameter());
}
Also used : ApiDescription(com.navercorp.pinpoint.common.util.ApiDescription) Test(org.junit.Test)

Example 3 with ApiDescription

use of com.navercorp.pinpoint.common.util.ApiDescription in project pinpoint by naver.

the class RecordFactory method getApi.

private Api getApi(final SpanAlign align) {
    final AnnotationBo annotation = AnnotationUtils.findAnnotationBo(align.getAnnotationBoList(), AnnotationKey.API_METADATA);
    if (annotation != null) {
        final Api api = new Api();
        final ApiMetaDataBo apiMetaData = (ApiMetaDataBo) annotation.getValue();
        String apiInfo = getApiInfo(apiMetaData);
        api.setTitle(apiInfo);
        api.setDescription(apiInfo);
        if (apiMetaData.getMethodTypeEnum() == MethodTypeEnum.DEFAULT) {
            try {
                ApiDescription apiDescription = apiDescriptionParser.parse(api.description);
                api.setTitle(apiDescription.getSimpleMethodDescription());
                api.setClassName(apiDescription.getSimpleClassName());
            } catch (Exception e) {
                logger.debug("Failed to api parse. {}", api.description, e);
            }
        }
        api.setMethodTypeEnum(apiMetaData.getMethodTypeEnum());
        return api;
    } else {
        final Api api = new Api();
        AnnotationKey apiMetaDataError = getApiMetaDataError(align.getAnnotationBoList());
        api.setTitle(apiMetaDataError.getName());
        return api;
    }
}
Also used : AnnotationBo(com.navercorp.pinpoint.common.server.bo.AnnotationBo) AnnotationKey(com.navercorp.pinpoint.common.trace.AnnotationKey) ApiMetaDataBo(com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo) ApiDescription(com.navercorp.pinpoint.common.util.ApiDescription)

Example 4 with ApiDescription

use of com.navercorp.pinpoint.common.util.ApiDescription in project pinpoint by naver.

the class ApiDescriptionParser method parse.

//  org.springframework.web.servlet.FrameworkServlet.doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
// com.mysql.jdbc.ConnectionImpl.setAutoCommit(boolean autoCommitFlag)
//        com.mysql.jdbc.ConnectionImpl.commit()
// org.apache.catalina.core.StandardHostValve.invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response):110
public ApiDescription parse(String apiDescriptionString) {
    if (apiDescriptionString == null) {
        throw new NullPointerException("apiDescriptionString must not be null");
    }
    final int methodStart = apiDescriptionString.lastIndexOf(METHOD_PARAM_START);
    if (methodStart == -1) {
        throw new IllegalArgumentException("'(' not found. invalid apiDescriptionString:" + apiDescriptionString);
    }
    final int methodEnd = apiDescriptionString.lastIndexOf(METHOD_PARAM_END);
    if (methodEnd == -1) {
        throw new IllegalArgumentException("')' not found. invalid apiDescriptionString:" + apiDescriptionString);
    }
    final int classIndex = apiDescriptionString.lastIndexOf(DOT, methodStart);
    if (classIndex == -1) {
        throw new IllegalArgumentException("'.' not found. invalid apiDescriptionString:" + apiDescriptionString);
    }
    String className = parseClassName(apiDescriptionString, classIndex);
    ApiDescription api = new DefaultApiDescription();
    api.setClassName(className);
    String methodName = parseMethodName(apiDescriptionString, methodStart, classIndex);
    api.setMethodName(methodName);
    String parameterDescriptor = apiDescriptionString.substring(methodStart + 1, methodEnd);
    String[] parameterList = parseParameter(parameterDescriptor);
    String[] simpleParameterList = parseSimpleParameter(parameterList);
    api.setSimpleParameter(simpleParameterList);
    int lineIndex = apiDescriptionString.lastIndexOf(':');
    // TODO for now, check and display the lineNumber
    if (lineIndex != -1) {
        try {
            int line = Integer.parseInt(apiDescriptionString.substring(lineIndex + 1, apiDescriptionString.length()));
            api.setLine(line);
        } catch (NumberFormatException e) {
            LoggerFactory.getLogger(this.getClass()).warn("line number parse error {}", e);
        }
    }
    return api;
}
Also used : DefaultApiDescription(com.navercorp.pinpoint.common.util.DefaultApiDescription) DefaultApiDescription(com.navercorp.pinpoint.common.util.DefaultApiDescription) ApiDescription(com.navercorp.pinpoint.common.util.ApiDescription)

Example 5 with ApiDescription

use of com.navercorp.pinpoint.common.util.ApiDescription in project pinpoint by naver.

the class ApiDescriptionParserTest method parseTag.

@Test
public void parseTag() {
    final String apiDescriptionString = ".Tomcat Servlet Process()";
    ApiDescription result = apiParser.parse(apiDescriptionString);
    logger.debug(result.getSimpleMethodDescription());
    logger.debug(result.getSimpleClassName());
}
Also used : ApiDescription(com.navercorp.pinpoint.common.util.ApiDescription) Test(org.junit.Test)

Aggregations

ApiDescription (com.navercorp.pinpoint.common.util.ApiDescription)6 Test (org.junit.Test)4 AnnotationBo (com.navercorp.pinpoint.common.server.bo.AnnotationBo)1 ApiMetaDataBo (com.navercorp.pinpoint.common.server.bo.ApiMetaDataBo)1 AnnotationKey (com.navercorp.pinpoint.common.trace.AnnotationKey)1 DefaultApiDescription (com.navercorp.pinpoint.common.util.DefaultApiDescription)1