Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread Garret Wilson

On 4/19/2019 8:04 PM, Rémy Maucherat wrote:

On Fri, Apr 19, 2019 at 11:14 PM Garret Wilson 
wrote:


On 4/19/2019 3:24 PM, Rémy Maucherat wrote:


tomcat.getService().addConnector(new Connector()); works very well, etc,
just look at what getConnector() does, it's very simple.


I did look at that first; that's why I mentioned the magic strings such 
as "HTTP/1.1". If I just use `new Connector()`, I may get something 
different than if I say `new Connector("HTTP/1.1")`. The latter 
potentially takes advantage of the APR connector if present; the former 
does not. (And how would I know that without looking at the source code?)


I'm happy to call `tomcat.getSerivce().addConnector(defaultConnector)`, 
but there needs to be some method for creating a connector with a 
default configuration. Otherwise I'm copying more and more large hunks 
of code from the Tomcat source code, which may break when things diverge 
in the future (not to mention cutting down on reusability).



…
You can also use a server.xml (and some other important config files like
web.xml) for your embedded now, you can look at Tomcat.main(...) (it is
used by the Tomcat container image example). If your configuration becomes
complex, it could be better than using Java to configure Tomcat.



I don't want server.xml or web.xml. This is /not/ complex; I merely want 
to serve static files in a directory. The irony is that I thought I was 
simplifying things my removing JSP etc. support; it turns out that this 
"simplification" complicated things greatly and required me to copy big 
hunks of Tomcat code. This could and should be improved, and I'm happy 
to help improve it.


Garret



Re: programmatically setting MIME mappings for static-only site

2019-04-19 Thread Konstantin Kolinko
пт, 19 апр. 2019 г. в 19:29, Garret Wilson :>
> I'm wanting to embed Tomcat to only serve static files (for the moment).
> That is, no JSP, etc. I also want to have the welcome files completely
> customizable.
>
> So instead of calling `tomcat.addWebapp()`, I go the completely
> programmable route and call `tomcat.addContext()`,
> `context.createWrapper()`, etc. This makes my bypass the
> `DefaultWebXmlListener`, which would have called
> `initWebappDefaults(Context ctx)` to set up the welcome files and such
> myself.
>
> But `initWebappDefaults()` also sets up the default MIME mappings. And
> `Tomcat.DEFAULT_MIME_MAPPINGS` is private.

Also note that the value is not synch'ed with the default list in
conf/web.xml. E.g  the following entries from the top of the default
list are missing


123
application/vnd.lotus-1-2-3


7z
application/x-7z-compressed


(and many others)

Some years ago the list in web.xml was synch'ed to the similar file in
Apache HTTPD, but the list used by embedded Tomcat was not updated.

Previous discussion:
http://markmail.org/message/gjkixk7wysopyztp

> So the situation seems to be that Tomcat forces me to choose between
> creating a full-fledged JSP server, or setting up all the MIME types
> with some list of my own. Maybe it would be good for me to have my own
> list eventually, but for now this seems like an artificial choice forced
> upon me.
>
> Part of the problem seems to be that the (ancient?) code has the MIME
> mappings as a string array!! Heaven knows we don't want to expose that.
> It should really be turned into a read-only map and then exposed so we
> can use it.

An array is a bad API, but generally it is faster to create an array.
All the time used to create a map goes to waste if it is only accessed
sequentially, like it is done here.

The only place where the values are used is

for (int i = 0; i < DEFAULT_MIME_MAPPINGS.length;) {
ctx.addMimeMapping(DEFAULT_MIME_MAPPINGS[i++],
DEFAULT_MIME_MAPPINGS[i++]);
}

There are some people who ask for options to make Tomcat to start up
faster (e.g. in a "serverless" environment when you start a process on
demand and pay for execution time). Not being careful here may
negatively affect the startup time. The current
'DEFAULT_MIME_MAPPINGS' field is a static one and is always created
when the class is loaded, regardless of whether it will be used or
not.


