Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No context loaded when using custom jetty.xml #198

Open
woulf opened this issue Nov 10, 2016 · 6 comments
Open

No context loaded when using custom jetty.xml #198

woulf opened this issue Nov 10, 2016 · 6 comments
Labels

Comments

@woulf
Copy link

woulf commented Nov 10, 2016

I might be missing something.
run jetty run build: nightly
eclipse: neon
jetty: 9.3.6

My webapp need a com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource, provided trough JNDI and a org.eclipse.jetty.security.JDBCLoginService. Therefore i provided the same jetty.xml i use on my production server with WAR deployed on it.

When running the app without the custom jetty.xml the console complain about the missing JNDI ressource, when running it with the custom jetty.xml the server start (really quickly compared to the production server), when i browse to the IP i only get 404 with no context referenced.

I tried adding to jetty.xml

<New class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath">/gateway</Set>
  <Set name="resourceBase">absolute\path\to\webapp</Set>
</New>

with no luck: still no error in the console, still 404

@xzer
Copy link
Owner

xzer commented Nov 11, 2016

It may be helpful If you can paste your jetty.xml, however I can share you my sample that I am using in my current work to show how to configure jndi support for RJR:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

    <New id="fooDataSource" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg></Arg>
        <Arg>jdbc/fooDataSource</Arg>
        <Arg>
         <New class="com.mchange.v2.c3p0.ComboPooledDataSource">
            <Set name="driverClass">org.postgresql.Driver</Set>
            <Set name="jdbcUrl">jdbc:postgresql://foo.local:5432/foo</Set>
            <Set name="user">foo</Set>
            <Set name="password">foo</Set>
            <Set name="initialPoolSize">2</Set>
            <Set name="minPoolSize">2</Set>
            <Set name="maxPoolSize">2</Set>
         </New>
        </Arg>
    </New>

</Configure>

And there is also another important thing you have to do :

At the launcher configuration window, where you configure the path of extra jetty.xml file, just above the input box of the path of jetty.xml, there is an checkbox named "JNDI Support", you must check it on.

Finally, you do not need to configure the context in the jetty.xml, the RJR will handle it well.

@woulf
Copy link
Author

woulf commented Nov 14, 2016

Ok so i managed to work this issue, based on your jetty.xml with this one:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

<New id="ressourcename" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jdbc/ressourcename</Arg>
    <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
             <Set name="Url">jdbc:mysql://IP:PORT/ressourcename</Set>
             <Set name="User">username</Set>
             <Set name="Password">password</Set>
            </New>
    </Arg>
</New>
<Call name="addBean">
    <Arg> 
        <New class="org.eclipse.jetty.security.JDBCLoginService">
          <Set name="name">ressourcename_jndi</Set>
          <Set name="config">absolute\path\to\jdbcRealm.properties</Set>
        </New>
    </Arg>
</Call>

Now i'm facing a second error regarding Weld:

WELD-001300: Unable to locate BeanManager

this seems due to WebAppContext configuration, as defined in jetty-env.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN"   "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="serverClasses">

    <Array type="java.lang.String">

        <Item>-org.eclipse.jetty.servlet.ServletContextHandler.Decorator</Item>

    </Array>

</Set>
<New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">

    <Arg></Arg>

    <Arg>BeanManager</Arg>

    <Arg>

        <New class="javax.naming.Reference">

            <Arg>javax.enterprise.inject.spi.BeanManager</Arg>

            <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>

            <Arg/>
        </New>

    </Arg>

</New>

i tried definining solely the jndi ressource in jetty.xml but it seems the classloading is mandatory, any way to do that using RJR?

@xzer
Copy link
Owner

xzer commented Nov 15, 2016

I am sorry that I am not familiar with WELD.

I don't know how you attach the jetty-env.xml to RJR? It seems that there is no way to do that.

Anyway, Since the BeanManager is a jndi resource, I think you can declare it in server scope instead of context scope.

And also, once I did something like following in my own project, which may be helpful if you have to do something on WebAppContext rather than Server:

<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <!--
    <Get id="defaultHandler" name="handler">
        <Call name="setAttribute">
          <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg>
          <Arg>xyz</Arg>
        </Call>
    </Get>
    -->

    <Set class="com.foo.jetty.hack.StartHacker" name="attr"><Get id="defaultHandler" name="handler"/></Set>

</Configure>

<Get id="defaultHandler" name="handler"/> will return the current (default) WebAppContext instance.
Notice the commented part, theoretically it should work but it does not work well due to the invoking order from jetty, thus I did some trick by the row not commented:

<Set class="com.foo.jetty.hack.StartHacker" name="attr"><Get id="defaultHandler" name="handler"/></Set>

StartHacker is a simple independent java class as following:

public class StartHacker {
    public final static void setAttr(Object obj) {
        if (obj == null) {
            return;
        }

        try {
            Method m = obj.getClass().getMethod("setAttribute", String.class, Object.class);
            Object[] params = new Object[] { "org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern", "xyz" };
            m.invoke(obj, params);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}

You should compile it and package it to a independent jar file and then add it to the RJR's runtime classpath, then you can configure the WebAppContext by java code.

It is not so beautiful but it works for me. And because the RJR have to configure the context by current java project, it is really difficult to allow developers to customize the context. An jetty expert may be helpful on addressing this issue but I am still waiting for that guy.

@woulf
Copy link
Author

woulf commented Nov 15, 2016

i don't actually attach the jetty-env to RJR, in a "non-embedded" deployement it is just read because it is in the web-inf folder, in this case i understand i don't work.
I'll try to use your Class and keep you updated with the results

@woulf
Copy link
Author

woulf commented Nov 15, 2016

got the same result.
Think i won't use Jetty for my local debug.
I let you close the issue if you think it can't be resolved

@xzer
Copy link
Owner

xzer commented Nov 17, 2016

Thanks for your report. I will keep this ticket opening because I think RJR should load the jetty-eny under WEB-INF, which should be considered as a bug.

@xzer xzer added the wontfix label Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants