Skip to main content

Adding a servlet to Orion (Eclipse Cloud IDE) from a package built using maven.


Orion is an open source project and it is under the Eclipse Cloud Development top-level project. It’s an cloud IDE which is available online and also which can be hosted in on premise. [1] [2]. Orion can work with git repos, create git repos or work with local code same as Eclipse.

Orion has two repos. For the backend server code [2] and for the client / ui code [3]. Orion server is an osgi server based on eclipse equinox. But the problems are they have not implemented the dropins concept. Because of that adding an external bundle to Orion Server is not straightforward. We have to edit the bundles.info to add a bundle to Orion server. And Orion is using jetty for the servlets.

As mentioned Orion is working with Jetty and to add a servlet via a bundle is easy if we use eclipse itself to develop and bundle the package. But if we use maven to build it then the problems arises. What we have to do is add an entry to plugins.xml and package the plugins.xml to the bundle we are creating.

So to do this what has to be done is add a plugins.xml (You can copy an existing plugins.xml from orion code base) to the resources directory and edit it to have your servlets in it. And in the pom.xml under the build tag add following section. You can look into the sample code [4].

     <resources>  
       <resource>  
         <directory>src/main/resources</directory>  
         <filtering>true</filtering>  
         <includes>  
           <include>build.properties</include>  
           <include>bundle.properties</include>  
           <include>plugin.xml</include>  
         </includes>  
       </resource>  
     </resources>  

Sample plugins.xml is as below.

 <?xml version="1.0" encoding="UTF-8"?>  
 <?eclipse version="3.4"?>  
 <plugin>  
   <extension  
      point="org.eclipse.equinox.http.registry.servlets">  
    <servlet  
       alias="/helloworld"  
       class="org.orion.sample.servlet.servlet.HelloWorldServlet">  
    </servlet>  
    <serviceSelector  
       filter="(other.info=org.eclipse.orion)">  
    </serviceSelector>  
   </extension>  
 </plugin>  

Servlet code will be the following

 package org.orion.sample.servlet.servlet;  
 import org.eclipse.orion.server.servlets.OrionServlet;  
 import javax.servlet.ServletException;  
 import javax.servlet.http.HttpServletRequest;  
 import javax.servlet.http.HttpServletResponse;  
 import java.io.IOException;  
 public class HelloWorldServlet extends OrionServlet {  
      @Override  
      protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {  
           resp.getWriter().println("Hello JCG, Hello OSGi");  
      }  
      public HelloWorldServlet() {  
           super();  
      }  
 }  

Since to deploy the bundle to Orion it has to be an osgi bundle you have add maven scr and maven bundle plugins to your project as well. So the build tag in the pom.xml should be like below.

   <build>  
     <resources>  
       <resource>  
         <directory>src/main/resources</directory>  
         <filtering>true</filtering>  
         <includes>  
           <include>build.properties</include>  
           <include>bundle.properties</include>  
           <include>plugin.xml</include>  
         </includes>  
       </resource>  
     </resources>  
     <plugins>  
       <plugin>  
         <groupId>org.apache.felix</groupId>  
         <artifactId>maven-scr-plugin</artifactId>  
         <version>1.7.2</version>  
         <executions>  
           <execution>  
             <id>generate-scr-scrdescriptor</id>  
             <goals>  
               <goal>scr</goal>  
             </goals>  
           </execution>  
         </executions>  
       </plugin>  
       <plugin>  
         <groupId>org.apache.felix</groupId>  
         <artifactId>maven-bundle-plugin</artifactId>  
         <version>2.3.5</version>  
         <extensions>true</extensions>  
         <configuration>  
           <instructions>  
             <Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>  
             <Bundle-Name>${project.artifactId}</Bundle-Name>  
             <Export-Package>  
               org.orion.sample.servlet.*,  
             </Export-Package>  
             <DynamicImport-Package>*</DynamicImport-Package>  
             <Require-Bundle>  
               org.eclipse.jetty.server,  
               org.eclipse.jetty.servlet,  
               org.eclipse.jetty.http,  
               org.eclipse.jetty.io,  
               org.eclipse.jetty.security,  
               org.eclipse.jetty.util,  
               org.eclipse.orion.server.core,  
               org.eclipse.orion.server.git,  
               org.eclipse.orion.server.servlets,  
               org.eclipse.equinox.http.registry  
             </Require-Bundle>  
           </instructions>  
         </configuration>  
       </plugin>  
     </plugins>  
   </build>  

