Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Jetty 9.4 issue while rendering JSP page

Not sure if it's the cause of your problem but given the names of the jars that contain the jstl libs (or the ones with "taglib" in them) don't match the pattern you've specified for the containerincludejarpattern you should fix that.
Jan

On Fri., 6 Jul. 2018, 09:54 Greg Wilkins, <gregw@xxxxxxxxxxx> wrote:

Hi,

I'm sorry but you've not well described your problem and giving us a lot of code does not help at all.


I suggest that you start with one of the examples from 9.4 that provides a sample JSP and then just change that to add in your JSPs and anything else you need.

regards




On 6 July 2018 at 08:44, Vibhas Karn <vibhaskk@xxxxxxxxx> wrote:

Hi All,

 

I am struggling with jetty Migration of 6.1 to latest or anything above Jetty 9.1 . Currently I am trying with Jetty 9.4 which is latest.

I am able to compile the old code with the new one but there are few issues with the migration which I am trying to fix. Yes its the tough job but no option left.

I am currently focussing to render the old jsp pages after migrating it to Jetty 9.4. Here is the sample code , I have mentioned the problem in the post below. Help me with you suggestion or anything as I am struggling to fix this issue since a week now.

 

JettyServer Sample Code :

 

public class JettyServer extends AbstractService implements IJettyServer, IStatus {

    public static final String SERVICE_NAME = "JettyServer"; //frozen

    private static final Logger log = Logger.getLogger(JettyServer.class.getName());

    private static JettyServer instance = null;

    private Server server;

 

    // The map of service id to the jetty slave.

    private final Map<Integer, IJettySlave> idToSlaveMap = new HashMap<Integer, IJettySlave>();

 

    // A linked list of the slaves.

    private final List<IJettySlave> availableSlaves = new LinkedList<IJettySlave>();

 

    // TODO ref count availableAPIs.

    private final Set<Class> availableAPIs = new HashSet<Class>();

 

    // The map of service if to the slave status.

    private final Map<Integer, IStatus> idToStatusMap = new HashMap<Integer, IStatus>();

    private final int registryPort;

    private int maxWaitForSlave = 0;

 

    /**

     * Creates a new JettyServer using the default registry port from the ServiceControllerConfig.

     * @throws RemoteException when RMI problems occur.

     */

    public JettyServer() throws RemoteException {

        this(ServiceControllerConfig.getInstance().getControlPort());

    }

 

    /**

     * Creates a new JettyServer using the control port passed.

     * @param registryPort the registry port.

     * @throws RemoteException when RMI problems occur.

     */

    public JettyServer(final int registryPort) throws RemoteException {

        this.registryPort = registryPort;

        instance = this;

    }

 

    @Override

    public void initialize(final ServiceConfiguration genericConfig, final Controller controller, final int serviceId,

        final ServiceLock lock) throws Exception {

        if (genericConfig instanceof JettyServerConfiguration) {

            configuration = (JettyServerConfiguration) genericConfig;

        } else {

            configuration = XmlConfigurable.createInstance(JettyServerConfiguration.class,

                    genericConfig.getXmlConfigElement());

        }

 

        server = new Server();

        log.info("jetty version = " + Server.getVersion()); //frozen

 

        maxWaitForSlave = getConfiguration().getMaxWaitForSlave();

 

        final boolean debug = getConfiguration().getMortBayDebug();

        log.info("Eclipse mortbay debug = '" + debug + "'"); //frozen

        org.eclipse.jetty.util.log.Log.getLog().setDebugEnabled(debug);

 

        // Configure http

        final boolean httpEnabled = getConfiguration().getHttpEnabled();

 

        if (httpEnabled) {

            final int mainPort = getConfiguration().getHttpPort();

 

            log.info("adding default connector on port '" + mainPort + "'"); //frozen

                                                                             //Re-writing the code for jetty 9.3

                                                                             // Setup HTTP Connector

 

            HttpConfiguration httpConf = new HttpConfiguration();

            httpConf.setSecurePort(mainPort);

            httpConf.setSecureScheme("https");

 

            // Establish the HTTP ServerConnector

            ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(httpConf));

            httpConnector.setPort(mainPort);

            server.addConnector(httpConnector);

        }

 

