|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codegist.crest.CRestBuilder
public class CRestBuilder
The default build :
CRest crest = new CRestBuilder().build();
will create CRest
with the following features :
- Annotation driven configuration handled by AnnotationDrivenInterfaceConfigFactory
, lookup for annotation in package org.codegist.crest.annotate
.
- Raw response return, meaning the given interface method return type must be either java.io.String, java.io.InputStream or java.io.Reader.
- HTTP calls handled by DefaultRestService
- Uses JDK dynamics proxies to instanciates given interfaces
This default configuration has the benefit to not require any third party dependencies, but is not the recommanded one.
For best performances, it is recommended to use the CGLib proxy factory, CglibProxyFactory
(requires cglib available in the classpath) and the apache http client backed rest service HttpClientRestService
, see useHttpClientRestService()
.
AnnotationDrivenInterfaceConfigFactory
,
PropertiesDrivenInterfaceConfigFactory
,
DefaultRestService
,
HttpClientRestService
,
CglibProxyFactory
,
JdkProxyFactory
,
DefaultCRest
Constructor Summary | |
---|---|
CRestBuilder()
|
Method Summary | |
---|---|
CRestBuilder |
addProperties(Map<String,Object> customProperties)
Adds all custom properties every services build with the resulting CRest instance will be passed. |
CRest |
build()
|
CRestBuilder |
expectsJson()
Resulting CRest instance will create interface instances that will auto marshall the response from JSON to user object model. |
CRestBuilder |
expectsXml(Class<?> factory)
Resulting CRest instance will create interface instances that will auto marshall the response from XML to user object model. |
CRestBuilder |
expectsXml(String modelPackageName)
Resulting CRest instance will create interface instances that will auto marshall the response from XML to user object model. |
CRestBuilder |
overrideDefaultConfigWith(Document document)
Resulting CRest instance will overrides any configuration resulting from its current InterfaceConfigFactory with the given xml configuration. |
CRestBuilder |
overrideDefaultConfigWith(InterfaceConfigFactory overridesFactory)
Resulting CRest instance will overrides any configuration resulting from its internal InterfaceConfigFactory with the configuration issued by the given overridesFactory. |
CRestBuilder |
overrideDefaultConfigWith(Map<String,String> props)
Resulting CRest instance will overrides any configuration resulting from its current InterfaceConfigFactory with the given properties. |
CRestBuilder |
returnRawResults()
Resulting CRest instance will create interface instances that will return raw response. |
CRestBuilder |
setBooleanSerializer(String trueSerialized,
String falseSerialized)
Sets how boolean should be serialized. |
CRestBuilder |
setDateSerializerFormat(String format)
Sets date serializer format to the given format. |
CRestBuilder |
setListSerializerSeparator(String sep)
Sets the list separator for the list serializer |
CRestBuilder |
setProperties(Map<String,Object> customProperties)
Sets a custom properties every services build with the resulting CRest instance will be passed. |
CRestBuilder |
setProperty(String name,
Object value)
Sets a custom property every services build with the resulting CRest instance will be passed. |
CRestBuilder |
setRestService(RestService restService)
Overrides the rest service every services build with the resulting CRest instance will use. |
CRestBuilder |
setSerializer(Type type,
Serializer serializer)
Sets a custom serializer for the given type the resulting CRest instance will use to serialize method arguments. |
CRestBuilder |
useCglibProxies()
Resulting CRest instance will use cglib proxies to build interface instances. |
CRestBuilder |
useHttpClientRestService()
Resulting CRest instance's RestService will be a single threaded instance of HttpClientRestService . |
CRestBuilder |
useHttpClientRestService(int maxConnections)
Resulting CRest instance's RestService will be a multi-threaded instance of HttpClientRestService . |
CRestBuilder |
useHttpClientRestService(int maxConnections,
int maxConnectionsPerRoute)
Resulting CRest instance's RestService will be a multi-threaded instance of HttpClientRestService . |
CRestBuilder |
useJdkProxies()
Resulting CRest instance will use native jdk proxies to build interface instances. |
CRestBuilder |
usePreauthentifiedOAuth(String consumerKey,
String consumerSecret,
String accessToken,
String accessTokenSecret)
Authentification parameters are added to the request headers. |
CRestBuilder |
usePreauthentifiedOAuth(String consumerKey,
String consumerSecret,
String accessToken,
String accessTokenSecret,
boolean authParamsInHeaders)
Resulting CRest instance will authentify every requests using OAuth (http://oauth.net/) authentification mechanism, using a pre-authentified access token and consumer information. |
CRestBuilder |
withAnnotatedConfig()
Resulting CRest instance will handle annotated configurated interfaces. |
CRestBuilder |
withPropertiesConfig(Map<String,String> props)
Resulting CRest instance will handle properties based configuration. |
CRestBuilder |
withXmlConfig(Document document)
Resulting CRest instance will handle xml based configuration. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CRestBuilder()
Method Detail |
---|
public CRest build()
public CRestBuilder useHttpClientRestService()
HttpClientRestService
.
HttpClientRestService
public CRestBuilder useHttpClientRestService(int maxConnections)
HttpClientRestService
.
maxConnections
- max concurrent connections (includes max connection per route as well)
HttpClientRestService
public CRestBuilder useHttpClientRestService(int maxConnections, int maxConnectionsPerRoute)
HttpClientRestService
.
maxConnections
- max concurrent connectionsmaxConnectionsPerRoute
- max connection per route
HttpClientRestService
public CRestBuilder setRestService(RestService restService)
restService
- rest service instance
public CRestBuilder setProperty(String name, Object value)
name
- property keyvalue
- property value
InterfaceContext.getProperties()
public CRestBuilder setSerializer(Type type, Serializer serializer)
The given type reflects the given Interface type, polymorphism is not considered.
type
- Type to seralizeserializer
- Serializer
InterfaceContext.getProperties()
public CRestBuilder addProperties(Map<String,Object> customProperties)
customProperties
- properties map
InterfaceContext.getProperties()
public CRestBuilder setProperties(Map<String,Object> customProperties)
customProperties
- properties map
InterfaceContext.getProperties()
public CRestBuilder withAnnotatedConfig()
AnnotationDrivenInterfaceConfigFactory
public CRestBuilder withPropertiesConfig(Map<String,String> props)
Given properties must be able to configure any possible interface given to the resulting CRest instance.
props
- configuration properties
public CRestBuilder withXmlConfig(Document document)
Given xml must be able to configure any possible interface given to the resulting CRest instance.
document
- xml configuration document
public CRestBuilder overrideDefaultConfigWith(Map<String,String> props)
InterfaceConfigFactory
with the given properties.
Properties must be formatted as documentated in PropertiesDrivenInterfaceConfigFactory
Can be used for instance to override the server end-point for differents devs environment.
props
- properties
PropertiesDrivenInterfaceConfigFactory
public CRestBuilder overrideDefaultConfigWith(Document document)
InterfaceConfigFactory
with the given xml configuration.
Document must be formatted as documentated in XmlDrivenInterfaceConfigFactory
Can be used for instance to override the server end-point for differents devs environment.
document
- xml configuration
XmlDrivenInterfaceConfigFactory
public CRestBuilder overrideDefaultConfigWith(InterfaceConfigFactory overridesFactory)
InterfaceConfigFactory
with the configuration issued by the given overridesFactory.
This factory is meant to returns template configs, thus can return configuration with null values that will be interpreted as fallbacking to the current InterfaceConfigFactory
.
overridesFactory
- config overrider factory
public CRestBuilder expectsJson()
Interfaces given to the CRest instance can return any object type as long as the marshaller can unmarshall them. (requires jackson available in the classpath)
JacksonMarshaller
public CRestBuilder returnRawResults()
Given interface methods return types must be either java.lang.String, java.io.Reader or java.io.InputStream
public CRestBuilder expectsXml(Class<?> factory)
Interface given to the CRest instance can return any object type as long as the marshaller can unmarshall them.
factory
- The JAXb user object model factory class
JaxbMarshaller
public CRestBuilder expectsXml(String modelPackageName)
Interface given to the CRest instance can return any object type as long as the marshaller can unmarshall them.
modelPackageName
- The package name where the user object model is located
JaxbMarshaller
public CRestBuilder useJdkProxies()
JdkProxyFactory
public CRestBuilder useCglibProxies()
CglibProxyFactory
public CRestBuilder usePreauthentifiedOAuth(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret)
Authentification parameters are added to the request headers.
See usePreauthentifiedOAuth(String, String, String, String, boolean)
consumerKey
- Consumer keyconsumerSecret
- Consumer secretaccessToken
- Preauthentified access tokenaccessTokenSecret
- Preauthentified access token secret
usePreauthentifiedOAuth(String, String, String, String, boolean)
public CRestBuilder usePreauthentifiedOAuth(String consumerKey, String consumerSecret, String accessToken, String accessTokenSecret, boolean authParamsInHeaders)
consumerKey
- Consumer keyconsumerSecret
- Consumer secretaccessToken
- Preauthentified access tokenaccessTokenSecret
- Preauthentified access token secretauthParamsInHeaders
- If true, adds the authentification information into the request headers, otherwise in the query string
public CRestBuilder setDateSerializerFormat(String format)
Shortcut to builder.setProperty(CRestProperty.SERIALIZER_DATE_FORMAT, format)
format
- Date format to use
CRestProperty.SERIALIZER_DATE_FORMAT
public CRestBuilder setBooleanSerializer(String trueSerialized, String falseSerialized)
Shortcut to:
builder.setProperty(CRestProperty.SERIALIZER_BOOLEAN_TRUE, trueSerialized)
builder.setProperty(CRestProperty.SERIALIZER_BOOLEAN_FALSE, falseSerialized)
trueSerialized
- String representing serialized form of TRUEfalseSerialized
- String representing serialized form of FALSE
CRestProperty.SERIALIZER_BOOLEAN_TRUE
,
CRestProperty.SERIALIZER_BOOLEAN_FALSE
public CRestBuilder setListSerializerSeparator(String sep)
Shortcut to builder.setProperty(CRestProperty.SERIALIZER_LIST_SEPARATOR, sep)
sep
- Separator string
CRestProperty.SERIALIZER_LIST_SEPARATOR
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |