Skip to content

Commit

Permalink
Mise à jour
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspocus committed May 18, 2011
1 parent c0aa078 commit d818b6d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 47 deletions.
22 changes: 11 additions & 11 deletions conf/dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ self: play -> camel 1.0

require:
- play 1.2
- rome -> rome 0.9:
transitive: false
force: true
# - rome -> rome 0.9:
# transitive: false
# force: true
- org.apache.derby -> derby 10.7.1.1
- commons-pool -> commons-pool 1.5.5
- org.apache.activemq -> activemq-core 5.5.0
- org.apache.activemq -> activemq-pool 5.5.0
- org.apache.activemq -> activemq-camel 5.5.0
- org.apache.camel -> camel-core 2.7.1
- org.apache.camel -> components 2.7.1
- org.apache.camel -> camel-amqp 2.7.1
- org.apache.camel -> camel-activemq 1.1.0:
transitive: false
# - org.apache.camel -> camel-amqp 2.7.1
- org.apache.camel -> camel-context 2.7.1
# - org.apache.camel -> camel-spring 2.7.1
- org.apache.camel -> camel-ftp 2.7.1
- org.apache.camel -> camel-jms 2.7.1
- org.apache.camel -> camel-mail 2.7.1
- org.apache.camel -> camel-routebox 2.7.1
- org.apache.camel -> camel-jpa 2.7.1
- org.apache.camel -> camel-soap 2.7.1
- org.apache.camel -> camel-jetty 2.7.1
# - org.apache.camel -> camel-routebox 2.7.1
# - org.apache.camel -> camel-jpa 2.7.1
# - org.apache.camel -> camel-soap 2.7.1
# - org.apache.camel -> camel-jetty 2.7.1
# - org.apache.camel -> camel-http 2.7.1
# - org.apache.camel -> camel-netty 2.7.1
# - org.apache.activemq -> activemq-optional 5.5.0:
# transitive: false
# exclude:
# - net.sf.josql -> gentlyweb-utils 1.5
# - net.sf.josql -> josql 1.5
Expand Down
4 changes: 3 additions & 1 deletion conf/routes
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# This file defines all module routes (Higher priority routes first)
#
# import these routes in the main app as :
# * / module:noee-camel
# * / module:camel
#
# ~~~~

#* /@camel CamelApplication.index()
66 changes: 31 additions & 35 deletions src/play/modules/camel/CamelPlugin.java
Original file line number Diff line number Diff line change
@@ -1,53 +1,37 @@
package play.modules.camel;

import java.net.InetSocketAddress;
import java.net.URI;
import javax.jms.ConnectionFactory;

import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerContext;
import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.BrokerInfo;
import org.apache.activemq.transport.TransportAcceptListener;
import org.apache.activemq.transport.TransportServer;
import org.apache.activemq.transport.TransportServerSupport;
import org.apache.activemq.camel.component.ActiveMQComponent;
import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.activemq.ActiveMQComponent;
import org.apache.camel.impl.DefaultCamelContext;

import play.Logger;
import play.Play;
import play.PlayPlugin;
import play.inject.BeanSource;
import play.inject.Injector;
import play.mvc.Http.Request;
import play.mvc.Http.Response;
import play.mvc.Router;


public class CamelPlugin extends PlayPlugin implements BeanSource {

private static DefaultCamelContext ctx;
private static BrokerService broker;

private static ActiveMQComponent amqc;
@Override
public void onApplicationStart() {
try {
if(broker == null){
// ActiveMQ
broker = new BrokerService();
broker.setAdvisorySupport(false);
broker.setUseJmx(true);
broker.setBrokerName(Play.configuration.getProperty("broker.name", "play-activemq"));
broker.addConnector(Play.configuration.getProperty("broker.connector", "nio://localhost:61616"));
broker.start();
Logger.info("ActiveMQ Broker started...");
}
if(ctx == null){
if (ctx == null) {
// Camel
ctx = new DefaultCamelContext();
ctx.setName(Play.configuration.getProperty("camel.name", "play-camel"));
ActiveMQComponent amqc = new ActiveMQComponent(ctx);
amqc = new ActiveMQComponent(ctx);
amqc.setBrokerURL(Play.configuration.getProperty("broker.url", "vm:localhost"));
ctx.start();
Logger.info("Camel EIP started...");
Logger.info("Camel & ActiveMQ Services are now started...");
}

} catch (Exception e) {
Expand All @@ -60,10 +44,10 @@ public void onApplicationStart() {
public void onApplicationStop() {
try {
ctx.shutdown();
while(!ctx.isStopped()){
while (!ctx.isStopped()) {
Thread.sleep(100);
}
Logger.info("Camel & ActiveMQ Services are now stopped");
Logger.info("Camel & ActiveMQ Services are now stopped\n");
} catch (Exception e) {
// TODO: handle exception
}
Expand All @@ -79,21 +63,33 @@ public <T> T getBeanOfType(Class<T> clazz) {
if (clazz.equals(CamelContext.class)) {
Logger.info("%s Injection...OK", clazz.getName());
return (T) ctx;
}else if (clazz.equals(BrokerService.class)) {
}
else if (clazz.equals(ConnectionFactory.class)) {
Logger.info("%s Injection...OK", clazz.getName());
return (T) broker;
return (T) amqc.getConfiguration().getConnectionFactory();
}

Logger.info("%s Injection...KO", clazz.getName());
return null;
}

@Override
public boolean rawInvocation(Request request, Response response) throws Exception {
if ("/@camel".equals(request.path)) {
response.status = 302;
response.setHeader("Location", "/@camel/");
return true;
}
return false;
}

public static BrokerService getBroker(){
return broker;
}
@Override
public void onRoutesLoaded() {
Router.prependRoute("GET", "/@camel/?", "CamelApplication.index");
}

public static CamelContext getCamelContext(){
return ctx;
}

}

0 comments on commit d818b6d

Please sign in to comment.