Interface ServiceClientFactory

  • All Known Implementing Classes:
    ServiceClientFactoryImpl

    public interface ServiceClientFactory
    This is the interface for a factory used to create client stubs for a Service. The following example shows the typical usage in your code:
     @Named
     public class UcMyUseCaseImpl extends MyUseCaseBase implements UcMyUseCase {
       @Inject private ServiceClientFactory clientFactory;
    
       @Override @javax.annotation.security.RolesAllowed(...)
       public Foo doSomething(Bar bar) {
         MyExternalServiceApi externalService = this.clientFactory.create(MyExternalServiceApi.class);
         Some result = externalService.doSomething(convert(bar));
         return convert(result);
       }
     }
     
    As you can see creating a service client stub is easy and requires only a single line of code. However, internally a lot of things happen such as the following aspects: All these aspects can be configured via spring and customized with own implementations.
    Since:
    3.0.0
    • Method Detail

      • create

        <S> S create​(Class<S> serviceInterface)
        Type Parameters:
        S - the generic type of the serviceInterface. For flexibility and being not invasive this generic is not bound to Service (S extends Service).
        Parameters:
        serviceInterface - the Class reflecting the interface that defines the API of your Service.
        Returns:
        a new instance of the given serviceInterface that is a client stub. Invocations to any of the service methods will trigger a remote call and synchronously return the result.
      • create

        <S> S create​(Class<S> serviceInterface,
                     Map<String,​String> config)
        Type Parameters:
        S - the generic type of the serviceInterface. For flexibility and being not invasive this generic is not bound to Service (S extends Service).
        Parameters:
        serviceInterface - the Class reflecting the interface that defines the API of your Service.
        config - the Map with explicit configuration properties. See ServiceConfigProperties for further details.
        Returns:
        a new instance of the given serviceInterface that is a client stub. Invocations to any of the service methods will trigger a remote call and synchronously return the result.