Wildcard Subdomain In SpringBoot For my Mac - java

I am creating a web application in which there will be multiple subdomain. Each client will be having its own subdomain. Each subdomain will have individual database. For example I am having a client abc, then it will have subdomain as abc.mydomain.com and its database name will be abc.
Now this application is created in spring boot. Here I want to configure wildcard subdomain. So how can I configure it in spring boot. For this, I had tried few solution.
I had changed my /etc/hosts and added an domain name entry in it as below
127.0.0.1 www.mydomain.com
But now I want subdomain in this. How can I do it.
I had seen somewhere that I need to configure server.xml of tomcat. In server.xml I had added below line.
<Host name="www.mydomain.com" appBase="webapps" unpackWARs="true"
autoDeploy="true">
<Alias>*.mydomain.com</Alias>
</Host>
Can you please help me with this. Also let me know incase you need more details in this.

After been working for multiple days I came to a solution for this question. As I was working for wildcard subdomain in localhost. Thus for this I need to use an external software called dnsmasq, I had executed following commands to install dnsmasq in my laptop.
brew install dnsmasq
After installing dnsmasq in my laptop I need to to configure it. For this I have to update the dnsmasq. For my case it is located at
/usr/local/etc/dnsmasq.conf
In this file I have to add few lines to configure wildcard subdomain. Lines are as below.
# Route all *.mydomain.com addresses to localhost
address=/mydomain.com/127.0.0.1
# Don't read /etc/resolv.conf or any other configuration files.
no-resolv
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
Next I need to restart my dnsmasq service. Command for it is as below.
sudo brew services start dnsmasq
Finally you need to create a file mydomain.com at /etc/resolver (Create folder resolver if not exists). Add below line in mydomain.com file.
nameserver 127.0.0.1
This is the complete configuration for setting up swildcard subdomain in your mac os.
For reference you can follow this link

Related

How to map an app from Tomcat8 to Apache in JBoss Web Server?

I install JBoss 3.0.1 and it functions well both Apache on port 80 & Tomcat8 on port 8080. I deploy a sample war file from Tomcat and can view it at http://localhost:8080/sample/.
So is it possible to map it on Apache, then we can access it at http://localhost/sample/? If yes, can you please help me how to do that? Any suggestion would be appreciated.
Update: For POC purpose, the OS is Windows 7
You can do it by means of AJP. You don't specify what OS are you using, but I will assume it is GNU/Linux, although instructions for MS Windows will be similar.
The procedure is the following:
Install Apache module for AJP, usually it is called something like libapache2-mod-jk. (In debian/ubuntu you can run sudo apt-get install libapache2-mod-jk).
Then you will have a new module calledjk or similar. You have to enable it (In debian/ubuntu you can run sudo a2enmod jk).
Default configuration will serve mostly, open it a see where does JkWorkersFile point. This file is needed to configure the workers that manage communication with tomcat apps.
Create workers file (if it does not exists). A workers file is more or less as following.
Sample workers file:
ps=/
worker.list=worker1,worker2,...
# worker1 definition
worker.worker1.port=8009
worker.worker1.host=192.168.1.23
worker.worker1.type=ajp13
# worker2 definition
....
Every worker can point to different tomcat server. Port must be the same that configured into $CATALINA_HOME/conf/server.xml. In this file there is a connector for AJP protocol:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Every worker has to point to this port.
Finally, you can configure virtual host, locations, etc. into Apache with JkMount workerName to indicate Apache that this url has to be forwarded to the proper worker.
There are plenty of samples an documentation. Here you are with Tomcat official docs: https://tomcat.apache.org/connectors-doc/webserver_howto/apache.html
Hope it helps!
Edit
If you are using MS Windows, you can download mod_jk from this url https://tomcat.apache.org/download-connectors.cgi
Install it and configure as suggested. Due to you want to map this url http://localhost/sample to tomcat app in http://localhost:8080/sample Your configuration must be the following:
workers file (Review port with server.xml tomcat conf file):
worker.list=worker1
# worker1 definition
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
Apache Location directive (Review order, deny and allow to suit your needs):
<Location /sample/>
JkMount worker1
Order deny,allow
Deny from all
Allow from localhost
</Location>