        // Configure SSL

        final boolean sslEnabled = getConfiguration().getSslEnabled();

 

        if (sslEnabled) {

            //Re-writing code for Jetty 9.3

            final int mainPort = getConfiguration().getHttpPort(); //8580

            final int sslPort = getConfiguration().getSslPort(); //8581

            final String sslKeyStore = getConfiguration().getSslKeyStore();

            final String sslPassword = getConfiguration().getSslPassword();

            final String sslKeyPassword = getConfiguration().getSslKeyPassword();

            final String sslTrustPassword = getConfiguration().getSslTrustPassword();

 

           //Added for  Jetty 9.3

            final KeyStore trustKeyStore = KeyStore.getInstance(getConfiguration().getSslKeyStore());

 

            SslContextFactory theSSLFactory = new SslContextFactory();

 

            theSSLFactory.setKeyStorePath(sslKeyStore);

            theSSLFactory.setKeyManagerPassword(sslPassword);

            theSSLFactory.setKeyStorePassword(sslKeyPassword);

            theSSLFactory.setTrustStore(trustKeyStore);

            theSSLFactory.setTrustStorePassword(sslTrustPassword);

 

            // Setup HTTP Connector

            HttpConfiguration httpConf = new HttpConfiguration();

            httpConf.setSecurePort(mainPort);

            httpConf.setSecureScheme("https");

 

            // Setup HTTPS Configuration

            HttpConfiguration httpsConf = new HttpConfiguration(httpConf);

            httpsConf.addCustomizer(new SecureRequestCustomizer()); // adds ssl info to request object

 

            // Establish the HTTPS ServerConnector

            ServerConnector httpsConnector = new ServerConnector(server,

                    new SslConnectionFactory(theSSLFactory, "http/1.1"), new HttpConnectionFactory(httpsConf));

            httpsConnector.setPort(sslPort);

 

            log.info("adding ssl connector on port '" + sslPort + "'"); //frozen

            server.addConnector(httpsConnector);

 

            //}

        }

 

        // Check we had 1 connector else the server is useless

        if (server.getConnectors().length == 0) {

            throw new FileNotFoundException("No connectors registered.  Please see HttpEnable or SslEnable XML tags."); //frozen

        }

 

        // Configure the handlers

        final HandlerCollection handlers = new HandlerCollection();

 

        //4. Enabling the Annotation based configuration

        org.eclipse.jetty.webapp.Configuration.ClassList classlist = org.eclipse.jetty.webapp.Configuration.ClassList.setServerDefault(server);

        classlist.addAfter("org.eclipse.jetty.webapp.FragmentConfiguration",

           "org.eclipse.jetty.plus.webapp.EnvConfiguration", "org.eclipse.jetty.plus.webapp.PlusConfiguration");

        classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration",

