45
votes

I made an RCP plugin with embedded Jetty as following:

1) In plugin.xml -> Dependencies, I have added the following:

org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.registry
org.mortbay.jetty.server
javax.servlet

2) In plugin.xml -> Extensions, I have added a Servlet extension point (org.eclipse.equinox.http.registry.servlet)

class: TemperatureServlet
alias:/temperature

The TemperatureServlet looks like this:

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TemperatureServlet extends HttpServlet {

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        System.out.println("doGet Called");

        resp.sendRedirect("Convertor.jsp");
    }
}

The file Convertor.jsp looks like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<f:view>
<h:form>
        <h:panelGrid columns="2">
            <h:outputLabel value="Celsius"></h:outputLabel>
            <h:inputText  value="#{temperatureConvertor.celsius}"></h:inputText>
        </h:panelGrid>
        <h:commandButton action="#{temperatureConvertor.celsiusToFahrenheit}" value="Calculate"></h:commandButton>
        <h:commandButton action="#{temperatureConvertor.reset}" value="Reset"></h:commandButton>
        <h:messages layout="table"></h:messages>
    </h:form>


    <h:panelGroup rendered="#{temperatureConvertor.initial!=true}">
    <h3> Result </h3>
    <h:outputLabel value="Fahrenheit "></h:outputLabel>
    <h:outputLabel value="#{temperatureConvertor.fahrenheit}"></h:outputLabel>
    </h:panelGroup>
</f:view>
</body>
</html>

The file faces-config.xml contains:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config
 xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">  
    <managed-bean>
        <managed-bean-name>temperatureConvertor</managed-bean-name>
        <managed-bean-class>hellojsf.TemperatureConvertor</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>

</faces-config>

My plugin has the following hierarchy:

plugin-name
---src
------class package
---------Activator.java
---------Application.java
---------ApplicationActionBarAdvisor.java
---------ApplicationWorkbenchWindowAdvisor.java
---------Perspective.java
---------TemperatureConvertor.java
---------TemperatureServlet.java
---META-INF
------MANIFEST.MF
---resources
-------WebContent
----------WEB-INF
-------------faces-config.xml
-------------web.xml
----------Convertor.jsp
---plugin.xml

In Activator class, method start(), I have started the web server like this:

public void start(BundleContext context) throws Exception {
        super.start(context);
        plugin = this;

        Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry");
        if (bundle.getState() == Bundle.RESOLVED) {
            bundle.start(Bundle.START_TRANSIENT);
        }

        Dictionary settings = new Hashtable();
        settings.put("http.enabled", Boolean.TRUE);
        settings.put("http.port", 8080);
        settings.put("http.host", "0.0.0.0");
        settings.put("https.enabled", Boolean.FALSE);
        settings.put("context.path", "/");
        settings.put("context.sessioninactiveinterval", 1800);

        try {
            JettyConfigurator.startServer(PLUGIN_ID + ".jetty", settings);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

To this plugin I have added also the following libraries:

  • JSTL: javax.servlet.jsp.jstl-1.2.1-javadoc.jar; javax.servlet.jsp.jstl-api-1.2.1-javadoc.jar
  • JSF 2.0 (Apache MyFaces JSF Core-2.0 API 2.0.2)

After I launch the application, if I type in my browser localhost:8080/temperature

It doesn't know where to find Convertor.jsp. My question is: how can I configure this plugin to know the resource location WebContent and the most important, how can I configure the plugin to know how to process JSFs and to know about the faces-config.xml and web.xml.

Can I, for example, when I define the extension org.eclipse.equinox.http.registry.servlets, do something like this? class: javax.faces.webapp.FacesServlet alis: /*.jsp

(all the files *.jsp to be processed by the FacesServlet)?

Thank you very much and sorry if the questions are silly, but I am new in this area of RCP plugins, Jetty and JSF.

2
I guess you already have solved this problem or else you wouldn't be asking new questions about JSF and all that stuff. Also, if you use JSF 2, then you should move to Facelets. I'll recommend you to read What are the differences between JSP and Facelets?, What is the difference between JSF, Servlet and JSP? and the links there. Don't take it as I'm against you, instead I don't have the exact answer for your question but just providing some guidance to a better path.Luiggi Mendoza
Also, if you have the answer to any of your questions, you can answer (and accept) them to help other people in this guidance.Luiggi Mendoza
Thank you very much for you advice!You guessed it well. I solved the problem,but I didn't have time to write a proper answer for it. But soon I will come back with the answer.wallE
@wallE you ready to write an answer?sharakan
did u try localhost:8080/ only. Did you copy you war file to war folder in jetty? It can pick files up with jetty running via terminal or maven [mvn jetty:run].A.P.S

2 Answers

1
votes

Take a look at setting a context in jetty. You can define it before start your server.

public class OneWebApp
{
    public static void main(String[] args) throws Exception
    {
        String jetty_home = System.getProperty("jetty.home","..");

        Server server = new Server(8080);

        WebAppContext webapp = new WebAppContext();
        webapp.setContextPath("/");
        webapp.setWar(jetty_home+"/webapps/test.war");
        server.setHandler(webapp);

        server.start();
        server.join();
    }
}
1
votes

A JSP Extension Factory class in org.eclipse.equinox.jsp.jasper.registry provides JSP support for use in conjunction with the servlets extension point.

The JSPFactory can be used in conjunction with org.eclipse.equinox.http.registry and the Servlets extension point to allow the use of JSPs declaratively with the extension registry.

JSPFactory will accept a "path" parameter corresponding to the base path in the bundle to look up JSP resources. This parameter can be set using the ":" separator approach or by xml parameter.

e.g. class="org.eclipse.equinox.jsp.jasper.registry.JSPFactory:/A/PATH" or