> Then of course I see the comment:
>
>  > TODO: would a properties resource be better ? Or just parsing
> /etc/mime.types ?
>
> To answer part of that question, we can't just parse `/etc/mime.types`
> because the embedded server might not even have an `/etc/mime.types`
> file. This should definitely be put into a properties resource, I would
> think.

For reference,
https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

> So I've probably answered my own question; this is an old TODO that
> needs to be done, I suppose?
>

Best regards,
Konstantin Kolinko

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread Rémy Maucherat
On Fri, Apr 19, 2019 at 11:14 PM Garret Wilson 
wrote:

> On 4/19/2019 3:24 PM, Rémy Maucherat wrote:
> > On Fri, Apr 19, 2019 at 7:46 PM Woonsan Ko  wrote:
> >
> >> I found this before from
> >>
> https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424
> >>
> >>  // Note: make sure that tomcat creates the default connector...
> >>  tomcat.getConnector();
> >>
> >> Worth trying...
>
>
> Yes, that fixed it, Woonsan! Thank you so much!
>
>
> > That looks correct, and it's easy to spot with the logging (the connector
> > logs that it's starting if it's there). I removed the magic creation of
> the
> > connector because it was causing far more hacks (where the magic
> connector
> > had to be removed after its startup). It seemed more normal to have to
> > explicitly create a connector.
> >
> > Rémy
>
> I don't know the history of this, but I have a couple of doubts on the
> face of it.
>
> First, the impression I get from reading _Apache Tomcat 7_ (Apress) is
> that I can create a server piecing together the components (Server,
> Service, Connector, Engine, Host, Context) if I want, but the whole
> point of the `Tomcat` class is to be a helper for doing all this
> automatically. So it seems a bit countertuitive that the `Tomcat` class
> is now making me do some of this wiring automatically. Why then would I
> use the `Tomcat` class? Why don't I just wire it all together from
> scratch? And why did we arbitrarily pick `Connector` for this "magic"
> creation? Why don't we have to call `Tomcat.getHost()` to make sure the
> host gets built, for instance?
>
> Secondly, calling a getter method in order to invoke some secret magic
> creation sauce behind the scenes reeks of a kludge. (Nothing personal;
> I'm just commenting on the design.) This is not "normal". It's not at
> all obvious that there is this magic step required before the thing will
> work. For example, when you see the following code, without some blatant
> comment it's easy to think that this is a no-op call that should be
> removed:
>
>  tomcat.setPort(8080);
>  tomcat.getConnector();  //"It doesn't look like this does anything;
> maybe it we should remove it… "
>  tomcat.setBaseDir("/foo/bar");
>
> If I'm forced to create a connector, I would at least like the option to
> do something normal and expected, such as:
>
> tomcat.getService().addConnector(tomcat.createDefaultConnector());
>
> I _could_ create a default connector manually, but I'd have to be
> copying more of the source code (along with "magic" identifiers such as
> "HTTP/1.1"). So returning to the first doubt above: why am I using the
> `Tomcat` class if it doesn't do the default things for me automatically?
>

Sorry, but the SpringBoot use case is more important [they want to be able
to create a Tomcat without a connector], so that's the way it is now.

tomcat.getService().addConnector(new Connector()); works very well, etc,
just look at what getConnector() does, it's very simple.

The Tomcat class is not supposed to help much in this area, but rather on
setting up the Tomcat instance right, creating contexts right, etc. You can
look at the code and you'll see what the more complex parts are. Adding a
connector isn't one of them.

You can also use a server.xml (and some other important config files like
web.xml) for your embedded now, you can look at Tomcat.main(...) (it is
used by the Tomcat container image example). If your configuration becomes
complex, it could be better than using Java to configure Tomcat.

Rémy


Re: programmatically setting MIME mappings for static-only site

2019-04-19 Thread Garret Wilson

On 4/19/2019 5:12 PM, Christopher Schultz wrote:

On April 19, 2019 4:20:24 PM UTC, Garret Wilson
 wrote:


So I've probably answered my own question; this is an old TODO
that needs to be done, I suppose?

Yep.

+1

This is a perfect "beginner" enhancement.



Yay! I'd love to take that on.

Would you like to assign a GitHub ticket to me, or should I create one? 
I don't remember the details of the source control process, but you guys 
have described it before when talking about configuration. I'll review 
the other threads to remember what the GitHub status is, but if it's OK 
to assign me a GitHub ticket, that would sure be helpful (instead of my 
keeping track of emails).


Garret


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread Garret Wilson

On 4/19/2019 3:24 PM, Rémy Maucherat wrote:

On Fri, Apr 19, 2019 at 7:46 PM Woonsan Ko  wrote:


I found this before from
https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424

 // Note: make sure that tomcat creates the default connector...
 tomcat.getConnector();

Worth trying...



Yes, that fixed it, Woonsan! Thank you so much!



That looks correct, and it's easy to spot with the logging (the connector
logs that it's starting if it's there). I removed the magic creation of the
connector because it was causing far more hacks (where the magic connector
had to be removed after its startup). It seemed more normal to have to
explicitly create a connector.

