Skip to main content
Jump to: navigation, search

Scout/Concepts/Servlets


Scout
Wiki Home
Website
DownloadGit
Community
ForumsBlogTwitterG+
Bugzilla
Bugzilla

A Scout server application provides a set of servlets.

Servlets Extension point

The server runs into an OSGi container. The servlet are registered by using the org.eclipse.equinox.http.registry.servlets extension point. For each servlet you want to have in your application you need to defined them in the plugin.xml of your server application.

For example:

    <extension
          name=""
          point="org.eclipse.equinox.http.registry.servlets">
       <servlet
             alias="/process"
             class="org.eclipse.scout.rt.server.ServiceTunnelServlet">
       </servlet>
    </extension>

The registration maps together the path that need to be called (alias) and a java class (extending javax.servlet.Servlet) that will handle the HTTP request. It is also possible to initialize the servlet with some parameters.

ServiceTunnelServlet

This is the main Servlet of a scout server application.

Path: /process

This is the main entry point for client-server communication. The C obj.pngClientHttpServiceTunnel calls the servlet on the /process path.

Usually the Tunnel is configured in the Client Session. The URL to this path is defined in the server.url property.

If called from a browser, this Servlet will provide some useful information and configuration possibilities.

Scout MiniCRM ServiceTunnelServlet Process.png

  • General: you can find here some general informations (Session, Jaas context, product id)
    • Monitoring: you can activate or deactivate the monitoring of your application
    • Log level: you can change the log level on the fly.
  • Services: Description of the different services served by the scout Server. For each service the class and interface hierarchy is provided and the list of available operations on this service (with the corresponding method signature). The services are classified like this:
    • Outline Services
    • Lookup Services
    • Common Services
    • Other Services

Path: /ajax

On the /ajax path, the ServiceTunnelServlet is also registred. The difference to /process is that no security filter for authentication are registered.

When the Scout application is deployed as webapplication (RAP UI), there are two servers:

  • the scout-server like for the other UIs.
  • the RAP-server that is also the scout-client.

In this configuration, authentication should happend on the RAP-server. It is expected that the scout client put a Subject on the Session. In this case, the client can call this specific backend (without any authentication).

ResourceServlet

This servlet is useful to serve some resources. This servlet expect some arguments:

  • bundle-name: the name of the bundle where the resource is
  • bundle-path: the path within the bundle where the resource is

Path: /

When they are created with the new scout project wizard, the server application contains an html index page, located here: {server bundle}/resources/html This page is served with a ResouceServlet registered like this in the plugin.xml:

      <servlet
            alias="/"
            class="org.eclipse.scout.rt.server.ResourceServlet">
         <init-param
               name="bundle-name"
               value="org.eclipsescout.demo.minicrm.server">
         </init-param>
         <init-param
               name="bundle-path"
               value="/resources/html">
         </init-param>
      </servlet>

As a result the {server bundle}/resources/html/index.html is served as default page in the server application:

MiniCRM ResourceServlet IndexHtml.png

RemoteFileServlet

Diagnostic Servlet

Introduced with Scout 3.10 this servlet displays some diagnostic information. This creates an html page with diagnostic information like JVM Memory allocation and cpu architecture. It is also possible to add diagnostic information from any class entity. If an Entity wants to provide diagnostic status info it has to implement org.eclipse.scout.rt.server.admin.diagnostic.IDiagnostic and has to register itself at the DiagnosticFactory: org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticFactory.addDiagnosticStatusProvider() and org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticFactory.removeDiagnosticStatusProvider()

Here an example how you can it under the /info path:

      <servlet
            alias="/info"
            class="org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticServlet">
      </servlet>

Here a preview how it could looks like (depending on the registered Diagnostic entities):

Eclipse Scout-LunaM4-Diagnostics.png

Custom servlet

Of course you can write your own servlet and register it.

Here an example of a servlet returning as JSON string the list of all osgi-bundles contained in the server:

import java.io.IOException;
import java.io.PrintWriter;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import org.eclipse.scout.rt.server.commons.servletfilter.HttpServletEx;
import org.eclipsescout.demo.minicrm.server.Activator;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
 
/**
 * Example Servlet:
 * Provides the list of the installed bundle as JSON String.
 */
public class BundleListServlet extends HttpServletEx {
  private static final long serialVersionUID = 1L;
 
  @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try {
      BundleContext context = Activator.getDefault().getBundle().getBundleContext();
 
      response.setContentType("application/json");
      PrintWriter out = response.getWriter();
      out.print("{");
      out.print("\"bundles\": [");
      boolean first = true;
      for (Bundle b : context.getBundles()) {
        if (first) {
          first = false;
        }
        else {
          out.print(" , ");
        }
        out.print("{ \"Symbolic Name\": \"" + b.getSymbolicName() + "\",");
        out.print("\"Version\": \"" + b.getVersion().toString() + "\"}");
      }
      out.print(" ] ");
      out.print("}");
      out.close();
    }
    catch (IOException e) {
      e.printStackTrace();
    }
  }
}

You need to register it (for example on the /bundles path):

      <servlet
            alias="/bundles"
            class="org.eclipsescout.demo.minicrm.server.servlet.BundleListServlet">
      </servlet>

Security

For each of the servlet you need to define who is allowed to call it. This is realized with a combination of security filters.

See Also

Back to the top