日期:2014-05-16 浏览次数:20983 次

from("jms:TOOL.CLONE.PAGE").beanRef("clonepage")
.split().body()
.choice()
.when().mvel("request.body[0] == 'img'").beanRef("clonepage", "processImg")
.when().mvel("request.body[0] == 'css'").beanRef("clonepage", "processCss").to("direct:cssimg")
.when().mvel("request.body[0] == 'script'").beanRef("clonepage", "processScript")
.otherwise().beanRef("clonepage", "processOthers");
from("direct:cssimg").split().body().beanRef("clonepage", "processImg");
@Override
protected void configure() {
super.configure();
// lets add in any RouteBuilder instances we want to use
bind(MyRouteBuilder.class);
bind(Printer.class);
}
/**
* Lets configure the JMS component, parameterizing some properties from the
* jndi.properties file
*/
@Provides
@JndiBind("jms")
JmsComponent jms(@Named("activemq.brokerURL") String brokerUrl) {
return JmsComponent.jmsComponent(new ActiveMQConnectionFactory(brokerUrl));
}
@Provides
@JndiBind("myBean")
SomeBean someBean(Injector injector) {
return injector.getInstance(SomeBean.class);
}
private static final String PERSISTENCE_UNIT_NAME = "p-unit";
public static EntityManagerFactory factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
// @Provides
// EntityManager emp(){
// return MyModule.factory.createEntityManager();
// }
@Provides
@JndiBind("hpb")
HttpProcessBean hpb(Injector injector) {
return injector.getInstance(HttpProcessBean.class);
}
@Provides
@JndiBind("extrator")
ArticleExtrator extrator(Injector injector){
return injector.getInstance(ArticleExtrator.class);
}
@Provides
@JndiBind("clonepage")
ClonePage clonepage(Injector injector){
return injector.getInstance(ClonePage.class);
}
public void processCss(@Header("sitetr") String siteThemeRoot, @MVEL("request.body[1]") final String pageUrl,@MVEL("request.body[2]") String saveFileName,Exchange exchange){
ProducerTemplate template = context.createProducerTemplate();
//in-out pattern.
Exchange ecc = template.send("http4://localhost",new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(Exchange.HTTP_URI,"http4://" + pageUrl);
}
});
Message out = ecc.getOut();
String c = out.getBody(String.class);
List<String[]> relations = new ArrayList<String[]>();
//url(../Images/lian.gif)
Pattern p = Pattern.compile("url\\s*?\\(['\"\\s]*(.*?)['\"\\s]*\\)");
Matcher m = p.matcher(c);
String[] hu = getHostnameUri(pageUrl);
while(m.find()){
String url = m.group(1);
relations.add(getOneItem(url, "img", null, hu[0], hu[1]));
}
exchange.getOut().setHeader("sitetr", siteThemeRoot);
exchange.getOut().setBody(relations);
template.sendBodyAndHeader("file://" + siteThemeRoot,c,Exchange.FILE_NAME,saveFileName);
}