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

Difference between revisions of "Scout/Concepts/Servlets"

(Created page with "{{ScoutPage|cat=Server}} A Scout server application provides a set of servlets. == Servlets Extension point== The server runs into an OSGi container. The servlet are register...")
 
(Replaced content with "The Scout documentation has been moved to https://eclipsescout.github.io/.")
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{ScoutPage|cat=Server}}
+
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 <code>org.eclipse.equinox.http.registry.servlets</code> extension point. For each servlet you want to have in your application you need to defined them in the <code>plugin.xml</code> of your server application.
+
 
+
For example:
+
<source lang="xml">
+
    <extension
+
          name=""
+
          point="org.eclipse.equinox.http.registry.servlets">
+
      <servlet
+
            alias="/process"
+
            class="org.eclipse.scout.rt.server.ServiceTunnelServlet">
+
      </servlet>
+
    </extension>
+
</source>
+
 
+
The registration maps together the path that need to be called (alias) and a java class (extending <code>javax.servlet.Servlet</code>) 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 {{ScoutLink|Concepts|Communication|communication}}. The {{ScoutJavadoc|ClientHttpServiceTunnel|C}} calls the servlet on the <code>/process</code> path.
+
 
+
Usually the Tunnel is configured in the Client Session. The URL to this path is defined in the <code>server.url</code> property.
+
 
+
If called from a browser, this Servlet will provide some useful information and configuration possibilities.
+
 
+
[[File:Scout_MiniCRM_ServiceTunnelServlet_Process.png|500px]]
+
 
+
* 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|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: <code>{server bundle}/resources/html</code>
+
This page is served with a ResouceServlet registered like this in the <code>plugin.xml</code>:
+
<source lang="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>
+
</source>
+
 
+
As a result the <code>{server bundle}/resources/html/index.html</code> is served as default page in the server application:
+
 
+
[[File:MiniCRM_ResourceServlet_IndexHtml.png|500px]]
+
 
+
== RemoteFileServlet ==
+
{{Note|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:  
+
<code>org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticFactory.addDiagnosticStatusProvider()</code> and <code>org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticFactory.removeDiagnosticStatusProvider()</code>
+
 
+
Here an example how you can it under the /info path:
+
<source lang="xml">
+
      <servlet
+
            alias="/info"
+
            class="org.eclipse.scout.rt.server.admin.diagnostic.DiagnosticServlet">
+
      </servlet>
+
</source>
+
 
+
Here a preview how it could looks like (depending on the registered Diagnostic entities):
+
 
+
[[File:Eclipse_Scout-LunaM4-Diagnostics.png|500px]]
+
 
+
== 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:
+
<source lang="java">
+
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();
+
    }
+
  }
+
}
+
</source>
+
 
+
You need to register it (for example on the <code>/bundles</code> path):
+
<source lang="xml">
+
      <servlet
+
            alias="/bundles"
+
            class="org.eclipsescout.demo.minicrm.server.servlet.BundleListServlet">
+
      </servlet>
+
</source>
+
 
+
== Security ==
+
For each of the servlet you need to define who is allowed to call it. This is realized with a combination of {{ScoutLink|Concepts|Security#Security_Filters|security filters]].
+
 
+
== See Also ==
+
* {{ScoutLink|Concepts|Server Plug-In|Server Plug-In}}
+
* {{ScoutLink|Concepts|Security}}
+
* {{ScoutLink|Concepts|Communication}}
+

Latest revision as of 05:35, 14 March 2024

The Scout documentation has been moved to https://eclipsescout.github.io/.

Back to the top