Rémy


I don't know the history of this, but I have a couple of doubts on the 
face of it.


First, the impression I get from reading _Apache Tomcat 7_ (Apress) is 
that I can create a server piecing together the components (Server, 
Service, Connector, Engine, Host, Context) if I want, but the whole 
point of the `Tomcat` class is to be a helper for doing all this 
automatically. So it seems a bit countertuitive that the `Tomcat` class 
is now making me do some of this wiring automatically. Why then would I 
use the `Tomcat` class? Why don't I just wire it all together from 
scratch? And why did we arbitrarily pick `Connector` for this "magic" 
creation? Why don't we have to call `Tomcat.getHost()` to make sure the 
host gets built, for instance?


Secondly, calling a getter method in order to invoke some secret magic 
creation sauce behind the scenes reeks of a kludge. (Nothing personal; 
I'm just commenting on the design.) This is not "normal". It's not at 
all obvious that there is this magic step required before the thing will 
work. For example, when you see the following code, without some blatant 
comment it's easy to think that this is a no-op call that should be removed:


    tomcat.setPort(8080);
    tomcat.getConnector();  //"It doesn't look like this does anything; 
maybe it we should remove it… "

    tomcat.setBaseDir("/foo/bar");

If I'm forced to create a connector, I would at least like the option to 
do something normal and expected, such as:


tomcat.getService().addConnector(tomcat.createDefaultConnector());

I _could_ create a default connector manually, but I'd have to be 
copying more of the source code (along with "magic" identifiers such as 
"HTTP/1.1"). So returning to the first doubt above: why am I using the 
`Tomcat` class if it doesn't do the default things for me automatically?


Garret


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: programmatically setting MIME mappings for static-only site

2019-04-19 Thread Christopher Schultz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA256

Garret,

On 4/19/19 15:12, Mark Thomas wrote:
> On April 19, 2019 4:20:24 PM UTC, Garret Wilson
>  wrote:
>> I'm wanting to embed Tomcat to only serve static files (for the 
>> moment). That is, no JSP, etc. I also want to have the welcome
>> files completely customizable.
>> 
>> So instead of calling `tomcat.addWebapp()`, I go the completely 
>> programmable route and call `tomcat.addContext()`, 
>> `context.createWrapper()`, etc. This makes my bypass the 
>> `DefaultWebXmlListener`, which would have called 
>> `initWebappDefaults(Context ctx)` to set up the welcome files and
>> such myself.
>> 
>> But `initWebappDefaults()` also sets up the default MIME
>> mappings. And `Tomcat.DEFAULT_MIME_MAPPINGS` is private.
>> 
>> So the situation seems to be that Tomcat forces me to choose
>> between creating a full-fledged JSP server, or setting up all the
>> MIME types with some list of my own. Maybe it would be good for
>> me to have my own list eventually, but for now this seems like an
>> artificial choice forced upon me.
>> 
>> Part of the problem seems to be that the (ancient?) code has the
>> MIME mappings as a string array!! Heaven knows we don't want to
>> expose that.
>> 
>> It should really be turned into a read-only map and then exposed
>> so we can use it.
>> 
>> Then of course I see the comment:
>> 
>>> TODO: would a properties resource be better ? Or just parsing
>> /etc/mime.types ?
>> 
>> To answer part of that question, we can't just parse
>> `/etc/mime.types` because the embedded server might not even have
>> an `/etc/mime.types` file. This should definitely be put into a
>> properties resource, I would
>> 
>> think.
>> 
>> So I've probably answered my own question; this is an old TODO
>> that needs to be done, I suppose?
> 
> Yep.