            "org.eclipse.jetty.annotations.AnnotationConfiguration");

 

        for (final WebAppContext webAppContext : getConfiguration().getWebAppContexts()) {

            log.info("Adding WebAppContext " + webAppContext.getWar() + " at " + webAppContext.getContextPath()); //frozen

 

            webAppContext.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",

                ".*/[^/]*jstl.*\\.jar$");

            handlers.addHandler(webAppContext);

        }

 

        final boolean accessLogEnabled = getConfiguration().getLogEnabled();

 

        if (accessLogEnabled) {

            final RequestLogHandler requestLogHandler = new RequestLogHandler();

            final File logDir = ServiceUtilities.getLogDirectory();

 

            if (!logDir.exists()) {

                logDir.mkdirs();

            }

 

            final File logFile = new File(getConfiguration().getLogFormat());

 

            if (!logFile.getParentFile().exists()) {

                logFile.getParentFile().mkdirs();

            }

 

            final NCSARequestLog requestLog = new NCSARequestLog(getConfiguration().getLogFormat());

            requestLog.setRetainDays(getConfiguration().getLogRetain());

            requestLog.setAppend(getConfiguration().getLogAppend());

            requestLog.setExtended(getConfiguration().getLogExtended());

            requestLog.setLogTimeZone(getConfiguration().getLogTz());

            requestLog.setLogLatency(getConfiguration().getLogLatency());

            requestLogHandler.setRequestLog(requestLog);

            handlers.addHandler(requestLogHandler);

        }

 

        handlers.addHandler(new DefaultHandler());

 

        server.setHandler(handlers);

 

        // server.setUserRealms(new UserRealm[] { new OSMUserRealm() });

        // server.addBean(new LoginService[] { new OSMUserRealm() });

 

        // HashLoginService loginService = new HashLoginService();

        //loginService.setName("osmRealm");

        //server.addBean(loginService);

 

        // log.info("initialize...." + loginService.getName());

        JettyServerInfo.install(server);

 

        super.initialize(configuration, controller, serviceId, lock);

    }

 

    @Override

    public JettyServerConfiguration getConfiguration() {

        return (JettyServerConfiguration) super.getConfiguration();

    }

 

    @Override

    public synchronized void stop() {

        final Thread t = new Thread("JettyServer Stop Thread") { //frozen

                @Override

                public void run() {

                    try {

                        server.stop();

                    } catch (Exception ex) {

                        log.log(Level.SEVERE, "Failed to stop Jetty server", ex); //frozen

                    }

                }

            };

 

        t.start();

 

        try {

            t.join(500);

        } catch (final InterruptedException ex) {

        }

 

        super.stop();

    }

 

    @Override

    public synchronized void start() throws Exception {

        log.info("start()"); //frozen

 

        registerJetty();

 

        server.start();

 

        // finish startup which registers with the controller

        super.start();

 

        server.join(); //For Jetty 9.3 and above

 

        // server.join(); need to uncomment and verify if jetty if we need server.join in Jetty 9.3 as previous person don't have

        log.info("After Jetty 9.3 Services starts..");

    }

 

    private void registerJetty() throws RemoteException, AlreadyBoundException, AlreadyBoundException {

        final Registry registry = LocateRegistry.getRegistry("127.0.0.1", registryPort); //frozen

 

        final Remote remote = UnicastRemoteObject.toStub(this);

        log.info("Registering JettyServer"); //frozen

        registry.rebind(IJettyServer.JETTYSERVER_NAME, remote);

    }

 

    @Override

    public void unregister(final IJettySlave slave) throws RemoteException {

        log.info("unregister(" + slave.getName() + ") (ID=" + slave.getServiceID() + ")"); //frozen

 

        synchronized (idToSlaveMap) {

            idToSlaveMap.remove(slave.getServiceID());

 

            if (slave instanceof IStatus) {

                synchronized (idToStatusMap) {

                    idToStatusMap.remove(slave.getServiceID());

                }

            }

        }

 

        synchronized (availableSlaves) {

            // Shouldnt really be in the list as teh BusyAPIDynamicProxy shouldnt

            // have re-added it on a shutdown.

            if (availableSlaves.remove(slave)) {

                availableSlaves.notifyAll();

            }

        }

    }

 

    @Override

    public void register(final IJettySlave slave) throws RemoteException {

        log.info("registered(" + slave.getName() + ") (ID=" + slave.getServiceID() + ")"); //frozen

 

        synchronized (idToSlaveMap) {

            idToSlaveMap.put(slave.getServiceID(), slave);

 

            if (slave instanceof IStatus) {

                synchronized (idToStatusMap) {

                    idToStatusMap.put(slave.getServiceID(), (IStatus) slave);

                }

            }

        }

 

        synchronized (availableSlaves) {

            availableSlaves.add(slave);

            availableSlaves.notifyAll();

        }

 

        synchronized (availableAPIs) {

            availableAPIs.addAll(slave.getAPIs());

        }

    }

 

    public static JettyServer getInstance() {

        return instance;

    }

 

    public <I extends Remote> I get(final Class<I> i) throws RemoteException {

        return createApiProxy(i);

    }

 

    void push(final IJettySlave slave) {

        synchronized (availableSlaves) {

            availableSlaves.add(0, slave);

            availableSlaves.notifyAll();

        }

    }

 

    <I extends Remote> IJettySlave pop(final Class<I> i)

        throws RemoteException {

        if (idToSlaveMap.isEmpty()) {

            throw new IllegalStateException("No JettySlaves available, please check the server log files."); //frozen

        }

 

        if (availableAPIs.isEmpty()) {

            throw new IllegalStateException("No JettySlave APIs available, please check the server log files."); //frozen

        }

 

        synchronized (availableAPIs) {

            // Check if any slave provides this API, as its pointless waiting

            // when we know an API will not be available.

            // FYI : This should be removed if we provide auto startup of slaves.

            if (!availableAPIs.contains(i)) {

                throw new RemoteException("API " + i.getName() + " is not available."); //frozen

            }

        }

 

        final long end = System.currentTimeMillis() + maxWaitForSlave;

 

        while (System.currentTimeMillis() < end) {

            synchronized (availableSlaves) {

                // Get a service from any idle slave.

                final Iterator<IJettySlave> it = availableSlaves.iterator();

 

                while (it.hasNext()) {

                    final IJettySlave slave = it.next();

 

                    try {

                        final I slaveApi = slave.get(i);

 

                        if (slaveApi != null) {

                            it.remove(); // remove this slave from list

 

                            return slave;

                        }

                    } catch (final RemoteException re) {

                        // this host doesnt work so remove it.

                        it.remove();

                    }

                }

 

                // now wait for a slave to become inactive

                final long sleep = end - System.currentTimeMillis();

 

                try {

                    if (sleep > 0) {

                        availableSlaves.wait(sleep);

                    }

                } catch (final InterruptedException ex) {

                }

            }

        }

 

        throw new IllegalStateException("All APIs '" + i.getName() + "' are busy or unavailable."); //frozen

    }

 

    /**

     * Creates a proxy for the specific interface.

     * @param <I> a remote interface class.

     * @param i the remote interface class

     * @return the proxy for this interface.

     * @throws RemoteException when RMI fails.

     * @see BusyAPIDynamicProxy

     */

    @SuppressWarnings("unchecked")

    private <I extends Remote> I createApiProxy(final Class<I> i)

        throws RemoteException {

        // Insert the busy dynamic proxy so we know which is busy

        final I proxy = (I) java.lang.reflect.Proxy.newProxyInstance(i.getClassLoader(), new Class[] { i },

                new BusyAPIDynamicProxy<I>(this, i));

 

        return proxy;

    }

 

    public final Map<Integer, IStatus> getSlaveStatus()

        throws RemoteException {

        return new TreeMap<Integer, IStatus>(idToStatusMap);

    }

 

    public final IStatus getStatus() {

        return this;

    }

 

    @Override

    public long getUpTime() throws RemoteException {

        final java.lang.management.RuntimeMXBean mx = java.lang.management.ManagementFactory.getRuntimeMXBean();

 

        return mx.getUptime() / 1000;

    }

 

    @Override

    public long getTotalMemory() throws RemoteException {

        return Runtime.getRuntime().totalMemory();

    }

 

    @Override

    public long getFreeMemory() throws RemoteException {

        return Runtime.getRuntime().freeMemory();

    }

 

    @Override

    public long getMaxMemory() throws RemoteException {

        return Runtime.getRuntime().maxMemory();

    }

 

    public static void main(final String[] args) throws Exception {

        // jetty depends on the registry all the time.

        LocateRegistry.createRegistry(ServiceControllerConfig.getInstance().getControlPort());

 

        System.setProperty("service.id", "-1"); //frozen

 

        runStandalone(SERVICE_NAME);

 

        // jetty server depends on a slave working.

        runStandalone("JettySlave1"); //frozen

    }

}

 

