|
Page Edited :
SM :
servicemix-jsr181
servicemix-jsr181 has been edited by Lars Heinemann (Aug 15, 2008). Content:servicemix-jsr181ServiceMix jsr181 component is a JBI Service Engine exposing (annotated) POJO as services on the JBI Bus. Features:
InstallationInstalling the servicemix-jsr181 component can be done in several ways:
Note that when using ant tasks, the component is not started, you will have to start it manually using ant tasks or a console. ConfigurationSeveral parameters can be configured using a JMX console.
DeploymentYou can deploy Service Units containing a file named xbean.xml for activating consumer and provider endpoints. This xml file should respect the given syntax, though this is a spring based xml configuration file from where all beans of class Jsr181Endpoint <beans xmlns:jsr181="http://servicemix.apache.org/jsr181/1.0"> ... </beans> Any numbers of endpoints can be specified in the xbean.xml file.
Accessing the JBI busThe prefered way to access the JBI bus is by retrieving a ComponentContext implementation. <jsr181:endpoint ...> <jsr181:pojo> <bean class="xxx"> <property name="context" ref="context" /> </bean> </jsr181:pojo> </jsr181:endpoint> If you want to send a request to another service from your POJO, you can add the following method on your POJO: private javax.jbi.component.ComponentContext context; public void setContext(javax.jbi.component.ComponentContext context) { this.context = context; } You will be able to use the provided DeliveryChannel to send requests. Note that only sendSync is allowed for active JBI exchanges (but you have to use send for DONE or ERROR status exchanges). You can also use the client api: public void myMethod() { ServiceMixClient client = new ServiceMixClientFacade(this.context); QName service = new QName("http://servicemix.org/cheese/", "receiver"); EndpointResolver resolver = client.createResolverForService(service); client.send(resolver, null, null, "<hello>world</hello>"); } Lightweight modeThe servicemix-jsr181 component can also be configured in a spring/xbean configuration file, for use in an embedded ServiceMix. <sm:activationSpec> <sm:component> <jsr181:component> <jsr181:endpoints> <jsr181:endpoint pojoClass="test.EchoService2" serviceInterface="test.Echo" annotations="none" /> </jsr181:endpoints> </jsr181:component> </sm:component> </sm:activationSpec>
ProxiesYou can create java proxies for JBI endpoints, provided that they expose a WSDL. The basic configuration is the following: <jsr181:proxy id="proxy" container="#jbi" interfaceName="test:EchoPortType" type="test.Echo" /> You can use it from one of you client bean, or from inside another component, and call the JBI endpoint as a plain Java object. From a jsr181 Service Unit, it could be used as following: <jsr181:endpoint serviceInterface="test.Echo"> <jsr181:pojo> <bean class="test.EchoProxy"> <property name="echo"> <jsr181:proxy service="test:EchoService" context="#context" type="test.Echo" /> </property> </bean> </jsr181:pojo> </jsr181:endpoint> private Echo echo; public void setEcho(Echo echo) { this.echo = echo; } public void myMethod() { String result = echo.echo("world"); ... } EJBsUsing spring EJB proxies, you can easily expose an existing EJB on the JBI bus. <jsr181:endpoint annotations="none" service="my:ejb" endpoint="ejb" serviceInterface="foo.bar.Hello"> <jsr181:pojo> <bean class="org.springframework.ejb.access.SimpleRemoteStatelessSessionProxyFactoryBean"> <property name="jndiName" value="my/jndi/path"/> <property name="businessInterface" value="foo.bar.Hello"/> <property name="jndiTemplate" ref="jndiTemplate"/> </bean> </jsr181:pojo> </jsr181:endpoint> MTOM supportMTOM is a way to handle large amounts of binary data in your services. Unlike attachments, the XML infoset stays the same. MTOM just "optimizes" any base64Binary data you have in your messages. When MTOM is turned on, this base64 data gets sent as a binary attachment saving time and space. MTOM support can be turned on using: <jsr181:endpoint mtomEnabled="true" ... />
MTOM is supported for the following classes:
If you have a bean with the following method: public String echo(String msg, DataHandler binary) { ... } you will be able to call it using the following requests: <echo xmlns:xop='http://www.w3.org/2004/08/xop/include'> <msg>hello world</msg> <binary> <xop:Include href=''/> </binary> </echo> provided that the JBI message contains an attachment named "binary". Accessing the JBI exchangeSome times, while processing the incoming request, you need to access the underlying JBI exchange. public String echo(String msg, DataHandler binary) { ... MessageExchange exchange = org.apache.servicemix.jsr181.JBIContext.getMessageExchange(); ... } |
Unsubscribe or edit your notifications preferences