+1

This is a perfect "beginner" enhancement.

- -chris
-BEGIN PGP SIGNATURE-
Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/

iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAly6K5wACgkQHPApP6U8
pFhxyRAAw2AkPD1gtbc9/0poWuZrJMBLeDY41G13V+3VGwAu+YsBTpUmyh24lv/6
YOjGiNLYvqYLoKMx//obH/dwK38OwzZVJcS6z91ip9E5Unu2s++X3tNlOh98+C69
xCIc09Q/9B4jCIwA2NrgQY5KBqRk6wPm+xcG6EvCBJ8jijDkaw9qs9TkvUI26sIs
6JR24wR6YipTG6r4DTpHl8Z0ltbgEA14rws9TvQUWvODizvFVEZroSVtIsF6NYBB
wiiA+JPuvcWHyouxoQCLtrTELkcAX2F7RskY+vaH8Yvr4lUiX+P6mPHuLh9X/CLF
yoaks+zc/wPiaGiECh08zw6d5HFvwvM7cseLWhDO+PCVj2HsoIxxLniaBRWmYF5t
QPdRFIc83Gz5Aq6TUNyxjIqNXZnN5Fz1pvxWitSK671APKLzpqI27mf90GF9+gqL
VVbROKlfpzacE98pv7UHeKT9v0rEo1Ramw29BwpshtDvhVgEIrcMID0/ExDdct4W
bd4NUY1PEW3ykB0HVKCDEPPQVecbuNEYFe7tgtxO8YZqq1adyZmGCQffaQEpa7z0
mWKBa8JAFDpDS2sQMDlLP2Lddu1z2wW8izdWt5ArFCSGZQpVJQh7XQY41Fy7bB0y
5lH7htGK0S2CrvX7UT4JpmNbvtQ1b4K/hb1wKI3O/ljKnUKXDNs=
=B/mc
-END PGP SIGNATURE-

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread John Dale
Tomcat doesn't seem to timeout one its own unless my DBCP is being
abused in the code.

I'm thinking firewall .. also, double-check your port configuration(s)
in server.xml (or context.xml if that's the route you're going).

