public static String generateApiString ( ApplicationContext ctx , String remotingVarName , String pollingApiVarName ) throws JsonProcessingException { RemotingApi remotingApi = new RemotingApi ( ctx . getBean ( ConfigurationService . class ) . getConfiguration ( ) . getProviderType ( ) , "router" , null ) ; for ( Map . Entry < MethodInfoCache . Key , MethodInfo > entry : ctx . getBean ( MethodInfoCache . class ) ) { MethodInfo methodInfo = entry . getValue ( ) ; if ( methodInfo . getAction ( ) != null ) { remotingApi . addAction ( entry . getKey ( ) . getBeanName ( ) , methodInfo . getAction ( ) ) ; } else if ( methodInfo . getPollingProvider ( ) != null ) { remotingApi . addPollingProvider ( methodInfo . getPollingProvider ( ) ) ; } } remotingApi . sort ( ) ; StringBuilder extDirectConfig = new StringBuilder ( 100 ) ; extDirectConfig . append ( "var " ) . append ( remotingVarName ) . append ( " = " ) ; extDirectConfig . append ( new ObjectMapper ( ) . writer ( ) . withDefaultPrettyPrinter ( ) . writeValueAsString ( remotingApi ) ) ; extDirectConfig . append ( ";" ) ; List < PollingProvider > pollingProviders = remotingApi . getPollingProviders ( ) ; if ( ! pollingProviders . isEmpty ( ) ) { extDirectConfig . append ( "\n\nvar " ) . append ( pollingApiVarName ) . append ( " = {\n" ) ; for ( int i = 0 ; i < pollingProviders . size ( ) ; i ++ ) { extDirectConfig . append ( " \"" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getEvent ( ) ) ; extDirectConfig . append ( "\" : \"poll/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getBeanName ( ) ) ; extDirectConfig . append ( "/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getMethod ( ) ) ; extDirectConfig . append ( "/" ) ; extDirectConfig . append ( pollingProviders . get ( i ) . getEvent ( ) ) ; extDirectConfig . append ( "\"" ) ; if ( i < pollingProviders . size ( ) - 1 ) { extDirectConfig . append ( ",\n" ) ; } } extDirectConfig . append ( "\n};" ) ; } return extDirectConfig . toString ( ) ; }
Returns the api configuration as a String