org.codegist.crest.config
Class PropertiesDrivenInterfaceConfigFactory

java.lang.Object
  extended by org.codegist.crest.config.PropertiesDrivenInterfaceConfigFactory
All Implemented Interfaces:
InterfaceConfigFactory

public class PropertiesDrivenInterfaceConfigFactory
extends Object
implements InterfaceConfigFactory

Properties based config factory of any possible interfaces given to the factory.

Usefull when the end-point should be read externally instead, eg for profil (dev,integration,prod)

Expected format for a single Interface config is of the following :

- Any property not specified as mandatory is optional.

- The same logic as the annotation config applies here, config fallbacks from param to method to interface until one config is found, otherwise defaults to any respective default value (InterfaceConfig, MethodConfig, ParamConfig).

 package my.rest.interface;
 class Interface {
     String get();
     String get(String s);
     void push(String s);
 }
 -----------------------------------------------
 service.test.class=my.rest.interface.Interface  #Mandatory if no global server is configured
 # interface specifics configs
 service.test.end-point=http://localhost:8080    #Mandatory if no global server is configured
 service.test.context-path=/my-path
 service.test.encoding=utf-8
 service.test.global-interceptor=my.rest.interceptor.MyRequestInterceptor
 # default interface method configs
 service.test.path=/hello
 service.test.static-param.my-param-name.value=value1
 service.test.static-param.my-param-name.destination=BODY
 service.test.http-method=DELETE
 service.test.socket-timeout=1
 service.test.connection-timeout=2
 service.test.request-interceptor=my.rest.MyRequestHandler2
 service.test.response-handler=my.rest.MyResponseHandler
 service.test.error-handler=my.rest.MyErrorHandler
 service.test.retry-handler=my.rest.MyRetryHandler
 # default method param configs
 service.test.name=name
 service.test.destination=BODY
 service.test.serializer=my.rest.serializer.MyParamSerializer
 service.test.injector=my.rest.injector.MyRequestInjector
 

service.test.method.m1.pattern=get\\(.\*\) #Pattern matching one or more methods. Config will apply to all matched method. Applies to "String get()" amd "String get(String)" # method specifics configs service.test.method.m1.path=/get service.test.method.m1.static-param.my-param-name-2.value=value service.test.method.m1.static-param.my-param-name-2.destination=HEADER service.test.method.m1.http-method=PUT service.test.method.m1.socket-timeout=3 service.test.method.m1.connection-timeout=4 service.test.method.m1.request-interceptor=my.rest.interceptor.MyRequestInterceptor2 service.test.method.m1.response-handler=my.rest.MyResponseHandler2 service.test.method.m1.error-handler=my.rest.MyErrorHandler2 # default param configs service.test.method.m1.name=name1 service.test.method.m1.destination=URL service.test.method.m1.injector=my.rest.injector.MyRequestInjector2 service.test.method.m1.serializer=my.rest.serializer.MyParamSerializer2 # param specific configs service.test.method.m1.params.0.name=a # Param config applies also to all matched method as long as the method as enough param, otherwise is ignored. service.test.method.m1.params.0.destination=URL service.test.method.m1.params.0.serializer=my.rest.serializer.MyParamSerializer3 service.test.method.m1.params.0.injector=my.rest.interceptor.MyRequestInterceptor3

service.test.method.m2.pattern=push\\(\\) service.test.method.m2.path=/push (...) service.test2.class=my.rest.interface.Interface2 (...)

Can contain as much interface config as needed in a single Properties (or Map) object.

A shortcut to configure the server for all interfaces is :

 service.end-point=My server url
 

The interface specific end-point if specified override the global one.

Author:
Laurent Gilles (laurent.gilles@codegist.org)
See Also:
InterfaceConfig

Constructor Summary
PropertiesDrivenInterfaceConfigFactory(Map<String,String> properties)
           
PropertiesDrivenInterfaceConfigFactory(Map<String,String> properties, boolean useDefaults)
           
 
Method Summary
 InterfaceConfig newConfig(Class<?> interfaze, CRestContext context)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PropertiesDrivenInterfaceConfigFactory

public PropertiesDrivenInterfaceConfigFactory(Map<String,String> properties)

PropertiesDrivenInterfaceConfigFactory

public PropertiesDrivenInterfaceConfigFactory(Map<String,String> properties,
                                              boolean useDefaults)
Method Detail

newConfig

public InterfaceConfig newConfig(Class<?> interfaze,
                                 CRestContext context)
                          throws ConfigFactoryException
Specified by:
newConfig in interface InterfaceConfigFactory
Parameters:
interfaze - Interface to build the configuration from
context - Current CRest context
Returns:
The interface config object.
Throws:
ConfigFactoryException - for any problem occuring during the configuration construction
See Also:
InterfaceConfigFactory


Copyright © 2011. All Rights Reserved.