Spring boot, how to access jetty server instance? - jetty

I'm using "spring-boot-starter-web" with jetty.
After I launch the application, I was able to call rest functions.
Is there any way I can access Jetty instance directly or I can wire Server/Servlet context after the jetty starts?

If you need more control over the embedded Jetty instance, think about using your own JettyEmbeddedServletContainerFactory. Look at the Spring Boot docs, especially the section Customizing ConfigurableEmbeddedServletContainer directly. There is an example for using an a TomcatEmbeddedServletContainerFactory but its the same for Jetty (both implementing ConfigurableEmbeddedServletContainer).

Related

Having RESTful service in RCP application

We have an existing eclipse RCP application that works as a standalone product. At a high level, this product is used to configure a image specification using its UI and we can export a sample Image based on these configuration.
Now we are developing another web application that has several modules and one module of it is to develop something that our eclipse RCP application does.
Just to provide a QUICK integration of the RCP application for demo purpose, I plan to run the RCP application separately in the server machine and expose its static functionality as a RESTful webservice. So the module shall make a RESTful call to the RCP application.
Now just to begin with I tried to embed a jetty server for hosting the REST service during the start of RCP application like below
But the thing is after the Jetty server is started I am not able to access the TestWebService using the path i configured. So I am confused if this is the right approach to have a RESTful service inside a RCP application. Please note that iam able to hit the server with http://localhost:1002, but not the service.
Following is the console log when i hit on http://localhost:1002/hello/test:
It's a really weird architecture you're experimenting with.
I mean to write an RCP-application which listens on a port and offers REST services on it; this could lead to further obstacles.
Instead I would seperate it into two software artifacts: an RCP-app and a web-application (.war).
You could extract a business-logic jar (It can be an OSGi plug-in if necessary) contaning your image manipulation logic.
Then include this plug-in/.jar as a dependency in the webapp and offer out it's functionalities thru a Web-container (Tomcat, GlassFish, etc.)
So your other (third) application will connect to the Web-services offered by this .war file.
opt.1) If you need a single running instance (because of database or other shared resource) then your RCP-app will have to use this REST service too.
opt.2) If not then simple compile the .jar/plug-in containing the business-logic into your RCP-app.

Can stand-alone Jetty be used as a reverse proxy (without Apache mod-proxy)

I have an application which includes a Jetty web server that we distribute to multiple user to deploy on their servers. Based on some new requirements, we need to include reverse proxy capabilities. The Jetty documentation talks about using Apache as the reverse proxy in front of Jetty. While this works, it would be much easier to just use Jetty and not have to carry around Apache. Is there any way to configure standalone Jetty as a reverse proxy?
Sure you should be able to use the ProxyServlet which is fully async and quite customizable if needed:
http://www.eclipse.org/jetty/documentation/current/proxy-servlet.html

Compile JSP & Java on browser refresh - Tomcat

Is there any way to setup Tomcat server so whenever I make changes to Java class or JSP page the change is visible on browser refresh.
I'm bored stopping and starting Tomcat. I want to configure Tomcat like the way WAMP works [where you can see the PHP code change upon browser refresh]
If it's for development mode that's ok. Don't use it for production stuff.
You don't have to restart the server. You can restart the app through the Tomcat Manager.
You can even do this directly as: http://[hostname]:[port]/manager/reload?path=[/path/to/your/webapp]
or
Define your context as reloadable
Be careful: It is NOT recommended to place elements directly in the server.xml file
Check out the Tomcat configuration guide
For java classes: reloadable
Set to true if you want Catalina to monitor classes in /WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically reload the web application if a change is detected. This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications. You can use the Manager web application, however, to trigger reloads of deployed applications on demand.
NOTE - The value for this property will be inherited from the reloadable attribute you set on the surrounding Context component, and any value you explicitly set here will be replaced.
(http://tomcat.apache.org/tomcat-7.0-doc/config/loader.html)
For JSP: development ($CATALINA_BASE/conf/web.xml)
development - Is Jasper used in development mode? If true, the frequency at which JSPs are checked for modification may be specified via the modificationTestInterval parameter.true or false, default true.
Hope this helps

How does one add or update a WAR file/folder to the default embedded Jetty server in a Restlet 2.1 Application?

I would like to develop a Restlet 2.1 Java SE or Java EE Application that uses a (default) Jetty server, as opposed to an external Jetty/Tomcat server.
But I would like to configure the WAR file/folder that Jetty is processing, even allowing for stop(), reconfigure() or reload(), start() to happen at run time. In the external case, I can use setWar("path to war file/folder") from the Jetty API to achieve my goal, so this is plan B. Plan A is to figure out how to do this from the Restlet 2.1 API.
I cannot see a way to do it and I'm hoping that I'm just missing an obvious, or even not-so-obvious solution.
I think the Jetty WebAppProvider will provide what you need. If not, have a look at my hot swap code for WAR files in an embedded Jetty on this thread.

How can I deliver jetty with many webapps via jnlp?

I have a webapp (http://sourceforge.net/projects/sf-mvn-plugins/files/m2-repo/net/sf/maven/plugins/example-captaincasa-jnlp/0.1-SNAPSHOT/example-captaincasa-jnlp-0.1-SNAPSHOT.war/download) which uses jsf in a servlet container. This works fine with jetty-maven-plugin run-war target at my local pc. In the future I would like make more of this kind of webapps.
I am looking for a way to deliver these webapps with jetty via jnlp. The end user should be have a zero installation but the webapps needs servlet container and my hoster does not support a servlet container or application server or so on.
I don't like an embedded solution because in this case each webapp must be delivered with a separate jetty und run with a separate jetty -> too big size -> to many download size and so on.
The architecture should be similar to this:
(source: sourceforge.net)
Example: Bundle1 could contains jetty and deployed webapp1 and Bundle2 could contains jetty and deployed webapp1 and webapp2 (related to requirements of end user I would like deliver many variant of my webapps)
But what is my question?
Which jars of jetty are needed? I would like these upload to my homepage for hosting.
Which jar should I use for jetty as main jar to start him via jnlp?
Which main class should I use to start jetty via jnlp?
Which parameter could I use to configure jetty to say this is war of webapp1 and this is war of webapp2.... or this is directory of weapps for hot deployment...?
The important question for me is 1. If this is answered so that I could run jetty local (without maven plugin) and via manual maybe I could solve the rest 2-4.
Why not deploy a normal Java app (with a main() etc.) that invokes Jetty programatically via its Server class? That class is configured via code with the appropriate contexts, servlet classes etc.
I've done that before with success. The only headache is running one Jetty with multiple apps being downloaded on request (if I read your question correctly). Can you use some classloading magic, and load classes/apps on demand from a remote URL ?
I have found another way today. This is interesting too. Here is the concept:
Use java webstart to install an osgi container
Use a bundle x or a osgi service to download all bundles of your app
Use the jetty bundle to provide jetty support
Then the application is installed
I got the idea from this article:
http://www.toedter.com/blog/?p=45