Apache coyote vulnerability fixes are causing wrong port usage - java

I'm using an embedded tomcat server in one of my java project. the creation of server looks like
Tomcat _tomcat = new Tomcat();
i have configured the Tomcat server to use port numbers from 9001
everything was working fine.
Problem statement
To address the Apache coyote vulnerability which was addressed in a nessus scan i have modified the tomcat server creation to
Tomcat _tomcat = new Tomcat();
_tomcat.getConnector().setXpoweredBy(false);
_tomcat.getConnector().setProperty("server", "");
after doing this change tomcat server is binding to port number 8080, which i have not configured anywhere, this is causing issue when i try to run two instances at once. gives the below error. Tomcat server unable to bind error
Question
How to avoid tomcat server from using port 8080 with apache coyote vulnerability fixes?

Here when you do _tomcat.getConnector() a connector instance is called which is not yet initialized, and it uses default values and listens at port 8080 which is default port for a tomcat Connector instance.
instead of performing setXpoweredBy(false) and setProperty("server", "") on defualt instance of connector, move this part to where you are creating tomcat Connector instance. something like
Connector connector = new Connector();
connector.setPort(port);
connector.setXpoweredBy(false);
connector.setProperty("server", "");
and then set this connector to tomcat server
_tomcat.setConnector(connector);

Related

Embedded Jetty: How to set the JMX port in source code

We have system tests and when they start an Embedded Jetty boots via the setup. The Embedded Jetty includes a JMX server, too. Then we have tests which must connect to the JMX Server via:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:<JMX_PORT>/jmxrmi");
JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
The problem is we cannot connect from the tests to the JMX server when we do not know the JMX port up front. Has anybody a clue how to specify the JMX port up front when the Embedded Jetty is built within the source code? The system property stuff is of no help here.

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

Timeout while deploying Java Application to remote glassfish server from Netbeans

while deploying to a remote Glassfish 4.1 Server from Netbeans 8.0.1, i get a Timeout.
I configured the Glassfish Server by adding a new Server Instance and that seemed to work. I can see the applications running on the server and i am able to undeploy a application (directly from netbeans).
But when i try to deploy my application to the remote Server, i get a timeout Exception.
(i used enable-secure-admin to gain remote access from netbeans to the server)
What confuses me is, that when i enabled secure admin, i expected to see a https:// url in netbeans. But this url starts with http:// and i cant find an option to change this.
Server Attributes:
Host: [remote-ip]
DAS Port: 4848
Domain: domain1 (same as on the remote server)
Target: empty
Username PW : as set on the remote server
"Enable JDBC Driver Deployment" and "Preserve Sessions Across Redeployment" are checked
Could you please attach the logs.
most probably its issue with the grizzly jar.
Please try the patched grizzly jar and see if it works for you.
Checkout : https://java.net/jira/browse/GRIZZLY-1713 for the same

How to get bound server address and port programmatically in Java EE?

At startup we need to get the server address and the http port of the running application. Until now we made it like this:
MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
ObjectName socketBindingMBean = new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http");
String host = (String) mBeanServer.getAttribute(socketBindingMBean, "boundAddress"),
Integer port = (Integer) mBeanServer.getAttribute(socketBindingMBean, "boundPort"));
Everything was fine but after migration from jBoss 7.1.1.Final to 7.1.3.Final we got the problem that the MBean isn't defined at server startup. That means everything is fine if I deploy the application on an already running jboss server, but if I start the server and the application is loaded up during server start MBeans are not there.
I don't know why but I have the feeling that jBoss makes sure, that out application is started/loaded before most of the MBeans. I had a small look and found out that following Mbeans are loaded after our application:
jboss.as:interface=..
jboss.as:socket-binding-group=..
jboss.as:subsystem=..
jboss.as:core-service=management.. (some)
So,
how can I force jBoss to load MBeans before my application?
is there another way/mbean where I can get my information?
I got the same issue in JBOSS Wildfly 8.1 . I solved the problem with the code below that worked for me to get server address and http port:
//http port
ManagementFactory.getPlatformMBeanServer().getAttribute(new ObjectName("jboss.as:socket-binding-group=standard-sockets,socket-binding=http"), "port");
//http adress
ManagementFactory.getPlatformMBeanServer().getAttribute(new ObjectName("jboss.as:interface=public"), "inet-address");

How to activate SSL(HTTPS) in Glassfish 3.0 embedded API?

We are implementing an application with a webservice as component and decided to use the Glassfish 3.0 embedded distri to provide the webservice. And it works.
We need a SSL(HTTPS) connection to the webservice, but we didn't find any documentation or hint how to activate it programmatically via the embedded API.
Thus we tried to configure the embedded Glassfish via domain.xml, what has a listener configured with SSL. And the port is reachable but only without SSL. The embedded Glassfish seem to ignore the configuration to activate SSL for the port.
Has anyone experience in configuring embedded Glassfish with SSL?
Ok,
sorry that it took so much time for my answer.
The programmatical embedded API seems not to porvide a way to do this task.
Except to run an asadmin command:
logger.debug("Configure port for SSL");
String command = "create-http-listener";
ParameterMap params = new ParameterMap();
params.add("listeneraddress", "0.0.0.0");
params.add("listenerport", "443");
params.add("defaultvs", "server");
params.add("securityenabled", "true");
params.add("enabled", "true");
params.add("DEFAULT", "http-listener2");
CommandRunner runner = server.getHabitat().getComponent(CommandRunner.class);
ActionReport report = server.getHabitat().getComponent(ActionReport.class);
runner.getCommandInvocation(command, report).parameters(params).execute();
Running this code is simmlar to execute:
asadmin create-http-listener --listeneraddress 0.0.0.0 --listenerport 443 --defaultvs server securityenabled=true --enabled=true http-listener2
But this solution creates a new port with SSL. Reconfigure the already started port would be a nice option.

Categories