On 4/19/19, Garret Wilson  wrote:
> Embedding Tomcat 9 (with OpenJDK 11 on Windows 10) I want to serve
> static files from `/foo/bar`. From scouring the web (primarily
> https://stackoverflow.com/a/15235711/421049 ), the documentation, and
> some books (primarily _Apache Tomcat 7_), I have this:
>
>  Tomcat tomcat = new Tomcat();
>  tomcat.setPort(8080);
>  tomcat.setBaseDir("/foo");
>  Context ctx = tomcat.addContext("", "/foo/bar");
>  final Wrapper defaultServlet = ctx.createWrapper();
>  defaultServlet.setName("default");
> defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
>  defaultServlet.addInitParameter("debug", "1");
>  defaultServlet.addInitParameter("listings", "false");
>  defaultServlet.setLoadOnStartup(1);
>  ctx.addChild(defaultServlet);
>  ctx.addServletMappingDecoded("/", "default");
>  ctx.addWelcomeFile("index.html");
>  tomcat.start();
>  tomcat.getServer().await();
>
> Everything looks like it starts up:
>
>  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardService
> startInternal
>  INFO: Starting service [Tomcat]
>  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardEngine
> startInternal
>  INFO: Starting Servlet engine: [Apache Tomcat/9.0.19]
>  Apr 19, 2019 2:18:10 PM
> org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
>  WARNING: Creation of SecureRandom instance for session ID
> generation using [SHA1PRNG] took [281] milliseconds.
>  Apr 19, 2019 2:18:10 PM org.apache.catalina.core.ApplicationContext
> log
>  INFO: default: DefaultServlet.init:  input buffer size=2048, output
> buffer size=2048
>
> But connections to http://localhost:8080/ time out. (I'm pretty sure but
> not positive that I don't have anything blocking this in the firewall.)
>
> Is there some simple thing I'm missing to connect things together?
>
> Thanks,
>
> Garret
>
> P.S. The documentation on the web for the details of this is
> surprisingly sparse.
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: 404 response to URLs with trailing decimal

2019-04-19 Thread Mark Thomas
On April 19, 2019 5:32:11 PM UTC, Mark Reyes  wrote:
>Hello,
>
>I find that Tomcat 8 will not serve up static content with a trailing
>decimal in
>the URL.  A response code of 404 is served up, not the static content.
>
>My configuration is a symbolic link in the webapps/ directory. e.g.
>
> 
>
>   allowLinking="true"
>
> 
>
>A sample request URL that fails is:
> http://localhost:8080/externalData/trailingDot.
>
>I have tried to URL encode the period in the request, but the problem
>still
>exists.
>Is this a bug in Tomcat?  If so, should I send in a bug request?
>Below are the instance specifics.
>
>Thank you.
>mark.re...@ucop.edu
>
>Server version: Apache Tomcat/8.0.24
>Server built:   Jul 1 2015 20:19:55 UTC
>Server number:  8.0.24.0
>OS Name:Linux
>OS Version: 4.14.104-78.84.amzn1.x86_64
>Architecture:   amd64
>JVM Version:1.8.0_201-b09
>JVM Vendor: Oracle Corporation
>
>-
>To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>For additional commands, e-mail: users-h...@tomcat.apache.org

Assuming the file /externalData/trailingDot. exists then yes, that looks like a 
bug.

Mark

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: programmatically setting MIME mappings for static-only site

2019-04-19 Thread Mark Thomas
On April 19, 2019 4:20:24 PM UTC, Garret Wilson  wrote:
>I'm wanting to embed Tomcat to only serve static files (for the
>moment). 
>That is, no JSP, etc. I also want to have the welcome files completely 
>customizable.
>
>So instead of calling `tomcat.addWebapp()`, I go the completely 
>programmable route and call `tomcat.addContext()`, 
>`context.createWrapper()`, etc. This makes my bypass the 
>`DefaultWebXmlListener`, which would have called 
>`initWebappDefaults(Context ctx)` to set up the welcome files and such 
>myself.
>
>But `initWebappDefaults()` also sets up the default MIME mappings. And 
>`Tomcat.DEFAULT_MIME_MAPPINGS` is private.
>
>So the situation seems to be that Tomcat forces me to choose between 
>creating a full-fledged JSP server, or setting up all the MIME types 
>with some list of my own. Maybe it would be good for me to have my own 
>list eventually, but for now this seems like an artificial choice
>forced 
>upon me.
>
>Part of the problem seems to be that the (ancient?) code has the MIME 
>mappings as a string array!! Heaven knows we don't want to expose that.
>
>It should really be turned into a read-only map and then exposed so we 
>can use it.
>
>Then of course I see the comment:
>
> > TODO: would a properties resource be better ? Or just parsing 
>/etc/mime.types ?
>
>To answer part of that question, we can't just parse `/etc/mime.types` 
>because the embedded server might not even have an `/etc/mime.types` 
>file. This should definitely be put into a properties resource, I would
>
>think.
>
>So I've probably answered my own question; this is an old TODO that 
>needs to be done, I suppose?

Yep.

Mark


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread Rémy Maucherat
On Fri, Apr 19, 2019 at 7:46 PM Woonsan Ko  wrote:

> On Fri, Apr 19, 2019 at 1:24 PM Garret Wilson 
> wrote:
> >
> > Embedding Tomcat 9 (with OpenJDK 11 on Windows 10) I want to serve
> > static files from `/foo/bar`. From scouring the web (primarily
> > https://stackoverflow.com/a/15235711/421049 ), the documentation, and
> > some books (primarily _Apache Tomcat 7_), I have this:
> >
> >  Tomcat tomcat = new Tomcat();
> >  tomcat.setPort(8080);
> >  tomcat.setBaseDir("/foo");
>
> I found this before from
>
> https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424
>
> // Note: make sure that tomcat creates the default connector...
> tomcat.getConnector();
>
> Worth trying...
>

That looks correct, and it's easy to spot with the logging (the connector
logs that it's starting if it's there). I removed the magic creation of the
connector because it was causing far more hacks (where the magic connector
had to be removed after its startup). It seemed more normal to have to
explicitly create a connector.

