Re: [jetty-users] Run multiple instances of the same WAR servlet and pass it a config value

2023-10-04 Thread Alexander Farber via jetty-users
Apologies, the getServletConfig().getContextPath() in the init() of my
servlet works well, that probably had been a problem in my VS Code.

Still I wonder, if I would set a "property" with a "name" and "value" as
described in the "Jetty XML Syntax" section
https://eclipse.dev/jetty/documentation/jetty-10/operations-guide/index.html#og-xml
- how could I retrieve the value in the servlet?

Best regards
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Run multiple instances of the same WAR servlet and pass it a config value

2023-10-04 Thread Alexander Farber via jetty-users
I try to use the following but the method is not available:

@Override
public void init() throws ServletException {
super.init();

mLanguage = getServletConfig().getContextPath();
   }
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


[jetty-users] Run multiple instances of the same WAR servlet and pass it a config value

2023-10-04 Thread Alexander Farber via jetty-users
Good morning,

I have an "overengineered" setup with Jetty 10.0.16 and haproxy 2.7.8,
where I currently run 6 different Jetty instances to serve the same servlet
-

I have programmed that WAR servlet using Maven and it supports 6 languages:

src/main/resources/strings.properties
src/main/resources/strings_de.properties
src/main/resources/strings_fr.properties
src/main/resources/strings_nl.properties
src/main/resources/strings_pl.properties
src/main/resources/strings_ru.properties

and then in the configure method I fetch the language value from the
"COUNTRY" env var:

@Override
public void configure(JettyWebSocketServletFactory factory) {
mLanguage = System.getenv("COUNTRY");
mBundle = ResourceBundle.getBundle("strings",
LOCALES.get(mLanguage));

factory.setIdleTimeout(Duration.ofSeconds(IDLE_TIMEOUT_SECONDS));
factory.setMaxBinaryMessageSize(0);
factory.setMaxTextMessageSize(64 * 1024);
factory.setCreator(new WordsCreator(this,
mBundle.getString(STR_DATABASE_URL)));
}

Then I have the following 6 scripts on my Rocky Linux 8.8 to start the
Jetty instances

/etc/systemd/system/jetty-de.service
/etc/systemd/system/jetty-en.service
/etc/systemd/system/jetty-fr.service
/etc/systemd/system/jetty-nl.service
/etc/systemd/system/jetty-pl.service
/etc/systemd/system/jetty-ru.service

And the only differences the scripts have is the port and the "COUNTRY" env
var:

[Unit]
Description=Jetty
After=network-online.target

[Service]
Environment=COUNTRY=de

Type=simple
User=jetty
Group=jetty
ExecStart=/usr/bin/java -Djdbc.drivers=org.postgresql.Driver -jar
/usr/share/java/jetty-home-10.0.16/start.jar
jetty.home=/usr/share/java/jetty-home-10.0.16
jetty.base=/var/www/jetty-base-de jetty.http.host=127.0.0.1
jetty.http.port=8081
SuccessExitStatus=143
Restart=always
RestartSec=180
PrivateTmp=true

[Install]
WantedBy=multi-user.target

In the /etc/haproxy/haproxy.cfg I look at the request path and forward the
request to one of the ports:

backend jetty_de
server domain 127.0.0.1:8081 send-proxy
backend jetty_en
server domain 127.0.0.1:8082 send-proxy
backend jetty_fr
server domain 127.0.0.1:8083 send-proxy
backend jetty_nl
server domain 127.0.0.1:8084 send-proxy
backend jetty_pl
server domain 127.0.0.1:8085 send-proxy
backend jetty_ru
server domain 127.0.0.1:8080 send-proxy

frontend wordsbyfarber_com
bind 95.216.113.90:80
bind 95.216.113.90:443 ssl crt
/etc/pki/tls/certs/wordsbyfarber.com.pem no-sslv3

redirect scheme https if !{ ssl_fc }

use_backend jetty_de if { path_beg /de }
use_backend jetty_en if { path_beg /en }
use_backend jetty_fr if { path_beg /fr }
use_backend jetty_nl if { path_beg /nl }
use_backend jetty_pl if { path_beg /pl }
use_backend jetty_ru if { path_beg /ru }

default_backend jetty_en

Finaly my config XML files look like this to "bind" the servlet to a
certain context path:

# cat /var/www/jetty-base-de/webapps/de.xml

http://www.eclipse.org/jetty/configure_9_0.dtd;>


/de
/var/www/words-5.0.war



Thank you for reading my mail, it is a bit longer, because I am trying to
provide enough details.

My question is, if it is possible to handle my task with a single Jetty
instance?

Could I set the env var in the  /var/www/jetty-base-de/webapps/de.xml file?