Jetty Configuration class:

 

/**

* RCS: $Id: //oswm/rel20.10_Patches/WorkManager/src/com/osm/services/webservice/JettyServerConfiguration.java#1 $

* Last Modified: $Author: adminp4 $, $DateTime: 2018/03/28 14:59:10 $

*/

package com.osm.services.webservice;

 

import java.io.File;

 

import java.util.ArrayList;

import java.util.List;

import java.util.logging.Logger;

 

import org.eclipse.jetty.webapp.WebAppContext;

 

import org.w3c.dom.Element;

 

import com.osm.services.configuration.ManagerServiceConfiguration;

 

 

public class JettyServerConfiguration extends ManagerServiceConfiguration {

    private static final Logger log = Logger.getLogger(JettyServerConfiguration.class.getName());

    private static final String WAR_TAG = "War"; //frozen

    private static final String MAX_WAIT_FOR_SLAVE_TAG = "MaxWaitForSlave"; //frozen

    private static final String MORTBAY_DEBUG_TAG = "MortBayDebug"; //frozen

    private static final String HTTP_ENABLED_TAG = "HttpEnabled"; //frozen

    private static final String HTTP_PORT_TAG = "HttpPort"; //frozen

    private static final String NIO_ENABLED_TAG = "NioEnabled"; //frozen

 