Rémy


>
> Woonsan
>
> >  Context ctx = tomcat.addContext("", "/foo/bar");
> >  final Wrapper defaultServlet = ctx.createWrapper();
> >  defaultServlet.setName("default");
> >
> defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
> >  defaultServlet.addInitParameter("debug", "1");
> >  defaultServlet.addInitParameter("listings", "false");
> >  defaultServlet.setLoadOnStartup(1);
> >  ctx.addChild(defaultServlet);
> >  ctx.addServletMappingDecoded("/", "default");
> >  ctx.addWelcomeFile("index.html");
> >  tomcat.start();
> >  tomcat.getServer().await();
> >
> > Everything looks like it starts up:
> >
> >  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardService
> > startInternal
> >  INFO: Starting service [Tomcat]
> >  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardEngine
> > startInternal
> >  INFO: Starting Servlet engine: [Apache Tomcat/9.0.19]
> >  Apr 19, 2019 2:18:10 PM
> > org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
> >  WARNING: Creation of SecureRandom instance for session ID
> > generation using [SHA1PRNG] took [281] milliseconds.
> >  Apr 19, 2019 2:18:10 PM org.apache.catalina.core.ApplicationContext
> log
> >  INFO: default: DefaultServlet.init:  input buffer size=2048, output
> > buffer size=2048
> >
> > But connections to http://localhost:8080/ time out. (I'm pretty sure but
> > not positive that I don't have anything blocking this in the firewall.)
> >
> > Is there some simple thing I'm missing to connect things together?
> >
> > Thanks,
> >
> > Garret
> >
> > P.S. The documentation on the web for the details of this is
> > surprisingly sparse.
> >
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> >
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>
>


Re: unable to serve static files with embedded Tomcat