Or maybe alternatively access the value of "contextPath" from the
configure() method?

Thank you for any suggestions
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
Thank you, Joakim - your second suggestion has worked well for me:

 webapps/root.xml

http://www.eclipse.org/jetty/configure_9_0.dtd;>

/


index.html




/var/www/html/wordsbyfarber.com
true




js
text/javascript;charset=utf-8




Now I get the following response headers and the file is displayed with
correct international characters in the Microsoft Edge browser:

HTTP/1.1 200 OK
last-modified: Tue, 03 Oct 2023 09:52:40 GMT
content-type: text/javascript;charset=utf-8
accept-ranges: bytes
vary: Accept-Encoding
content-encoding: gzip
server: Jetty(10.0.16)
connection: close

Best regards
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


Re: [jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
Thank you Joakim for the extensive answer, however -

On Tue, Oct 3, 2023 at 2:23 PM Joakim Erdfelt via jetty-users <
jetty-users@eclipse.org> wrote:

> Per the javascript RFC, the `text/javascript` mime-type has an optional
> `charset` parameter.
> The behavior is documented at
> https://datatracker.ietf.org/doc/html/rfc9239#name-charset-parameter
>
> Essentially, if the charset is unspecified, then the encoding is UTF-8.
>
> > the encoding is unfortunately not set to utf8 (like it is for the served
> json files).
>
> For JSON, the charset parameter is not used.
> Per spec, JSON is always UTF-8.
> See: https://www.rfc-editor.org/rfc/rfc8259#section-8.1
>
> In Jetty, the json encoding is specified as an assumed UTF-8.
> See:
> https://github.com/eclipse/jetty.project/blob/jetty-10.0.16/jetty-http/src/main/resources/org/eclipse/jetty/http/encoding.properties
> This means the `charset` parameter is not produced when generating the
> `Content-Type` header, and is ignored when parsing the `Content-Type`
> header.
>
>  > Is there a way to enforce that without compiling a custom version of
> Jetty?
>
> You can customize the in-place `MimeTypes` for a context.
>
> servletContextHandler.getMimeTypes().addMimeMapping("txt",
> "text/javascript;charset=UTF-8");
> or
> webappContext.getMimeTypes().addMimeMapping("txt",
> "text/javascript;charset=UTF-8");
>
> or, If you have a WEB-INF/web.xml in your webapp, you can add a
> `` entry.
>
>   
> js
> text/javascript;charset=UTF-8
>   
>

I have problems that my UTF8 file is displayed wrongly in the browser -

  https://wordsbyfarber.com/Consts-ru.js

The browser displays pairs of junk characters instead of cyrillic letters
and from my (limited) experience having ";charset=utf8" in the header would
help it.

So I have followed your suggestion and have extended the
src/main/webapp/WEB-INF/web.xml with:


http://xmlns.jcp.org/xml/ns/javaee;
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
 xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd;>

WordsServlet
de.afarber.WordsServlet


WordsServlet
/


js
text/javascript;charset=UTF-8



Unfortunately the URL still returns the headers without "UTF-8" in there:

HTTP/1.1 200 OK
last-modified: Tue, 03 Oct 2023 09:52:40 GMT
content-type: text/javascript
accept-ranges: bytes
vary: Accept-Encoding
content-encoding: gzip
server: Jetty(10.0.16)
connection: close

Best regards
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users


[jetty-users] Setting text/javascript encoding to utf8 with Jetty 10.0.16

2023-10-03 Thread Alexander Farber via jetty-users
Hello,

I am using Jetty 10.0.16 and when it serves static JavaScript files (I have
Consts-en.js, Consts-de.js, Consts-fr.js, ...) the encoding is
unfortunately not set to utf8 (like it is for the served json files).

Is there a way to enforce that without compiling a custom version of Jetty?

I have searched on the internet and also here:

# find /usr/share/java/jetty-home-10.0.16 -type f -iname \*.prop\*
/usr/share/java/jetty-home-10.0.16/modules/deprecated.properties
/usr/share/java/jetty-home-10.0.16/modules/demo.d/demo-realm.properties
/usr/share/java/jetty-home-10.0.16/modules/demo.d/demo-login.properties
/usr/share/java/jetty-home-10.0.16/modules/sessions/infinispan/remote/resources/hotrod-client.properties
/usr/share/java/jetty-home-10.0.16/modules/jolokia/jolokia-realm.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jul/resources/java-util-logging-bridge.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jul/resources/java-util-logging.properties
/usr/share/java/jetty-home-10.0.16/modules/logging/jetty/resources/jetty-logging.properties
/usr/share/java/jetty-home-10.0.16/etc/jdbcRealm.properties

Thank you for any hints
Alex
___
jetty-users mailing list
jetty-users@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/jetty-users