And you have to add the Service Component class to get it activated at the startup. Code would be like following.

 package org.orion.sample.servlet.internal;  
 import org.osgi.service.component.ComponentContext;  
 /**  
  * @scr.component name="org.orion.sample.servlet.internal.ServletSampleServiceComponent" immediate="true"  
  */  
 public class ServletSampleServiceComponent {  
      protected void activate(ComponentContext context) {  
           System.out.println("Registration Complete");  
      }  
 }  

Now you can run mvn clean install on the package and build the jar file. Now go in to the Orion server folder and create a folder named dropins and copy your jar file in to dropins. Now edit

$ORION_HOME/configuration/org.eclipse.equinox.simpleconfigurator/bundles.info

file and following in the end add following line.

org.orion.sample.servlet,1.0.0,dropins/org.orion.sample.servlet-1.0.0.jar,4,false

[1] https://wiki.eclipse.org/Orion
[2] https://github.com/eclipse/orion.server
[3] https://github.com/eclipse/orion.client
[4] https://drive.google.com/open?id=0ByTCb2KmTk76OVMtcnplQnpOajQ

Comments

Popular posts from this blog

Generate JWT access tokens from WSO2 Identity Server

In Identity Server 5.2.0 we have created an interface to generate access tokens. Using that we have developed a sample to generate JWT tokens. You can find that sample under msf4j samples[1][2]. If you are build it as it is you will need to use Java 8 to build since msf4j is developed on Java 8. So you will need to run Identity Server on Java 8 as well. After building the project[2] please copy the jar inside target directory to $IS_HOME/repository/components/dropins/ directory. And then please add the following configuration to Identity.xml which is placed under $IS_HOME/repository/conf/identity/ folder inside tag OAuth . <IdentityOAuthTokenGenerator>com.wso2.jwt.token.builder.JWTAccessTokenBuilder</IdentityOAuthTokenGenerator> Then go to the database you used to store oauth tokens (This is the database pointed from the datasource you mentioned in the $IS_HOME/repository/conf/identity/identity.xml) and then alter the size of the column ACCESS_TOKEN of the tab...

Consuming File System artifacts from Kubernetes Pods

When you are deploying an application which contains artifacts written on file system dynamically withing kubernetes (k8s), for example a tomcat server exposed to outside to deploy war files, you need to make sure the file system state is preserved always. Otherwise if the pod goes down, you might loose data. So one solution is to mount an external disk. Yes indeed you can do that. But how robust is that solution. Say something happened to the external disk. How can you recover the data? Use several disks and rsync to sync the data. Sounds a robust solution. Say you want to increase the reliability. And what happens if rsync process get killed. How much will it cost to make it's reliability closer to 100%? We have a robust, simple solution. It's using gluster to save data. [1] [2] We install a pod named gluster for each node. There is an additional disk attached to each node which will be used as the data storage for gluster. This disk is formatted in a special forma...

Setting up Single node Kubernetes Cluster with Core OS bare metal

You might know already there is an official documentation to follow to setup a Kubernetes cluster on Core OS bare metal. But when do that specially single node cluster, I found some gaps in that documentation [1] . And another reason for this blog post is to get everything into one place. So this blog post will describe how to overcome the issues of setting up a single node cluster. Installing Core OS bare metal. You can refer to doc [2]  to install core os.  First thing is about users. Documentation [2]  tells you how to create a user without password. To login as that user you will need ssh keys. So to create a user with username password, you can use a cloud-config.yaml file. Here is a sample. #cloud-config users: - name: user passwd: $6$SALT$3MUMz4cNIRjQ/Knnc3gXjJLV1vdwFs2nLvh//nGtEh/.li04NodZJSfnc4jeCVHd7kKHGnq5MsenN.tO6Z.Cj/ groups: - sudo - docker Here value for passwd is a hash value. One of the below methods can be used...