Port and url error in heroku app - java

I made a webservice that publish a wsdl file , here is the code
Endpoint.publish("http://localhost:"+args[0]+"/main/webServ", new WebServiceImpl());
and here is the procfile
worker: java -cp target/classes:target/dependency/* com.example.Publisher $PORT
there is no error in the log file and I got the port number from there lets say its "7435".
and when I run :
telnet whispering-beyond-3102.heroku.com
I got nothing
how can I access the webserice url ? , I tried to go to:
http://whispering-beyond-3102.heroku.com:7435/run/java/main/webServ?wsdl
I get no output
what URL should I use

If you are exposing a web service, you'll want to be defining a web process in your Procfile instead of a worker process. This will tell Heroku to inject the $PORT environment variable on app start up and route web requests to your app on that port. Web requests from the Internet to your app should be on the default 80 (or 443 for HTTPS) and then Heroku will route the request to your app on the provided $PORT. Once you fix the Procfile, you should be able to access your web service at (on default port 80):
http://whispering-beyond-3102.heroku.com/run/java/main/webServ?wsdl

Related

Postman cannot reach local Jersey REST service

While working through a programming book, I implemented a local REST service running in Tomact on port 8081 in the folder webapi (http://localhost:8081/lwchapter1/webapi/user/login). When running a request in Postman I get an error:
Could not send request
Error: connect ECONNREFUSED 127.0.0.1:8081
I dont understand, how to debug this and therefore kindly ask for help!
The service is implemented (as far as I understand) like this:
Postman to test the API
Tomcat to provide the service
compiled War File
maven as a build tool
java class listening for POST requests in a specific folder
The java project compiles, undeploy/ deploy works and the war file is in the tomcat folder, tomcat is running.
Edit: I found a developer console in Postman giving additional information. Unfortunately this doesn't help either since there is no parameter in the request:
Could not find on r. Missing or invalid parameter.
No revision id found for response
I found the solution by:
checking which ports are open and listened by using
netstat -a -n -p tcp | grep 127.0.0.1*
in the terminal
understanding in which folder the REST service listens by checking the actual java program
Thanks to #MattVickery for your kind help, I really appreciated it!

How to start H2 database command line without PG server and Web Console?

I have the H2 database v1.4.199 on an AWS EC2 machine that I want to start in TCP mode via the command line, but it looks like by default the PG server and Web Console also start, which I don't want.
I'm using a very basic command to set the port. Here's the command and output:
$ java -cp h2*.jar org.h2.tools.Server -tcpPort 9092
TCP server running at tcp://10.1.64.202:9092 (only local connections)
PG server running at pg://10.1.64.202:5435 (only local connections)
Web Console server running at http://10.1.64.202:8082 (others can connect)
Failed to start a browser to open the URL http://10.1.64.202:8082: Browser detection failed, and java property 'h2.browser' and environment variable BROWSER are not set to a browser executable.
You can see the PG Server and Console Server are up, but I thought the PG Server and Web Console were something you had to explicitly enable? I also do not want outside connections to this H2 (my Java app is on the same EC2), so seeing that the console is configured so "others can connect" in the output is a bit concerning.
What's the right way to startup H2 to make this more restricted and safer?
edit: For more context a Java app on the localhost will connect with this code:
String url = "jdbc:h2:tcp://localhost:9092/" + filePath + ";MODE=MYSQL;AUTO_RECONNECT=TRUE;DB_CLOSE_ON_EXIT=FALSE";
return DataSourceBuilder.create()
.username("sa")
.url(url)
.driverClassName(org.h2.Driver.class.getName()).build();
The Java app connects just fine, but it shouldn't need the PG server and web console to make it work.
The server's help option may offer some guidance:
java -cp h2.jar org.h2.tools.Server -?
The output includes this:
Starts the H2 Console (web-) server, TCP, and PG server.
Usage: java org.h2.tools.Server <options>
When running without options, -tcp, -web, -browser and -pg are started.
…
The solution is to start the TCP server explicitly:
java -cp h2.jar org.h2.tools.Server -tcp -tcpPort 9092

URL for webapp Docker Tomcat IntelliJ

I'm using a Tomcat 9 server in a Docker container to deploy locally a webapp for development purposes. I can connect to my Tomcat using http://localhost:8080/ But I can't find my webapp URL anywhere. My Docker container is deployed from IntelliJ, and I have no URL field in the configuration of the Container.
Does anyone know where to find/set the URL ?
There is no URL to be set, at least not explicitly.
Once you have your application started in a container (either started through IntelliJ IDEA, Docker Desktop (for), command line...) with the port binding configuration (the Bind ports config section in your screenshot), you are only left with the application as if it was started on the host on the mapped port (the first section before the colon : in the port binding).
Which means you can simply access your application on:
http://localhost:8080
following the pattern for a URL: (protocol)://(host)(:port) where:
protocol is HTTP since you mentioned using Tomcat as a web server
host being you local station where the docker daemon is running on
port being the port you chose to map to the started container port

how run two servlets in the same local host?

I was implemented two different servlets in two different web projects in netbeans using tomcat server. When try to run html file for one servlet in one project it running, but when trying to run another servlet in second project the following message appear in browser. This site cannot be reashed in localhost 8080 and localhost refused to connect.
I try to solve it by following steps in cmd:
1-ipconfig /release
2-ipconfig /all
3-ipconfig /flushdns
4-ipconfig /renew
5-netsh int ip set dns
6-netsh winsock reset
and try close proxy and windows firwall but the problem is still.
You are trying to serve requests with 2 programs in the same port, which can't be done. What would you expect it would happen if you went to localhost:8080? Both of them would be serving requests in that port, so the OS doesn't allow it.
You can go to tomcat>conf folder in one of the projects, and edit the server.xml file.
There should be a line saying Connector port. Replace "8080" for other port, for example "8081" and start tomcat.

Terminate tomcat if port is already occupied

I have a web application which runs on tomcat and reports its status to another monitoring application (this monitoring application monitors several other processes in the system).
If the app gets deployed successfully in tomcat, the monitoring application shows that the app is live and operational.
But, if tomcat fails to listen on the port which is configured in Connector element in serer.xml, still the app gets deployed, so it is shown as live in the monitoring application. But, users cannot actually access the web application since the web server is not listening on the configured port.
Is there a way I can configure tomcat so that it will terminate (or at least not deploy the webapps) if it fails to listen on the server port?
I found this gist which might help you to implement a logic that binds to Tomcat's init event and checks for status of its components (according to the comments in the gist, you might already find a maven artifact which do the same).
Create a lifecycle listener, something like ConnectorListener and make it implement the LifeCycleListener interface. Then put the code from the gist into the overrided lifeCycleEvent method (you should make some adjustments to make it fit).
Then add it to your web.xml under <engine> tags.
You can write some script in {tomcat_setup}/bin/startup.sh file.
Add below script after line contains EXECUTABLE=catalina.sh.
parent=`dirname "$PRGDIR"`
file="$parent"/conf/server.xml
host=`hostname`
#get ports from server.xml
for i in `grep -o "<Connector port=\".*\"" "$file" | cut -d\" -f2`;
do
#check port is listening
ret=`cat < /dev/null > /dev/tcp/"$host"/"$i"`
if [ $? -eq 0 ]; then
echo "Tomcat is already working!"
exit 1
fi
done

Categories

Resources