    // SSL specific

    private static final String SSL_ENABLED_TAG = "SslEnabled"; //frozen

    private static final String SSL_PORT_TAG = "SslPort"; //frozen

    private static final String SSL_KEY_STORE_TAG = "SslKeyStore"; //frozen

    private static final String SSL_PASSWORD_TAG = "SslPassword"; //frozen

    private static final String SSL_KEY_PASSWORD_TAG = "SslKeyPassword"; //frozen

    private static final String SSL_TRUST_PASSWORD_TAG = "SslTrustPassword"; //frozen

 

    // Log specific

    private static final String ACCESS_LOG_FORMAT_TAG = "AccessLogFormat"; //frozen

    private static final String ACCESS_LOG_ENABLED_TAG = "AccessLogEnabled"; //frozen

    private static final String ACCESS_LOG_RETAIN_TAG = "AccessLogRetainDays"; //frozen

    private static final String ACCESS_LOG_APPEND_TAG = "AccessLogAppend"; //frozen

    private static final String ACCESS_LOG_EXTENDED_TAG = "AccessLogExtended"; //frozen

    private static final String ACCESS_LOG_LATENCY_TAG = "AccessLogLatency"; //frozen

    private static final String ACCESS_LOG_TZ_TAG = "AccessLogTimeZone"; //frozen

 

    // Read values

    private List<WebAppContext> warContexts = new ArrayList<WebAppContext>();

    private int maxWaitForSlaves;

    private boolean mortBayDebug;

    private boolean httpEnabled;

    private int httpPort;

    private boolean nioEnabled;

    private boolean sslEnabled;

    private int sslPort;

    private String sslKeyStore;

    private String sslPassword;

    private String sslKeyPassword;

    private String sslTrustPassword;

    private boolean logEnabled;

    private String logFormat;

    private int logRetain;

    private boolean logAppend;

    private boolean logExtended;

    private boolean logLatency;

    private String logTz;

 

    public JettyServerConfiguration() {

    }

 

    @Override

