Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Scout/Concepts/Servlets

< Scout‎ | Concepts
Revision as of 15:55, 9 October 2014 by Jeremie.bresson.unblu.com (Talk | contribs) (Security: fix link)

The Scout documentation has been moved to https://eclipsescout.github.io/. 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 The Scout documentation has been moved to https://eclipsescout.github.io/.. The The Scout documentation has been moved to https://eclipsescout.github.io/. 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

Note.png
TODO
Used by the RAP client to communicate with the server. Is this true?


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

Note.png
TODO
Link with Remote File


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 The Scout documentation has been moved to https://eclipsescout.github.io/..

See Also

Back to the top