Servlet URl mapping - java

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");
// ...

Related

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

how to remove tomcat port number 8080 from localhost url using java code in web aplication

when i run a any web aplication on any server that have default port like
http://localhost:8080/demo/
But i want hide or remove 8080 port number from our aplication using java code like http://localhost/demo/ from whole application
You can't change it using Java code. HTTP uses port 80 by default. Your server deviates from that by running on port 8080. So this alternate port number must be mentioned in the url. In order to get rid of it you need to make the server accessible via port 80.
You can simply change the port to "80" instead the tomcat's default "8080" in the server.xml file in the tomcat conf folder. More info: https://tomcat.apache.org/tomcat-8.0-doc/config/server.html
Or you can use a Reverse Proxy running on port 80 forwarding requests to port 8080. If you use Apache: https://httpd.apache.org/docs/current/mod/mod_proxy.html

Websphere not directing request to proxy server on response.sendRedirect

I have secured apache reverse proxy configured in front of my websphere 8 application server. I have set generic JVM arguments -Dhttps.proxyHost and -Dhttps.proxyPort but the requests on response.sendRedirect are not directed to peoxy server. It is directed to defualt port 9080.
How to solve this issue ?
I have solved this issue on Tomcat & Jboss by modifying my connector port as follows
connector name="http" protocol="HTTP/1.1" socket-binding="http" scheme="https" proxy-name=" 192.168.1.1 " proxy-port="443" secure="true"
How do I solve this for Websphere ?
I assume that you are using like below
response.sendRedirect(request.getContextPath() +
"/my/main.jsp");
Here - request.getContextPath gives the proxied server info.
As a quick fix I resolved it using the proxy server values from properties files.
response.sendRedirect("get proxy server name from prop file" +
"/my/main.jsp");
Solved this problem by following below steps.
Add following in Apache web server's virtual host tag . What you actually need is to forward along the protocol that was used to access the server.
VirtualHost *:443>
RequestHeader set X-Forwarded-Proto "https"
….
/VirtualHost>
For more explanation refer site
https://www.nczonline.net/blog/2012/08/08/setting-up-apache-as-a-ssl-front-end-for-play/
Following properties needs be added in Websphere webcontainer properties through admin console.
Go to Application servers > server1 > Web container > Custom properties
Add Following properties
httpsIndicatorHeader -
X-Forwarded-Proto (Request header value set in web server (in our case it is https) )
com.ibm.ws.webcontainer.extractHostHeaderPort -
true (To obey request port no)
trusthostheaderport -
true (To obey request port no)
Refered the below site for this settings
http://www-01.ibm.com/support/docview.wss?uid=swg21569667
http://129.33.205.81/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.iseries.doc/ae/rweb_custom_props.html
In our case (Websphere Liberty 21.0.0.9), we simply added a couple of directives in the corresponding Apache virtual host configuration:
RequestHeader set X-Forwarded-Proto "https"
ProxyPreserveHost On`
These directives are valid only from Apache 2.3.3 on
Both are mentioned in the article mentioned below by #Darshan Shah

restrict the default url of a web application

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.

Https issue with a java web app running on apache

I'm having regarding a java web app running on apache.
One of the pages is invoking an applet which code is an external server.
The company responsible of the applet told us to use HTTPS when invoking the page showing the applet as we had problems when we invoked the page using HTTP.
The problem is that when I browse the page in HTTPS , I have an ssl_error_rx_record_too_long error.
The address I want to browse looks like :
https://www.myurl.com:8084/myWebApp/pageContainingApplet.jsp?parameter1=value1&parameter2=value2
I looked for the server.xml file under /conf and added this tag:
<Connector port="8084" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
Still nothing
Error code: ssl_error_rx_record_too_long
This usually means the implementation of SSL on your server is not correct. The error is usually caused by a server side problem which the server administrator will need to investigate. Below are some things we recommend trying.
Ensure that port 443 is open and enabled on your server. This is the
standard port for https communications.
If SSL is using a non-standard port then FireFox 3 can sometimes give
this error. Ensure SSL is running on port 443.
If using Apache2 check that you are using port 443 for SSL. This can
be done by setting the ports.conf file as follows
Listen 80 Listen 443 https Make sure you do not have more than one
SSL certificate sharing the same IP. Please ensure that all SSL
certificates utilise their own dedicated IP.
If using Apache2 check your vhost config. Some users have reported
changing to default resolved the error.
Make sure that your SSL certificate is not expired
Try to specify the Cipher:
SSLCipherSuite
ALL:!aNULL:!ADH:!eNULL:!LOW:!EXP:RC4+RSA:+HIGH:+MEDIUM:+SSLv3
Also check this : https://support.servertastic.com/error-code-ssl-error-rx-record-too-long/

Categories