-
Notifications
You must be signed in to change notification settings - Fork 11
Spring
Brutusin-RPC uses Spring Framework to locate and instantiate application components. It also is specially suited for integrating with Spring Security, as explained here, indeed maven archetypes include Spring Security configuration.
At startup a http-aware application context is created, loading the component definitions from the resource brutusin-rpc.xml
(to be created by applications).
This resource is loaded via
getClassLoader().getResources("brutusin-rpc.xml")
so, a typical project creates it in the following path:src/main/resources/brutusin-rpc.xml
This context can be retrieved via HttpActionSupport.getInstance().getSpringContext()
or WebsocketActionSupport.getInstance().getSpringContext()
If a root context is configured for the web application, this context automatically is created as its child.
Actions and topics must be registered in a brutusin-rpc.xml
Spring file, with singleton
(default) scope in the root namespace.
Example:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- <bean id="${serviceId}" class="${actionClass}"/> -->
<bean id="test" class="org.brutusin.rpc.websocket.msg.Topic">
<constructor-arg value="org.brutusin.demo.TopicMessage" type="java.lang.Class"/>
<property name="description" value="A topic example. Messages to this topic are published using the `fire` websocket service"/>
</bean>
<bean id="fire" class="org.brutusin.demo.FireAction">
<property name="topic" ref="test"/>
<property name="description" value="An example service that publishes messages to topic `test`"/>
</bean>
<bean id="wsk.hello" class="org.brutusin.demo.HelloAction"/>
<bean id="date" class="org.brutusin.demo.spring.GetDateAction">
<property name="datePattern" value="yyyy-MM-dd'T'HH:mm:ss.SSSXXX"/>
</bean>
<bean id="time" class="org.brutusin.demo.spring.GetDateAction">
<property name="datePattern" value="h:mm a"/>
</bean>
<bean id="http" class="org.brutusin.demo.http.HttpAwareAction"/>
<bean id="condcache" class="org.brutusin.demo.http.ConditionalCachedAction"/>
<bean id="cache" class="org.brutusin.demo.http.ExpiringCachedAction"/>
<bean id="security" class="org.brutusin.demo.SecurityExceptionAction"/>
<bean id="exception" class="org.brutusin.demo.ExceptionAction"/>
<bean id="http.hello" class="org.brutusin.demo.complex.HelloWorldAction"/>
<bean id="logo" class="org.brutusin.demo.streaming.LogoAction"/>
<bean id="upload" class="org.brutusin.demo.streaming.UploadingAction"/>
<bean id="unsafe" class="org.brutusin.demo.UnSafeAction"/>
<bean id="idempotent" class="org.brutusin.demo.IdempotentUnSafeAction"/>
</beans>
The framework automatically finds them and uses their bean id property as identifier for the component.
Notice that the same action class can be used by different services, an dependency injection can be used.
- Home
- Getting started
- Services
- HTTP services
- Messaging topics
- Spring
- Documenting
- Referencing source code
- Builtin components
- Configuration
- Deployment
- Client APIs
- Security
- Developer notes
- Architecture
- Examples