Start server with help of Jetty runner - jetty

What I have:
Application which starts embedded jetty server in main method. When I need to move it on the server I should make a myApp.jar and launch it on the server.
What I want:
Not start embedded jetty server inside of application, but make myApp.war file and start it with help of Jetty runner
What a problem:
Before start embedded server I set WebsocketHandler to my server, and then ResourceHandler to the WebsocketHandler (see code below). I have no idea how to pass those params with help of jetty runner command.
Question:
May I use java -jar jetty-runner.jar contexts/my.xml?
If yes, how can I do that
How I do it now:
public static void main(String[] args) {
WebSocketHandler handler = new WebSocketHandler() {
#Override
public void configure(WebSocketServletFactory factory) {
factory.getPolicy().setMaxMessageSize(4533423);
factory.getPolicy().setIdleTimeout(Long.MAX_VALUE);
factory.setCreator(creator);
}
};
Server server = new Server(8080);
server.setHandler(handler);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler .setDirectoriesListed(true);
resourceHandler .setResourceBase(WEB_CLIENT_PATH);
handler.setHandler(resourceHandler );
server.start();
server.join();
}

If you need to setup jetty, there is a way described in documentation:
java -jar jetty-runner.jar --config my/jetty.xml my.war
If no, what is contexts/my.xml?

Related

How to configure WSS connection on Django Azure Web App

I've attempted to make an Azure Web App using Django. For the past couple days, I've mingled with Websockets for use for a real-time chat locally using the ws protocol. But, when deploying on Azure, I am forced to use the wss protocol due to the website being hosted on https. I've done some research on how to configure wss to no avail. Can anyone help?
I initiate the connection using:
if (window.location.protocol == 'https:') {
wsProtocol = 'wss://'
} else {wsProtocol = 'ws://'}
const chatSocket = new WebSocket(wsProtocol + window.location.host + "/");
This gives: "WebSocket connection to 'wss://pharma-send.azurewebsites.net/' failed:"
I'm using django-channels.
In the Startup Command of my Azure app I've tried running the Gunicorn server with ASGI using
gunicorn pharmasend.asgi:application --bind 0.0.0.0:8000 -w 2 -k uvicorn.workers.UvicornWorker
Although, this hasn't changed anything. Do I need to run an ASGI server, like Daphne or Uvicorn? Or, does Azure's Oryx do it for me?
Thanks for helping!

Curl is working on machine but not on web browser

I created a simple nodejs app on the aws-ec2 server following the instructions. The code is:
#!/usr/bin/env nodejs
var http = require('http');
http.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8080, '138.68.244.XXX');
//138.68.244.XXX is the IP of my ec2 server
console.log('Server running at http://localhost:8080/');
After I started the app by the command: node hello.js
I got output:
Server running at http://localhost:8080/
I was able to curl the URL:
curl http://138.68.244.XXX:8080
to get “Hello World” on the server itself, however, when I tried:
http://138.68.244.XXX:8080
in a browser, I got:
ERRCONNECTIONTIMED_OUT
Please help,
Thank you!
Check this FAQ entry (how to open a port on an instance with a public IP). As port 8080 is not a standard HTTP port, you probably need to update the security group and ACL.

Is it possible to know, when running jetty server started?

I would like to know when my jetty server started.
is there any command/any other way, that can show, when the running jetty server started?
if you are start jetty from command line then sudo service jetty start will give you the starting time as well it will start the server or you can use sudo service jetty check to get the starting time of jetty server

Spring Boot Application deployed on Elastic Beanstalk Java environment returns 502

I'm trying to deploy a very simple Spring Boot application on AWS Elastic Beanstalk using AWS's Java configuration (not their Tomcat configuration), but I keep getting a 502 error with the following log:
2016/06/10 02:00:14 [error] 4921#0: *1 connect() failed
(111: Connection refused) while connecting to upstream, client: 38.94.153.178,
server: , request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:5000/test",
host: "my-single-instance-java-app.us-east-1.elasticbeanstalk.com"
I've tried setting my port via Spring's application.properties to what the log seems to want (5000, using server.port=5000) and have verified that my application runs successfully on that port on localhost.
This question is very similar, except that I'm deploying a JAR instead of a WAR. It seems like there is something I'm missing regarding configuring Nginx, and I don't know how to proceed.
Here's my Spring Application:
#SpringBootApplication
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
#RestController
public static class MainController {
#RequestMapping("/test")
public String testMethod() {
return "Method success!";
}
}
}
Nginx doesn't know on which port your spring boot applicaiton is running.
Make application run on port 5000 that Nginx redirects to by default by adding "server.port=5000" to application.properties or other suggested ways in the last step:
https://pragmaticintegrator.wordpress.com/2016/07/12/run-your-spring-boot-application-on-aws-using-elastic-beanstalk/
From your question description and the security group settings you send me your only inbound Port 80 for your EC2 instance was open to world through firewall and you were using port 5000 for your application. So using the security rule that I gave you it opened the inbound port 5000 too for your EC2 instance so your application started working without above error.
If somebody is still getting such error, after setting server.port=5000.
Here's what you can do if you got db connectivity:
In configuration section of your dashboard, go to RDS section and create a remote db. Remember username, password of formed db.
In Software section, add following properties:
SPRING_DATASOURCE_URL=jdbc:mysql://(your-db-url)/ebdb
SPRING_DATASOURCE_USERNAME=(username)
SPRING_DATASOURCE_PASSWORD=(password)
SPRING_JPA_HIBERNATE_DDL_AUTO=update
SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.MySQL5Dialect
After reading both eb-engine.log as well nginx/error.log, the default nginx port is 5000 whereas the default port for spring-boot is 8080.
We can update our application via the elastic beanstalk CLI with the setenv cmd.
eb setenv SERVER_PORT=5000
We can update this in the code via application.properties
server.port=5000
These steps worked for me,
Go-To > Environments > Select your environment,
Select "Configuration" at the left
Click on "Edit" against Software
Scroll Down to "Environment Properties"
add one more entry SERVER_PORT and set some number, I set 5000

How may I deploy a Wt application with the built-in web server?

I am new using Wt and I would like to know what I must do to get an example (let’s say Hello) working on a web server (Apache or free webhost for testing).
I know how to use the built-in web server ; I have to launch that command :
./hello.wt --docroot . --http-address 0.0.0.0 --http-port 8080
Then, I go to http://127.0.0.1:8080/ and it is working.
But, how may I do this using Apache ?
Thanks.
Pass -DCONNECTOR_FCGI=ON to cmake and follow these instructions for configuring FastCGI with Apache
I added FastCgiServer /dir/to/Wt/Examples/Hello/hello.wt to my fastcgi.conf and now it's working.