2019-04-19 Thread Woonsan Ko
On Fri, Apr 19, 2019 at 1:24 PM Garret Wilson  wrote:
>
> Embedding Tomcat 9 (with OpenJDK 11 on Windows 10) I want to serve
> static files from `/foo/bar`. From scouring the web (primarily
> https://stackoverflow.com/a/15235711/421049 ), the documentation, and
> some books (primarily _Apache Tomcat 7_), I have this:
>
>  Tomcat tomcat = new Tomcat();
>  tomcat.setPort(8080);
>  tomcat.setBaseDir("/foo");

I found this before from
https://stackoverflow.com/questions/48998387/code-works-with-embedded-apache-tomcat-8-but-not-with-9-whats-changed/49011424

// Note: make sure that tomcat creates the default connector...
tomcat.getConnector();

Worth trying...

Woonsan

>  Context ctx = tomcat.addContext("", "/foo/bar");
>  final Wrapper defaultServlet = ctx.createWrapper();
>  defaultServlet.setName("default");
> defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
>  defaultServlet.addInitParameter("debug", "1");
>  defaultServlet.addInitParameter("listings", "false");
>  defaultServlet.setLoadOnStartup(1);
>  ctx.addChild(defaultServlet);
>  ctx.addServletMappingDecoded("/", "default");
>  ctx.addWelcomeFile("index.html");
>  tomcat.start();
>  tomcat.getServer().await();
>
> Everything looks like it starts up:
>
>  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardService
> startInternal
>  INFO: Starting service [Tomcat]
>  Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardEngine
> startInternal
>  INFO: Starting Servlet engine: [Apache Tomcat/9.0.19]
>  Apr 19, 2019 2:18:10 PM
> org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
>  WARNING: Creation of SecureRandom instance for session ID
> generation using [SHA1PRNG] took [281] milliseconds.
>  Apr 19, 2019 2:18:10 PM org.apache.catalina.core.ApplicationContext log
>  INFO: default: DefaultServlet.init:  input buffer size=2048, output
> buffer size=2048
>
> But connections to http://localhost:8080/ time out. (I'm pretty sure but
> not positive that I don't have anything blocking this in the firewall.)
>
> Is there some simple thing I'm missing to connect things together?
>
> Thanks,
>
> Garret
>
> P.S. The documentation on the web for the details of this is
> surprisingly sparse.
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



404 response to URLs with trailing decimal

2019-04-19 Thread Mark Reyes
Hello,

I find that Tomcat 8 will not serve up static content with a trailing decimal in
the URL.  A response code of 404 is served up, not the static content.

My configuration is a symbolic link in the webapps/ directory. e.g.

 

   allowLinking="true"

 

A sample request URL that fails is:
 http://localhost:8080/externalData/trailingDot.

I have tried to URL encode the period in the request, but the problem still
exists.
Is this a bug in Tomcat?  If so, should I send in a bug request?
Below are the instance specifics.

Thank you.
mark.re...@ucop.edu

Server version: Apache Tomcat/8.0.24
Server built:   Jul 1 2015 20:19:55 UTC
Server number:  8.0.24.0
OS Name:Linux
OS Version: 4.14.104-78.84.amzn1.x86_64
Architecture:   amd64
JVM Version:1.8.0_201-b09
JVM Vendor: Oracle Corporation

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



unable to serve static files with embedded Tomcat

2019-04-19 Thread Garret Wilson
Embedding Tomcat 9 (with OpenJDK 11 on Windows 10) I want to serve 
static files from `/foo/bar`. From scouring the web (primarily 
https://stackoverflow.com/a/15235711/421049 ), the documentation, and 
some books (primarily _Apache Tomcat 7_), I have this:


    Tomcat tomcat = new Tomcat();
    tomcat.setPort(8080);
    tomcat.setBaseDir("/foo");
    Context ctx = tomcat.addContext("", "/foo/bar");
    final Wrapper defaultServlet = ctx.createWrapper();
    defaultServlet.setName("default");
defaultServlet.setServletClass("org.apache.catalina.servlets.DefaultServlet");
    defaultServlet.addInitParameter("debug", "1");
    defaultServlet.addInitParameter("listings", "false");
    defaultServlet.setLoadOnStartup(1);
    ctx.addChild(defaultServlet);
    ctx.addServletMappingDecoded("/", "default");
    ctx.addWelcomeFile("index.html");
    tomcat.start();
    tomcat.getServer().await();

Everything looks like it starts up:

    Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardService 
startInternal

    INFO: Starting service [Tomcat]
    Apr 19, 2019 2:18:09 PM org.apache.catalina.core.StandardEngine 
startInternal

    INFO: Starting Servlet engine: [Apache Tomcat/9.0.19]
    Apr 19, 2019 2:18:10 PM 
org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
    WARNING: Creation of SecureRandom instance for session ID 
generation using [SHA1PRNG] took [281] milliseconds.

    Apr 19, 2019 2:18:10 PM org.apache.catalina.core.ApplicationContext log
    INFO: default: DefaultServlet.init:  input buffer size=2048, output 
buffer size=2048


But connections to http://localhost:8080/ time out. (I'm pretty sure but 
not positive that I don't have anything blocking this in the firewall.)


Is there some simple thing I'm missing to connect things together?

Thanks,

Garret

P.S. The documentation on the web for the details of this is 
surprisingly sparse.



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



programmatically setting MIME mappings for static-only site

2019-04-19 Thread Garret Wilson
I'm wanting to embed Tomcat to only serve static files (for the moment). 
That is, no JSP, etc. I also want to have the welcome files completely 
customizable.


So instead of calling `tomcat.addWebapp()`, I go the completely 
programmable route and call `tomcat.addContext()`, 
`context.createWrapper()`, etc. This makes my bypass the 
`DefaultWebXmlListener`, which would have called 
`initWebappDefaults(Context ctx)` to set up the welcome files and such 
myself.


But `initWebappDefaults()` also sets up the default MIME mappings. And 
`Tomcat.DEFAULT_MIME_MAPPINGS` is private.


So the situation seems to be that Tomcat forces me to choose between 
creating a full-fledged JSP server, or setting up all the MIME types 
with some list of my own. Maybe it would be good for me to have my own 
list eventually, but for now this seems like an artificial choice forced 
upon me.


Part of the problem seems to be that the (ancient?) code has the MIME 
mappings as a string array!! Heaven knows we don't want to expose that. 
It should really be turned into a read-only map and then exposed so we 
can use it.


Then of course I see the comment:

> TODO: would a properties resource be better ? Or just parsing 
/etc/mime.types ?


To answer part of that question, we can't just parse `/etc/mime.types` 
because the embedded server might not even have an `/etc/mime.types` 
file. This should definitely be put into a properties resource, I would 
think.


So I've probably answered my own question; this is an old TODO that 
needs to be done, I suppose?


Garret


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: OS

2019-04-19 Thread Mark Thomas
On April 18, 2019 6:54:37 PM UTC, Christopher Schultz 
 wrote:
>-BEGIN PGP SIGNED MESSAGE-
>Hash: SHA256
>
>
>
>On 4/18/19 01:06, liname...@outlook.com wrote:
>> Hello, I am doing an investigation. Does Windows Server 2019
>> support the following products:
>> 
>> Apache Tomcat   6.0.35 Tomcat Connectors (mod_jk)   1.2.35-m1.0
>> 
>> Is the other version supported? Can you tell me, thank you very
>> much.
>
>Tomcat requires a JVM of a certain version in order to run. Tomcat 6
>requires Java 5 or later, but is no longer supported by this
>community. Tomcat 6.0.35 is, in fact, *dangerously* out of date.

As is mod_jk 1.2.35. You should use the latest available mod_jk version.

Mark


>
>You should look at running Tomcat 7.0, 8.5, or 9.0 at this point.
>
>- -chris
>-BEGIN PGP SIGNATURE-
>Comment: Using GnuPG with Thunderbird - https://www.enigmail.net/
>
>iQIzBAEBCAAdFiEEMmKgYcQvxMe7tcJcHPApP6U8pFgFAly4x+0ACgkQHPApP6U8
>pFjoNhAAkf6jkOOgqm1XwCQM0ioIa9Ab9jji45S2fPX0CFs5pMZ/MRtbT0XBrzQ1
>lFbzF1wZBWkBCpHCL/KWGnpEo3TVYHRIz4e6wTU4zVsChl9D10bcQEpV2RMnL6D3
>mUP2OY9vwrQszaNEtbWsVjnm6XrqyGolGqpl0qBqoasqgn1b/jSX/WITnnmXatK4
>JM/3ouNamnbFzZkfaSQPP8dR3GoIz7PwzrfMbX1aGEsUFPe5bYDtjCuFfLlLaYCj
>HYkICLnZewtnGL5/FuxjWYFqLep/6k9P4lbBGvnAQwLqvGtbdpqfm44iuAUuBvWB
>R+lbKbvpORwxvRMc9ncqrm1fveWPLR5Wqt6bJH/eGGpPyurr95fiG6w8BtgFUMeL
>Rad8p+CZjPxDDJ0ZBSy2//VQchpVtdSolaBcEpb3+F2YJB/W0hBSKS2qSS/Pebz9
>2nnK1CRhSJ8pzqAVnPANXjAAWj7LqVt2zs6eA+G4ku2ISV3Gxfgvm//V67YOFjt6
>HcFOX9+wZlHiMcMtn0eCxIKT8CWTotftBEQpX//RwOlohZML9uUGfhP7/Y/R8raM
>BBzsqqWpUPZk8oujMxTHocibUF0QOh9427+8JjKRRuUgOmIoUo1iUcSu2UoEY8S1
>d4C6ba8ScfN8m+cF9kohLVCSjsrZsbDDCkMEZnkoiDGByDR4n6A=
>=RBTT
>-END PGP SIGNATURE-
>
>-
>To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>For additional commands, e-mail: users-h...@tomcat.apache.org


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org