正在加载...

fragment in Smooks

五月 14th, 2012

Transform the xml content into JavaBean, with Smooks. And the xml file looks like

<Article>
 <AticleNo>PM20120424001</ AticleNo>
 <ArticleTopic>2012 May 1st</ ArticleTopic >
 <PostBy>201204290830</PostBy>
 <ArticleContent>
 <div align="center"><strong>Hello<br /></strong>
  <div align="left">I want to post:<br />
 <ol>
  <li>1<span style="color:#FF0000;">5%</span>XX/li>
  <li>2<span style="color:#FF0000;">9999</span>,XX<span style="color:#FF0000;">5%</span></li>
  <li>3<span style="color:#FF0000;">99999</span>,XXY<span style="color:#FF0000;">10%</span></li>
 </ol>
 <p><br />
 </p>
  <p>Peter<br />
 </p>
 </div>
 </div>
 </  ArticleContent >
 </Article >

And if we use

<jb:bean beanId="article" class="java.util.HashMap" createOnElement="Article">
        <jb:value property="AticleNo"          data="AticleNo"     />
        <jb:value property="ArticleTopic"     data="ArticleTopic" />
        <jb:value property="PostBy"     data="PostBy"/>
        <jb:value property="ArticleContent"       data="ArticleContent"/>     
    </jb:bean>

We got an empty articeContent, because the articlecontent itself contains an xml stream.

Fragment 

<frag:serialize fragment="Article/ArticleContent" bindTo="contentbody" childContentOnly="true"/>

<jb:bean beanId="article" class="java.util.HashMap" createOnElement="Article">
        <jb:value property="AticleNo"          data="AticleNo"     />
        <jb:value property="ArticleTopic"     data="ArticleTopic" />
        <jb:value property="PostBy"     data="PostBy"/>
    </jb:bean>

The Java Code:

JavaResult jr = new JavaResult();
String message = (String) exchange.getIn().getBody();
smooks.filterSource(new StreamSource(new ByteArrayInputStream(message.getBytes())),    jr);

 Map<String, String> map= jr.getBean(HashMap.class);
 String contentbody = jr.getBean("contentbody").toString();

The map is the binded bean from <jb:bean xxx  and the contentbody is the fragmented articlecontent

Load CSV file into DB with camel-csv,camel-sql

三月 9th, 2012

Suppose we have a csv file, with only 2 columns, and wants to load it into a mysql table.

1, Load without transaction management

1.1, Java DSL looks like:

from("file:testcsv")            // load the csv files from the folder
        .unmarshal().csv()    // transform the csv file into java.util.List<java.util.List>
       .to("sql:insert into testcsv (value1, value2) Values (#, #)?batch=true") // batch=true will loop the list and then loop the list inside to feed the parameters (#,#,#...)

        .end();     

1.2, Spring xml configurations

  <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="xxx" />
        <property name="url" value="xxx" />
        <property name="username" value="xxx" />
        <property name="password" value="xxx" />
      </bean>

   

2, Add transaction control

2.1, Java DSL looks like:

Policy txrequried = (SpringTransactionPolicy)this.getApplicationContext().getBean("PROPAGATION_REQUIRED");

from("file:testcsv")
        .unmarshal().csv()
        .policy(txrequried)  // add transaction policy
        .to("sql:insert into testcsv (value1, value2) Values (#, #)?batch=true")
        .end();          

2.2, Spring xml configurations

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

    <!-- policy for required transaction used in our Camel routes -->
    <bean id="PROPAGATION_REQUIRED" class="org.apache.camel.spring.spi.SpringTransactionPolicy">
        <property name="transactionManager" ref="txManager"/>
        <property name="propagationBehaviorName" value="PROPAGATION_REQUIRED"/>
    </bean>
   
    <bean id="sql" class="org.apache.camel.component.sql.SqlComponent">
        <property name="dataSource" ref="dataSource"/>
    </bean>

   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="xxx" />
        <property name="url" value="xxx" />
        <property name="username" value="xxx" />
        <property name="password" value="xxx" />
      </bean>


Some pratice in JavaFX

九月 12th, 2011
Some of my pratices in JavaFX (..More)

SLA in SOA

八月 30th, 2011

Background:

When we implement a SOA, which involves several systems, some are ours, and some belongs to the external organizations (the  customers), we just try to make it a reliable and stable. But very soon we find it a black hole. Your reliability and stability relies on the service providers (different systems), and as they are located in different places, you can never believe they have enough availability.

Then you try to create all kinds of redundancy and fail-over solutions, to avoid the the service providers kill your ESB or other services consumers, and soon becomes a nightmare.

SLA

SLA, Service Level Agreement. In SOA, an engineer is quite easy to drop into technical interfaces: webservices, routings, message transformation, etc, but here SLA should be taken into consideration at the beginning when the SOA is architected, and especially the non-functional SLA metrics.

1, SLA is a promise for any comsumer when one service is exposed

It is the provider's resposibility to keep the SLA, that make the boundares clean, and the provider doesn't waste too much effort to try, and validate the quality of the services before it starts consuming.

2, SLA is a base when the provider consumes the service

When SLA is there, the providers can think the consumer is able to keep the SLA, and what's more important is, provider can and only can consume the services based on SLA. The consumer CANNOT mis-use the service, for example, if a serice is promised to process a data which is less then 2MB, and it is kept in SLA, then the consumer SHOULD NOT try to send a file which is 5MB to this services.

So SLA is also a limitation for the consumer, the provider should never get any "superise" from the consumer.

3, In ESB, the routing should also be designed based on each services' SLA that are registered in ESB

The services are always avaiable during the period they promise they will be, and they are never available when they don't promise. I don't think it is a smart way to put too much redundancies in ESB, and they will never be enough if the services providers give a very bad quality of services.

ServiceMix Turtorial

八月 25th, 2011
给公司写的一个ServiceMix 入门级的培训文档 (..More)

GDSN

八月 24th, 2011

正在写的一篇关于GDSN改善订单完成率及提升供应链整体效率的论文。



计划的大致内容:

产品提供者,将其产品信息发布至GS1兼容的全球公布数据池;

其客户订阅其产品,并将产品信息,属性,变更及时同步至订单管理系统;

由于数据的同步,大幅提高订单有效性,降低人工审核订单,纠错的时间,从而改善供应链上下游双方的整体效益;

由于产品数据池是多对多的架构,但产品提供者希望将数据发布至另一个客户时,其无需重复投资。

Apache Camel Training Doc

八月 24th, 2011
给公司写的一个关于Camel的初级培训文档 (..More)

ADempiere Marketing plan

四月 26th, 2011
http://www.adempiere.com/index.php/Marketing_Plan

Add a XLS reader for Smooks - Trial 1

四月 26th, 2011
This example is based on the previous blog: http://zpshen.appspot.com/?p=53401
It is a trial to integrate jxls with Smooks, to enable smooks to read xls file directly.
But in this example, the templates file use a customized java bean, and hardcoded it into a xml structure in smooks reader, there must be some smarter way, but need some more research. (..More)

jXLS-reader to parse an Excel into Java Bean

四月 26th, 2011
jXLS is a small and easy-to-use Java library for writing Excel files using XLS templates and reading data from Excel into Java objects using XML configuration.













And the following is the example, shows how to use jXLS's jxls-reader module to read a given excel file and parse it into a java bean (..More)