org.spicefactory.cinnamon.client
Interface ServiceChannel

All Known Implementing Classes:
AbstractServiceChannel, SpringServiceChannel, XmlServiceChannel

public interface ServiceChannel

Factory that creates Cinnamon client proxies. In a usual deployment scenario Cinnamon will be used with Flex/Flash clients. But if you need to invoke the same services that you exposed to Flex clients from a Java client, this facility comes in handy, since you do not need to bother with exposing the same service for a second protocol.

Cinnamon comes with two implementations of this interface. One uses Cinnamons own XML configuration format, the other uses a Spring ApplicationContext to assemble the configuration artifacts from.

An example: Let's assume you want to invoke a method on a service with the following interface:

public interface EchoService {
     
     public String echo (String str);
     
 }

The code needed for the invocation would look like this (assuming that you load the configuration from the server, of course you could also load it locally):

 ClientProxyFactory factory = new XmlClientProxyFactory();
 factory.setConfigResource(new HttpResource("http://www.mycompany.com/service-config.xml"));
 factory.setServiceUrl("http://www.mycompany.com/services/");
 factory.configure();
 EchoService service = factory.createService(EchoService.class, "echoService");
 String result = service.echo("Hello World");
 System.out.println("The result was: " + result);
 

Author:
Jens Halm

Method Summary
 void configure()
          Method that should be called once after all properties have been set on this instance but before any service instances will be created.
<T> T
createService(Class<T> serviceInterface, String serviceName)
          Creates a client service proxy that implements the specified service interface.
 CinnamonConfig getConfig()
          Returns the Cinnamon configuration.
 Set<String> getHeaderNames()
          Returns an unmodifiable Set containing all header names for this message.
 Object getHeaderValue(String name)
          Returns the header value for the given name.
 String getServiceUrl()
          Returns the service URL that client proxies should connect to.
 void removeHeader(String name)
          Removes the header for the given name.
 void setConfigResource(Resource resource)
          Sets the resource to load the Cinnamonn configuration from.
 void setHeader(String name, Object value)
          Sets a header for this message.
 void setServiceUrl(String serviceUrl)
          Sets the service URL that client proxies should connect to.
 

Method Detail

setConfigResource

void setConfigResource(Resource resource)
Sets the resource to load the Cinnamonn configuration from.

Parameters:
resource - the resource to load the Cinnamonn configuration from

setServiceUrl

void setServiceUrl(String serviceUrl)
Sets the service URL that client proxies should connect to.

Parameters:
serviceUrl - the service URL that client proxies should connect to

getServiceUrl

String getServiceUrl()
Returns the service URL that client proxies should connect to.

Returns:
the service URL that client proxies should connect to

getConfig

CinnamonConfig getConfig()
Returns the Cinnamon configuration. This method will throw an Exception if the factory is not fully initialized yet.

Returns:
the Cinnamon configuration

configure

void configure()
Method that should be called once after all properties have been set on this instance but before any service instances will be created.


createService

<T> T createService(Class<T> serviceInterface,
                    String serviceName)
Creates a client service proxy that implements the specified service interface.

Parameters:
serviceInterface - the service interface
serviceName - the name of the service as specified in the Cinnamon configuration
Returns:
a client service proxy

setHeader

void setHeader(String name,
               Object value)
Sets a header for this message. This is a custom message header and does not relate to HTTP headers or AMF0 headers.

Parameters:
name -
value -

removeHeader

void removeHeader(String name)
Removes the header for the given name.

Parameters:
name - the name of the header to remove

getHeaderNames

Set<String> getHeaderNames()
Returns an unmodifiable Set containing all header names for this message.

Returns:
an unmodifiable Set containing all header names for this message

getHeaderValue

Object getHeaderValue(String name)
Returns the header value for the given name. This is a custom message header and does not relate to HTTP headers or AMF0 headers.

Parameters:
name - the name of the header
Returns:
the header value for the given name or null if no such header exists