Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Raffaele,

Yes, I completely agree with you that it should be simple to replace an api jar.

Unfortunately, the latest javax.mail-api jars have a hard dependency on the com.sun.java mail implementation. So it is not a pure api jar at all. It means that we can't supply a pure api jar and let a user drop in the mail implementation jar of their choice.  So in the future (eg jetty-10) I think we will stop supplying the api jar altogether for that reason, because it is useless to use at runtime. Users will need to supply whatever mail jars they like to use.

In the short-term, I think it is worthwhile to try and make the replacement of the mail jar more painless. I've opened this issue: https://github.com/eclipse/jetty.project/issues/1600 so watch for some commits there.

BTW, the solution you have found of course works, however it isn't very portable: when you next upgrade jetty you're going to have to do the same manual edit process on the new $jetty.home/modules/jndi.mod.  Having your own my-jndi.mod in your own $jetty.base means that it will be invariant across upgrades to $jetty.home.

cheers
Jan

On 7 June 2017 at 14:40, Raffaele Gambelli <R.Gambelli@xxxxxxxxxxxxxxxxxxxxxxx> wrote:
Thanks Jan,

I tried with your suggestion in a standalone localhost jetty without a configured jetty.base, so I directly edited the original jndi.mod changing its lib folder, where I copied javax.mail-1.5.6.jar in place of  javax.mail.glassfish-1.4.1.v201005082020.jar

I'm not sure to understand your comment here https://github.com/eclipse/jetty.project/issues/1597#issuecomment-306737724 because from my surely wrong point of view it should be a simple matter of replace a jar verifying that it doesn't introduce regressions, anyway in this way it seems that I found a solution, thanks

Raffaele Gambelli

-----jetty-users-bounces@eclipse.org ha scritto: -----
Per: JETTY user mailing list <jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@eclipse.org
Data: 07/06/2017 09.53AM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Raffaele,

If you want to use jndi and configure a Session in the container space that is linked into your webapp space via <resource-ref> entries in your web.xml, then you will need to have the new javax.mail jar on the container's classpath, not the webapps. So I'd use the suggestion I made on 10th May about making a new jndi module.

I'll look at updating the javax.mail jar as per the issue Joakim has raised, although last time I looked the newer jars were a problem due to incorrect manifest entries or some such.

Jan

On 6 June 2017 at 17:57, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
Hi all jetty users, hi Jan

my problems with javamail seem not come to ending...

now it's time of:
"java.lang.ClassCastException: javax.mail.Session cannot be cast to javax.mail.Session
at org.apache.commons.mail.Email.setMailSessionFromJNDI(Email. java:612)

I've recently configured a javax.mail.Session jndi resource, but as you probably remember (if not I'm replying in the same old thread) I've left both mail.jar, either in jetty lib or in webapp lib.

I can't use an old javamail version for my webapplication, I want to use the latest, 1.5.6, why does jetty has an old version? 
Maybe the solution is not using jndi at this point, what do you think? Thanks guys, bye

Raffaele Gambelli



-----jetty-users-bounces@ eclipse.org ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Raffaele Gambelli
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 11/05/2017 04.15PM

Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Happiness, it worked, thanks for your patience.

Now last question, suppose tomorrow I install another application which would make use of javax.mail but it doesn't contain it as dependency, this webapplication won't see javax.mail on jetty since I declared it "server", is it correct? It is only to know if I have understood.

Thanks

Raffaele Gambelli


-----jetty-users-bounces@ eclipse.org ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 11/05/2017 03.41PM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Raffaele,

A few things wrong here.

Firstly, jetty does not use META-INF/context.xml.  You need a jetty style context xml file. See https://www.eclipse.org/jetty/documentation/9.4.x/configuring-specific-webapp- deployment.html.

Secondly, you need both the xml snippets I posted, not just one. So you should have:

  <Call name="prependSystemClass">
       <Arg>-javax.mail.</Arg>
  </Call>
  <Call name="prependServerClass">
      <Arg>javax.mail.</Arg>
  </Call>

Jan

On 11 May 2017 at 15:24, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
It didn't work :( here it is my just deployed META-INF/context.xml of my webapp:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/mail-ws">
    <Call name="prependServerClass">
        <Arg>javax.mail.</Arg>
    </Call>
</Context>

And these are the log rows after having enabled  -Dorg.eclipse.jetty.webapp.Web AppClassLoader.LEVEL=DEBUG, are they saying something useful?

2017-05-11 15:21:41.205:DBUG:oejw.WebAppC lassLoader:main: loadClass(javax.mail.FetchProfile) system=true server=false cl=WebAppClassLoader=MailProxy Server@29ca901e
2017-05-11 15:21:41.205:DBUG:oejw.WebAppClassLoader:main: loaded class javax.mail.FetchProfile
2017-05-11 15:21:41.205:DBUG:oejw. WebAppClassLoader:main: loadedClass(javax.mail.FetchProfile)==class javax.mail.FetchProfile from=startJarLoader@214c265e tried_parent=true

