restrict the default url of a web application - java

upon deploying a web application in Tomcat one can access it at the url http://localhost:8080/Application_name I want to disable/restrict access through this url as I have defined different url patterns/ servlet mapping in web.xml. How to achieve this.

I guess that's what you want:
Edit tomcat/conf/server.xml.
Specify a bind address for that connector:
<Connector
port="8080"
protocol="HTTP/1.1"
address="127.0.0.1"
connectionTimeout="20000"
redirectPort="8443"
/>
In this case, I'm setting 127.0.0.1 as IP address, so you can call through 127.0.0.1:8080/Application_name
But you can put an valid IP and that's how it will work.

Related

tomcat https cause request.getParameter return null

testing server uses centos 7 and tomcat 9
originally, testing server tomcat use http, this tomcat contains 4 web apps: a.war, b.war, c.war and d.war, it works fine and its server.xml looks like:
<Connector
port="80"
protocol="HTTP/1.1"
connectionTimeout="60000"
keepAliveTimeout="15000"
maxKeepAliveRequests="-1"
maxThreads="1000"
minSpareThreads="200"
maxSpareThreads="300"
minProcessors="100"
maxProcessors="900"
acceptCount="1000"
enableLookups="false"
executor="tomcatThreadPool"
maxPostSize="-1"
compression="on"
compressionMinSize="1024"
redirectPort="443" />
then i tried to use https with self signed ssl via keytool:
<Connector
port="443"
protocol="HTTP/1.1"
minSpareThreads="5"
maxSpareThreads="75"
enableLookups="true"
disableUploadTimeout="true"
acceptCount="100"
maxThreads="200"
maxPostSize="-1"
scheme="https"
secure="true"
SSLEnabled="true"
clientAuth="false"
sslProtocol="TLS"
keystoreFile="/opt/test.keystore"
keystorePass="123456"/>
however, after login, my webapp always shows loading:
I checked the log and found that there was an exception nullpointerexception because request.getParameter('key') returns null(actually both request.getParameterMap() and request.getParameterNames() return empty), but from the browser network, this parameter has been sent.
sometimes there is no any error in the log, but my webapp still always shows loading.
for #1 above, when login success, a.war will send requests to b.war, c.war and d.war, the request parameters includes an array(has 85 items and each item contains 7 fields) and key.
if i remove the array from the request parameter, only keep the request parameter key, then there is no always shows loading in https.
after checked the tomcat documents, i tried to change protocol for https connector.
If i changed the protocol from HTTP/1.1 to org.apache.coyote.http11.Http11Nio2Protocol, then there is no any problem in https, and i can send the request parameter array too.
so i don't understand:
send request parameter array(has 85 items and each item contains 7 fields) and key in https with protocol HTTP/1.1 sometimes will cause request.getParameterMap(), request.getParameterNames() return empty and request.getParameter('key') return null
why if i remove request parameter array in https with protocol HTTP/1.1, then it works fine.
why there is no any problem in http with protocol HTTP/1.1
why using org.apache.coyote.http11.Http11Nio2Protocol in https can solve my problems.

Two way ssl in tomcat

I have an application which is hosted on AWS instance and we used elastic load balancer with AWS SSL certificate. We used tomcat server. As we used AWS SSL certificate we have not configured 443 port on tomcat. Now we want to implement two way SSL certificate. I have searched for the same but most of the information is saying use SSLEnable=true in tomcat's server.xml but this will not work in my case. Can someone please help me in this situation to implement Two way SSL.
This is how i've setup it,
(server.xml)
<Connector
port="8081"
protocol="HTTP/1.1"
proxyPort="443"
scheme="https"
secure="true"
proxyName="mydomain.com"
connectionTimeout="50000"
URIEncoding="UTF-8"
redirectPort="8443" />

tomcat server times out on start after binding to specific address

I bound my tomcat server to a specific address of a VM it's running on in order to open it up to HTTP requests on port 8443 like thus.
<Connector port="8443" protocol="HTTP/1.1"
address="192.168.122.15"
connectionTimeout="20000"
redirectPort="8443" />
Now the server times out even if I set the start timeout timer to 600 seconds (10 minutes)
I tried the following:
https://jfrog.com/knowledge-base/tomcat-takes-forever-to-start-what-can-i-do/
Tomcat 7 times out during start up
Neither of these solutions work.
Please check connection port and redirection one, as you are trying to redirect to the same port you are binding:
<Connector port="8443" [....] redirectPort="8443" />
Regards.

Can not see my IP address externally

I installed Tomcat on Windows Server. Locally, if you type localhost:8080 or 127.0.0.1:8080 everything is working properly.
I have also set:
<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
address="0.0.0.0"
/>
But when I type its IP address or hostname (installation on AWS) is a bug:
This site can’t be reached
I also have an unlocked port in the firewall
Page by IP is not seen either locally or externally
Can you add address="your_ip_address" attribute on Connector tag .
You can type your ip_address or 0.0.0.0 so that from anywhere it can accessible.
If you are using AWS. Please check Security group for that instance, that has to modify 8080 port inbound rule to allow access for globally (0.0.0.0/0)
<Connector
port="8080"
protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
just enough. no need to mention address here.
now you can be browse your tomcat http://Public_IP:8080

Servlet URl mapping

I have a servlet wich generates a picture, "pictureServlet" to reach the servlet i use :
URL pictureURL = new URL("http://localhost:8888/Picture-portlet/pictureServlet");
Embedded Picture = new Embedded("", new ExternalResource(pictureURL));
window.addComponent(Picture);
the Code is being executed in a Portlet(Vaadin) if i click on a button the picture is being added to the portlet.
the problem is that i can only reach the servlet as long as i use it on localhost , e.g if i want to reach the servlet from another host : http://mypage.de:8888how do i tell my servlet that he should use the host http://mypage.de:8888 and not the localhost , http://localhost:8888
Well, for one you are using different ports. As it looks, your server is listening on port 8888 so http://mypage.de:8888 should work just as well as http://localhost:8888. http://mypage.de:8080 will, however, not work unless you have configured a listener on port 8080. To do that, edit your server.xml (in the tomcat conf directory) and add a connector for port 8080 inside the <Service> section
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"/>
how do i tell my servlet that he should use the host http://mypage.de:8888 and not the localhost , http://localhost:8888
Just change the URL accordingly.
URL pictureURL = new URL("http://mypage.de:8888/Picture-portlet/pictureServlet");
// ...

Categories