thanks.
it's currently packaged up as a test case in bpmscript-core. might be tricky
to run it on it's own at the moment (easiest way would be to grab the source
from cvs and run the org.bpmscript.jbi.component.CallEmailTest.
there are examples of bpmscript running from an SU but they'll only be able
to use the lightweight components if configured in servicemix.xml. hmmm...
should probably look to make this example more independent (as an SU and
associated servicemix.xml, like the servicemix examples).
The dynamic saaj binding is just the servicemix SaajBinding which allows you
to specify the soap endpoint in the message rather than only at config time.
Additional stuff about the example:
* It doesn't do any initial validation, there's an argument that it would be
better to do it earlier just because the more stateless stuff you can do
outside of bpmscript, the faster it'll be
* It doesn't currently do any error handling (to keep the example relatively
small)
* It could do all sorts of other cool things like: set up a task to buy or
sell and then call some stock buying web service
* It's using the in memory version of the bpmscript component which makes it
quicker to test
cheers,
j.
On 11/27/06, Guillaume Nodet <[EMAIL PROTECTED]> wrote:
It sounds really nice :)
I will try to launch this example tonight ...
I need to take a look at the DynamicSaajBinding to see what it does.
On 11/27/06, Jamie McCrindle <[EMAIL PROTECTED]> wrote:
> hi all,
>
> i've put together an example of a long running business process in
bpmscript
> that showcases some of the things you can do with bpmscript (on top of
> servicemix, of course). The script looks like this:
>
> /**
> * Demonstration of BpmScript using services including:
> *
> * - Lightweight Email Component
> * - Lightweight SOAP Component (modified)
> * - BpmScript Alarm Service
> *
> * Example takes in a request which looks something like:
> * <request>
> * <symbol>GOOG</symbol>
> * <min>12.9</min>
> * <max>53.9</max>
> * <to>[EMAIL PROTECTED]</to>
> * </request>
> *
> * It then looks up the stock price associated with the
> * symbol each hour using the ws.investbox.com web service
> * and email's the person specified in the to field of the
> * request if the price reaches more than the max or less
> * than the min. If not, the script sleeps for an hour and
> * then tries again.
> **/
> function main(input, sender) {
>
> // parse out the source xml
> var request = sourceToXml(input.getInMessage().getContent());
>
> // create some BpmScript Services
> var soapService = new SoapService(sender);
> var alarmService = new AlarmService(sender);
> var emailService = new EmailService(sender);
>
> // grab the minimum and maximum values from the request
> var min = parseFloat(request.min.text().toString());
> var max = parseFloat(request.max.text().toString());
>
> // check every hour
> while(alarmService.sendSync("PT1H")) {
>
> // create the SOAP content
> var message = <tns:GetQuote xmlns:tns="http://ws.invesbot.com/">
> <tns:symbol>{request..symbol.text()}</tns:symbol>
> </tns:GetQuote>;
>
> // send out the soap request
> var exchange = soapService.sendSync(
> soapService.toURL("http://ws.invesbot.com/stockquotes.asmx"),
> "http://ws.invesbot.com/GetQuote",
> xmlToSource(message));
>
> // get the xml from the response
> var xml = sourceToXml(exchange.getOutMessage().getContent());
>
> // parse out the bid. the reason this is more complicated
> // than it needs to be is because the data comes back as e.g.
> 23.5<small>x 100</small>
> var bid =
> parseFloat(/^(\d+\.\d+)/.exec(xml..Bid.text().toString())[0]);
>
> // send out an email if the bid price is higher than the max
> // or lower than the minimum set and end the script
> if(bid < min || bid > max) {
> emailService.send({"to":request.to.text().toString(),
> "from":request.to.text().toString(),
> "subject":"Bid has reached " + (bid < min ? "minimum" :
"maximum")
> + " value of " + bid,
> "text":xml.toXMLString()});
> break;
> }
> }
>
> sender.reply(ST.toStreamSource("<done/>"));
>
> }
>
>
> The spring config for the example looks as follows (without the smtp
> properties -- i was testing using gmail):
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns:sm="http://servicemix.apache.org/config/1.0"
> xmlns="http://xbean.org/schemas/spring/1.0"
> xmlns:bs="http://bpmscript.org/jbi" xmlns:test="urn:test">
>
> <bean id="mailSender"
> class="org.springframework.mail.javamail.JavaMailSenderImpl">
> <property name="host" value="${smtp.host}" />
> <property name="port" value="${smtp.port}" />
> <property name="protocol" value="smtps" />
> <property name="username" value="${smtp.username}" />
> <property name="password" value="${smtp.password}" />
> <property name="javaMailProperties">
> <props>
> <prop key="mail.smtps.auth">true</prop>
> <prop key="mail.smtp.starttls.enable">true</prop>
> <prop key="mail.smtp.debug">true</prop>
> </props>
> </property>
> </bean>
>
> <sm:container id="jbi" embedded="true" flowName="seda"
> createMBeanServer="false">
>
> <sm:activationSpecs>
>
> <sm:activationSpec>
> <sm:component>
> <bean
> class="
> org.bpmscript.jbi.component.InMemoryBpmScriptSpringComponent">
> <property name="endpoints">
> <list>
> <bean
> class="org.bpmscript.jbi.component.ProcessEndpoint">
> <property name="endpoint" value="email" />
> <property name="sourceResource"
> value="classpath:email/main.js" />
> </bean>
> </list>
> </property>
> </bean>
> </sm:component>
> </sm:activationSpec>
>
> <sm:activationSpec componentName="dynamicsoap"
> service="bs:dynamicsoap">
> <sm:component>
> <bean class="org.bpmscript.jbi.DynamicSaajBinding"></bean>
> </sm:component>
> </sm:activationSpec>
>
> <sm:activationSpec componentName="emailSender"
> service="bs:emailSender">
> <sm:component>
> <bean
> class="
org.apache.servicemix.components.email.SimpleMailSender">
> <property name="sender" ref="mailSender"/>
> </bean>
> </sm:component>
> </sm:activationSpec>
>
> </sm:activationSpecs>
> </sm:container>
>
> </beans>
>
>
--
Cheers,
Guillaume Nodet