Raffaele Gambelli



-----jetty-users-bounces@ eclipse.org ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 11/05/2017 02.14PM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

I'd like to see all the output from --list-modules. However, as the output says "transitive" there is something that is enabled that is transitively enabling jndi. It could be that you have "annotations" enabled, or "websocket" enabled, both of which transitively depend on the "plus" module, which itself depends on the "jndi" module.

Jan

On 11 May 2017 at 12:55, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
Thanks Jan, I'll try but I'm really don't understanding why the meaning of this output:

[t] Module: jndi
     Depend: server
        LIB: lib/jetty-jndi-${jetty.version }.jar
        LIB: lib/jndi/*.jar
    Enabled: <via> <transitive from> ${jetty.base}/start.ini

It says enabled but in start.ini the string "jndi" does not appear but the doc says that to disable a module I should comment it into start.ini, mumble mumble, am I wrong or it is a bit confusing?

Raffaele Gambelli


-----jetty-users-bounces@ eclipse.org ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 11/05/2017 12.43PM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

OK, well to be on the safe side, you can also add these lines to your context xml file:

  <Call name="prependServerClass">
   <Arg>javax.mail.</Arg>
  </Call>

They tell jetty that javax.mail should be something that is invisible to the user, but if it's provided inside the webapp use that instead.

If you do not do any jndi stuff, then jetty should be loading from the javax.mail jar inside your webapp.

To verify, run with -Dorg.eclipse.jetty.webapp.WebAppClassLoader.LEVEL=DEBUG and you will see where your javax.mail classes are being loaded from.

cheers
Jan

On 11 May 2017 at 12:26, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
Thanks Jan but in my start.ini I have no entry "jndi" but option --list-module effectly says (follows grep jndi):
 [t] Module: jndi
        LIB: lib/jetty-jndi-${jetty.version}.jar
        LIB: lib/jndi/*.jar
     Depend: jndi
    3) jndi            <transitive>


Ti disable module I'm following this doc:


-----jetty-users-bounces@ eclipse.org ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 11/05/2017 11.42AM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Raffaele,

So if you're not using jndi, then don't enable the jndi module, so the jetty-supplied javax.mail jar won't be on your classpath. Then leave the javax.mail-1.5.5 jar in your webapp.
Then, add these lines to the context xml file that sets up your webapp. These lines tell jetty that replacement of javax.mail from the system classpath by the webapp is permitted:

  <Call name="prependSystemClass">
   <Arg>-javax.mail.</Arg>
  </Call>

Jan

On 11 May 2017 at 11:09, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
Hi Jan, do you have some updates for me? 
Unfortunately jetty comes with an old version of javax.mail...

Thanks, best regards

Raffaele Gambelli

----- jetty-users-bounces@xxxxxxxxxxg ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Raffaele Gambelli
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 10/05/2017 04.47PM

Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Sure Jan and thank you again for your reactivity.

My webapp is a sort of mail server, configurable to handle one or more email accounts and listen for either new or removed messages, so I absolutely need to choose the javax.mail version.
No, I don't use jndi.

Thanks

Raffaele Gambelli



----- jetty-users-bounces@xxxxxxxxxxg ha scritto: -----
Per: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Da: Jan Bartel
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 10/05/2017 04.14PM
Oggetto: Re: [jetty-users] Force webapp to use different javax.mail from that one included in lib/jndi

Raffaele,

Before I answer you, please tell me whether you want to use javax.mail directly in your code to send/receive email, or do you want to use it with jndi, eg lookup a reference to "mail/Session" ?

Jan

On 10 May 2017 at 15:56, Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com> wrote:
Thanks Jan, but with your method, if jetty needs its javax.mail version and can't find it because I configured that it should use mine, what could happen?

And what about of javax.mail jar of my webapp? Should I remove it from war I suppose

I would prefer to find a way to preserve jetty javax.mail but to tell jetty to load my javax.mail when my webapp executes, am I wrong?

Raffaele Gambelli



----- jetty-users-bounces@xxxxxxxxxxg ha scritto: -----
Per: jetty-users@xxxxxxxxxxx
Da: jetty-users-request@xxxxxxxxxxg
Inviato da: jetty-users-bounces@xxxxxxxxxxg
Data: 10/05/2017 03.31PM
Oggetto: jetty-users Digest, Vol 96, Issue 5

Send jetty-users mailing list submissions to
jetty-users@xxxxxxxxxxx

To subscribe or unsubscribe via the World Wide Web, visit
https://dev.eclipse.org/mailman/listinfo/jetty-users
or, via email, send a message with subject or body 'help' to
jetty-users-request@xxxxxxxxxxg

You can reach the person managing the list at
jetty-users-owner@xxxxxxxxxxx

When replying, please edit your Subject line so it is more specific
than "Re: Contents of jetty-users digest..."


Today's Topics:

   1. Force webapp to use different javax.mail from that one
      included in lib/jndi (Raffaele Gambelli)
   2. Re: Force webapp to use different javax.mail from that one
      included in lib/jndi (Jan Bartel)


----------------------------------------------------------------------

Message: 1
Date: Wed, 10 May 2017 14:39:24 +0200
From: Raffaele Gambelli < R.Gambelli@hitachi-systems-cbt.com>
To: jetty-users@xxxxxxxxxxx
Subject: [jetty-users] Force webapp to use different javax.mail from
that one included in lib/jndi
Message-ID:
< OF86B8A80F.759A6E4E-ONC125811C.0045866D-C125811C.00458685@hitachi-systems-cbt. com>

Content-Type: text/plain; charset="us-ascii"

An HTML attachment was scrubbed...
URL: < https://dev.eclipse.org/mailman/private/jetty-users/attachments/20170510/2d1cfa24/ attachment.html>

------------------------------

Message: 2
Date: Wed, 10 May 2017 15:30:57 +0200
From: Jan Bartel < janb@xxxxxxxxxxx>
To: JETTY user mailing list < jetty-users@xxxxxxxxxxx>
Subject: Re: [jetty-users] Force webapp to use different javax.mail
from that one included in lib/jndi
Message-ID:
<CAEHc-33PCpifkrFbTWNihB88=- 9Ju= nPZRuiSGKjM1fZnAytZg@xxxxxxxxxl.com>
Content-Type: text/plain; charset="utf-8"


I'd probably make a fresh jndi.mod, called eg my-jndi.mod that is copied
from $JETTY_HOME/modules/jndi.mod and put it into $JETTY_BASE/modules. Then
I'd change the last line of it to refer to a different lib, eg lib/my-jndi.
So the module would look like this:

[name]
myjndi

[depend]
server

[lib]
lib/jetty-jndi-${jetty.version}.jar
lib/my-jndi/*.jar


Put the javax.mail jars and any others you need into
$JETTY_BASE/lib/my-jndi. Then all you need to do is to activate it with a
java -jar ../start.jar --add-to-start=my-jndi and you're done.

The good thing about this approach is that it is portable across any
updates to different versions of jetty.

Jan

On 10 May 2017 at 14:39, Raffaele Gambelli <
R.Gambelli@hitachi-systems- cbt.com> wrote:

> Hi all jetty-users,
>
> I'm quite newbie in Jetty, I've used Tomcat for many years, I would like
> to know the best practice to force my webapp to use javax.mail 1.5.5 since
> it is using javax.mail.glassfish-1.4.1.v201005082020.jar found
> on /srv/jetty/lib/jndi of jetty 9.3.10.
>
> I don't believe it is safe replace that version with that one wanted by my
> webapplication, is it true?
>
> At last if the best practice was to update the jar leaving it where it is,
> then should I remove that dependency from my webapp, in a way that in
> WEB-INF/lib it shouldn't be present?
>
> Really thanks in advance, best regards
>
> Raffaele Gambelli
>
>
>
> element
> Font
> font-family
> font-size
> font-style
> font-variant
> font-weight
> letter-spacing
> line-height
> text-decoration
> text-align
> text-indent
> text-transform
> white-space
> word-spacing
> color
> Background
> bg-attachment
> bg-color
> bg-image
> bg-position
> bg-repeat
> Box
> width
> height
> border-top
> border-right
> border-bottom
> border-left
> margin
> padding
> max-height
> min-height
> max-width
> min-width
> outline-color
> outline-style
> outline-width
> Positioning
> position
> top
> bottom
> right
> left
> float
> display
> clear
> z-index
> List
> list-style-image
> list-style-type
> list-style-position
> Table
> vertical-align
> border-collapse
> border-spacing
> caption-side
> empty-cells
> table-layout
> Effects
> text-shadow
> -webkit-box-shadow
> border-radius
> Other
> overflow
> cursor
> visibility
>
> ______________________________ _________________
> jetty-users mailing list
> 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
>



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
*Expert assistance from the creators of Jetty and CometD*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: < https://dev.eclipse.org/mailman/private/jetty-users/attachments/20170510/219e2331/ attachment.html>

------------------------------

_______________________________________________
jetty-users mailing list
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

End of jetty-users Digest, Vol 96, Issue 5
****************************** ************




_______________________________________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
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
______________________________ _________________
jetty-users mailing list
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

_______________________________________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

______________________________ _________________
jetty-users mailing list
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

_______________________________________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

______________________________ _________________
jetty-users mailing list
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

______________________________ _________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

______________________________ _________________
jetty-users mailing list
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

______________________________ _________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
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
_______________________________________________
jetty-users mailing list
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

______________________________ _________________
jetty-users mailing list
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



--
Jan Bartel < janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
jetty-users mailing list
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

_______________________________________________
jetty-users mailing list
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



--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD


Back to the top