JavaEE app with EJB - glassfish configurations inside project

I have a JavaEE application with EJB, deployed in glassfish. If i add the connection pools, jndi resources, jms resources to the glassfish, then the project is working fine. But is there anyway i can do these things without adding these configurations from the glassfish admin console.
The purpose for this is, when i need to send my project to another person, he/she will also have to add these configs to glassfish. I need to prevent it
Best way to achieve this are probably command line scripts (bat, sh). There you can administrate GlassFish using the asadmin command. Here is a list of all asadmin subcommands: http://docs.oracle.com/cd/E18930_01/html/821-2416/gcode.html
Example to add a JNDI resource:
asadmin create-jndi-resource --user admin --passwordfile passwords.txt
--host pigeon --port 4001 --jndilookupname sample_jndi --restype queue
--factoryclass sampleClass --description "this is a sample jndi
resource" sample_jndi_resource
(Example source: http://docs.oracle.com/cd/E19879-01/820-4332/6nfq988q6/index.html)

How to check if JMX agent is working in Tomcat?

I have a Tomcat 8 instance. I'm trying to connect to it from JColsole. In order to do so I have added to the setenv.bat the following line:
CATALINA_OPTS=%CATALINA_OPTS% -Dcom.sun.management.jmxremote.password.file=D:\Utils\Apache\Tomcat\conf\remote.users -Dcom.sun.management.jmxremote.access.file=D:\Utils\Apache\Tomcat\conf\remote.acl -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=7777 -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=localhost
and in those two files -- remote.users and remote.acl i have defined user test with password test and the role readwrite.
However I cannot connect via JConsole (I tried using url localhost:7777 and service:jmx:rmi://localhost:7777).
Further investigation showed, that I cannot even telnet to 7777.
What am I doing wrong?
As it happens, when Tomcat is running as a service on Windows, I don't need setenv.bat, I need to use tomcat8w.exe -- GUI toll for adding options

Tomcat load balancer solutions

I'm looking for a good load balancer to use with Tomcat. Our application doesn't store anything in the session context so it isn't important to redirect to same server for the same user. I'd simply like something that can queue requests round-robin style or based on each server's inidividual load. I'd also like to be able to add application servers to those available to handle requests without having to restart the load balancer. We're running the application on linux if that matters.
If all you need is a software load balancer on linux use Apache Webserver2, Mod-Jk and Tomcat Clustering:
At your Webserver:
Install apache2 and modjk:
sudo apt-get install apache2 libapache2-mod-jk
sudo a2enmod jk
Create a workers.properties file available to your apache2. In some cases it's automatically created in your /etc/apache2 directory. This file is holding the lb config, node names, ips and ports of your Tomcat servers, i.e.:
worker.list=balancer,lbstats
#node1
worker.node1.type=ajp13
worker.node1.host=YOUR_TOMCAT-NODE-IP
worker.node1.port=YOUR_TOMCAT-NODE-AJP-PORT
worker.node1.lbfactor=10
#more nodes here ... (change name in between)
#lb config
worker.balancer.type=lb
#turn off sticky session
worker.balancer.sticky_session=0
#add all defined node names to this list (node1, node2, ...):
worker.balancer.balance_workers=node1
#lb status information (optional)
worker.lbstats.type=status
Create a Mod-Jk section in your apache2 config file, if it has not been created automatically.
JkWorkersFile /etc/apache2/workers.properties
JkLogFile /var/log/apache2/mod_jk.log
JkShmFile /tmp/jk-runtime-status
JkLogLevel info
Mount your application to the load balancer (apache2 config file):
JkMount /My-Java-App-Name balancer
JkMount /My-Java-App-Name/* balancer
JkMount /modjkstatus lbstats
At your Tomcat servers:
Install tomcat (using the tarball package, imho, way better then the apt verison). Change server.xml:
disable the http connectors in server.xml (by commenting them out).
enable AJP/1.3 connector and set the port you defined in workers.properties for this node.
add jvmRoute with the right node name to the "Engine" element:
<Engine jvmRoute="node1" ...
add a "Cluster" element for simplest configuration
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" />
Deploy your application to all tomcats and add a distributable element to your applications web.xml.
<distributable/>
Make sure the webserver can access the ajp ports on your tomcat servers and no one else can.
Start the webserver and the tomcats one after another and check the logs (/var/log/apache2/mod_jk.log, too).
Access your app: http://mywebserver.com/MyApp
Check (and deny access to) the lb status page http://mywebserver.com/modjkstatus

Glassfish Server Webservice behind Apache HTTP Server

Hi
We started to create our applications with J2EE. We now created a Webservice and deployed it to the Glassfish Server. We have written an apache proxy rule to access it via https://our.server.com/webservice-war (only https port is open to that server):
ProxyRequests Off
ProxyPass /webservice-war http://our.server.com:8080/webservice-war
ProxyPassReverse /webservice-war http://our.server.com:8080/webservice-war
Now everything works fine, but when we go to the to the ServiceEndpoint page (which is automatically generated) there is a link to the WSDL page:
http://our.server.com:8080/webservice-war/HostaliasSearchImplService?wsdl
which is obously wrong (Glassfish listens to port 8080). and also https is changed to http
Anyone an idea how I can fix it, that the automatically generated link is:
https://our.server.com/webservice-war/HostaliasSearchImplService?wsdl
BR, Rene
I discovered what I consider to be a very simple and elegant way to deal with the issue: use mod_substitute. Since those of us with this problem are already using Apache, and it's built in and simple, I liked this approach best.
I put a block similar to the below in one of my Apache conf files and found joy:
<Location />
AddOutputFilterByType SUBSTITUTE text/xml
Substitute "s|http://internal:8080/foo|https://external/foo|ni"
</Location>
Found the solution!
Anonym gave me a good hint about mod_jk. So here the complete configuration (for RHEL5).
First of all Download the mod_jk module for apache: http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.31/x86_64/
Put in in the modules directory /etc/httpd/modules and make it executeable:
chmod +x mod_jk-1.2.31-httpd-2.2.x.so
After that create /etc/httpd/conf/workers.properties:
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=localhost
worker.worker1.port=8009
The Port 8009 is the where the Glassfish jk connector listens (we come to that later).
No we have to configure mod_jk, therefore create the file: /etc/httpd/conf.d/mod_jk.conf with the following content:
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile /etc/httpd/conf/workers.properties
# Where to put jk logs
JkLogFile /var/log/httpd/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel debug
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
# Send everything for context /atsi-war to worker named worker1 (ajp13)
JkMount /yourapp-war/* worker1
(This means everything from your http://apache.webserver.com/yourapp-war/ will bi redirected to Glassfish yourapp-war application context)
Important, if you are using virtual hosts on apache, you have to set the option:
JkMountCopy On
for your virtual servers. Explication:
If this directive is set to "On" in
some virtual server, the mounts from
the global server will be copied to
this virtual server, more precisely
all mounts defined by JkMount or
JkUnMount.
Now we have to create the jk connecter in glassfish:
asadmin create-http-listener --listenerport 8009 --listeneraddress 0.0.0.0 --defaultvs server jk-connector
asadmin set configs.config.server-config.network-config.network-listeners.network-listener.jk-connector.jk-enabled=true
Restart Glassfish, and everything sould work.
As for rewriting the https -> http, I'm not sure that's possible(yet) without using mod_jk, see here
, but see also this little guide
Though, generally, you'll need configure Glassfish and set http.proxyPort (and probably http.proxyHost too). Hopefully that should reflect in the autogenerated WSDL URL.
Here's 3 different ways to do this:
1
Use asadmin (in the Glassfish bin/ directory, run
asadmin create-jvm-options "-Dhttp.proxyPort=80"
asadmin create-jvm-options "-Dhttp.proxyHost=our.server.com"
2
Edit domain.xml and add under the <java-config> element
<jvm-options>-Dhttp.proxyPort=80</jvm-options>
<jvm-options>-Dhttp.proxyHost=our.server.com</jvm-options>
3.
Open the Glassfish admin web page, under Application Server -> VM Settings -> JVM Options and add these options
http.proxyPort=80
http.proxyHost=our.server.com
Setting
server-config.network-config.protocols.protocol.http-listener-1.http.server-name=MyHost:80
on GlassFish Server Open Source Edition 3.1.2.2 (build 5) solved problem to me.

Categories