3 Replies Latest reply on Jun 9, 2011 2:27 AM by davsclaus

    OsgiLanguageResolver

    jamie3_james.archibald

      I am fooling around with Eclipse RAP, and want to be able to use Camel to create a simple chat application that publishes/consumes messages over an embedded ActiveMQ broker which has auto-discovery enabled.

       

      Here is what I've done thus far.

       

      1) Create a new Eclipse RAP project

      2) Add the camel and activemq jars as runtime dependencies into the project (see manifest below)

      3) Created a chat view part which contains my camel and activemq code (see ChartView class below)

      4) Used the CamelContextFactory to create the DefaultCamelContext such that is is compatible for OSGi.

       

      The problem I am having is when I start the camel context a NoSuchLanguageException is thrown. I've stepped through the source and have identified that the OsgiLanguageResolver class cannot find the language (eg. "simple").

       

       

       

      Here is my code below:

       

      Manifest

      -


       

      Manifest-Version: 1.0

      Bundle-ManifestVersion: 2

      Bundle-Name: Rap-chat

      Bundle-SymbolicName: rap-chat; singleton:=true

      Bundle-Version: 1.0.0.qualifier

      Bundle-Activator: rap_chat.Activator

      Require-Bundle: org.eclipse.rap.ui

      Bundle-ActivationPolicy: lazy

      Bundle-RequiredExecutionEnvironment: JavaSE-1.6

      Import-Package: javax.servlet;version="2.4.0",

      javax.servlet.http;version="2.4.0"

      Bundle-ClassPath: .,

      camel-core-2.7.2.jar,

      camel-jms-2.7.2.jar,

      swing2swt.jar,

      commons-management-1.0.jar,

      slf4j-api-1.6.1.jar,

      spring-core-3.0.5.RELEASE.jar,

      spring-context-3.0.5.RELEASE.jar,

      activemq-all-5.5.0.jar,

      spring-tx-3.0.5.RELEASE.jar,

      spring-jms-3.0.5.RELEASE.jar,

      spring-beans-3.0.5.RELEASE.jar,

      spring-aop-3.0.5.RELEASE.jar,

      commons-logging-1.1.1.jar,

      activemq-pool-5.5.0.jar,

      camel-spring-2.7.2.jar,

      spring-context-3.0.3.RELEASE.jar,

      spring-osgi-core-1.2.1.jar

       

       

       

      Java class

      -


       

       

      package rapchat;

       

      import java.net.InetAddress;

      import java.net.URI;

       

      import org.apache.activemq.broker.BrokerService;

      import org.apache.activemq.broker.TransportConnector;

      import org.apache.activemq.camel.component.ActiveMQComponent;

      import org.apache.camel.ProducerTemplate;

      import org.apache.camel.builder.RouteBuilder;

      import org.apache.camel.impl.DefaultCamelContext;

      import org.apache.camel.osgi.CamelContextFactory;

      import org.eclipse.swt.SWT;

      import org.eclipse.swt.events.KeyAdapter;

      import org.eclipse.swt.events.KeyEvent;

      import org.eclipse.swt.widgets.Composite;

      import org.eclipse.swt.widgets.Label;

      import org.eclipse.swt.widgets.Text;

      import org.eclipse.ui.part.ViewPart;

      import org.osgi.framework.BundleContext;

       

      import rap_chat.Activator;

      import swing2swt.layout.BorderLayout;

      import swing2swt.layout.FlowLayout;

       

      public class ChatView extends ViewPart {

           private Text text;

           private Text userName;

           private Text textChatMessage;

           private ProducerTemplate template;

           private DefaultCamelContext camel;

            

           public ChatView() {

           }

       

           @Override

           public void createPartControl(Composite parent) {

                parent.setLayout(new BorderLayout(0, 0));

                 

                text = new Text(parent, SWT.BORDER | SWT.MULTI);

                 

                Composite composite = new Composite(parent, SWT.NONE);

                composite.setLayoutData(BorderLayout.SOUTH);

                composite.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

                 

                Label labelUserName = new Label(composite, SWT.NONE);

                labelUserName.setBounds(0, 0, 49, 13);

                labelUserName.setText("Your Name:");

                 

                userName = new Text(composite, SWT.BORDER);

                userName.setBounds(0, 0, 76, 19);

                 

                Label labelChatMessage = new Label(composite, SWT.NONE);

                labelChatMessage.setText("Message:");

                 

                textChatMessage = new Text(composite, SWT.BORDER);

                textChatMessage.addKeyListener(new KeyAdapter() {

                     @Override

                     public void keyPressed(KeyEvent e) {

                          if (e.keyCode == SWT.CR) {

                               if (textChatMessage.getText().trim().length() > 0) {

                                    System.out.println("Send chat message: " + textChatMessage.getText());

                                    template.sendBody("activemq:topic:Chat", textChatMessage.getText());

                                    // clear

                                    textChatMessage.setText("");

                               }

                          }

                     }

                });

                 

                // start activemq

                try {

                      

                     BrokerService broker = new BrokerService();

                     broker.setBrokerName(InetAddress.getLocalHost().getHostName());

                     // configure the broker to use auto-discovery

                     TransportConnector tc = new TransportConnector();

                     tc.setUri(new URI("tcp://localhost:61616"));

                     tc.setDiscoveryUri(new URI("multicast://default"));

                     broker.addConnector(tc);

                     broker.setNetworkConnectorURIs(new String[]{

                          "multicast://default"     

                     });

                     broker.start();

                      

                     // in osgi world we need to create the camel context a bit differently

                     BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext();

                     CamelContextFactory factory = new CamelContextFactory();

                     factory.setBundleContext(bundleContext);

                     camel = factory.createContext();

                      

                     // camel will be responsible for connecting the chat client to the message broker

                     camel.addComponent("activemq", ActiveMQComponent.activeMQComponent("tcp://localhost:61616"));

                     camel.addRoutes(new RouteBuilder() {

       

                          @Override

                          public void configure() throws Exception {

                               from("activemq:topic:Chat")

                               .log("Got chat message: ${body}");

                          }

                           

                     });

                     camel.start();

                     template = camel.createProducerTemplate();

       

                     System.out.println("Chat ready!");

                      

                } catch (Exception e1) {

                     // TODO Auto-generated catch block

                     e1.printStackTrace();

                }

           }

            

           @Override

           public void dispose() {

                try {

                     camel.stop();

                } catch (Exception e) {

                     // TODO Auto-generated catch block

                     e.printStackTrace();

                }

                super.dispose();

           }

       

           @Override

           public void setFocus() {

                // TODO Auto-generated method stub

                 

           }

      }