    public void configure(final Element xmlConfigElement) {

        super.configure(xmlConfigElement);

 

        final List<Element> warElements = getChildren(WAR_TAG);

 

        for (final Element warElement : warElements) {

            final String context = warElement.getAttribute("context"); //frozen

            final String location = warElement.getAttribute("location"); //frozen

 

            if ((location != null) && !location.isEmpty()) {

                // check file is valid

                final File f = new File(location);

 

                if (!f.exists()) {

                    log.warning("War location '" + f.getAbsolutePath() + "' does not exists."); //frozen

                }

 

                final WebAppContext webAppContext = new WebAppContext();

                webAppContext.setContextPath(context);

                webAppContext.setResourceBase(f.getAbsolutePath()); //added in 9.3

                webAppContext.setWar(f.getAbsolutePath());

                webAppContext.setExtractWAR(false);

 

                warContexts.add(webAppContext);

 

                log.info("Context Path-->" + context);

                log.info("War location-->" + f.getAbsolutePath());

            } else {

                throw new IllegalStateException("War location must be specified."); //frozen

            }

        }

 

        maxWaitForSlaves = getChildValueAsInteger(MAX_WAIT_FOR_SLAVE_TAG, 4 * 60 * 1000);

        mortBayDebug = getChildValueAsBoolean(MORTBAY_DEBUG_TAG, false);

        httpEnabled = getChildValueAsBoolean(HTTP_ENABLED_TAG, true);

        nioEnabled = getChildValueAsBoolean(NIO_ENABLED_TAG, false);

        httpPort = getChildValueAsInteger(HTTP_PORT_TAG, 8580);

 

        sslEnabled = getChildValueAsBoolean(SSL_ENABLED_TAG, false);

        sslPort = getChildValueAsInteger(SSL_PORT_TAG, 8581);

        sslKeyPassword = getChildValue(SSL_KEY_PASSWORD_TAG);

        sslKeyStore = getChildValue(SSL_KEY_STORE_TAG);

        sslPassword = getChildValue(SSL_PASSWORD_TAG);

        sslTrustPassword = getChildValue(SSL_TRUST_PASSWORD_TAG);

 

        logEnabled = getChildValueAsBoolean(ACCESS_LOG_ENABLED_TAG, true);

        logFormat = getChildValue(ACCESS_LOG_FORMAT_TAG, "logs/access_logs/yyyy_mm_dd.access.log"); //frozen

        logRetain = getChildValueAsInteger(ACCESS_LOG_RETAIN_TAG, 90);

        logAppend = getChildValueAsBoolean(ACCESS_LOG_APPEND_TAG, true);

        logExtended = getChildValueAsBoolean(ACCESS_LOG_EXTENDED_TAG, false);

        logLatency = getChildValueAsBoolean(ACCESS_LOG_LATENCY_TAG, false);

        logTz = getChildValue(ACCESS_LOG_TZ_TAG, "GMT"); //frozen

 

        log.info("End of Configuration..");

    }

 

    public int getHttpPort() {

        return httpPort;

    }

 

    public boolean getNioEnabled() {

        return nioEnabled;

    }

 

    public boolean getHttpEnabled() {

        return httpEnabled;

    }

 

    public List<WebAppContext> getWebAppContexts() {

        return warContexts;

    }

 

    public int getMaxWaitForSlave() {

        return maxWaitForSlaves;

    }

 

    public boolean getMortBayDebug() {

        return mortBayDebug;

    }

 

    public boolean getSslEnabled() {

        return sslEnabled;

    }

 

    public int getSslPort() {

        return sslPort;

    }

 

    public String getSslKeyStore() {

        return sslKeyStore;

    }

 

    public String getSslPassword() {

        return sslPassword;

    }

 

    public String getSslKeyPassword() {

        return sslKeyPassword;

    }

 

    public String getSslTrustPassword() {

        return sslTrustPassword;

    }

 

    public boolean getLogEnabled() {

        return logEnabled;

    }

 

    public String getLogFormat() {

        return logFormat;

    }

 

    public int getLogRetain() {

        return logRetain;

    }

 

    public boolean getLogAppend() {

jetty-users@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top