My Web App will be deployed as a WAR package in a Jetty instance. It needs to perform a lot of caching before serving requests. How do I call the caching method before anything else? is the a static void main() in the web app standard?
A standard (old) way is to code a Servlet which takes care of initialization stuff in its init() method. You force it to be initialized at application start by adding a load-on-startup positive value in your web.xml
<servlet>
<servlet-name>myinit</servlet-name>
<servlet-class>com.example.MyInitServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
Today it's more usual to have a bean container like Spring, which takes care of this kind of things (instantiating services objects, preloading cacheable sharable data, etc).
Note: this recipe is for webapps in general, not specific to Jetty.
Related
I have a simple Spring MVC application. For that application I have Implemented Circuit Breaker Pattern using #EnableCircuitBreaker Annotation. It is working fine. But While trying to generate the hystrix stream it showing 404 error. Can anyone please help me out this.
Hystrix stream (/hystrix.stream) is only enabled if you have spring boot actuator dependency. Please try to add the below dependency into your pom or gradle build file.
org.springframework.boot:spring-boot-starter-actuator
Updated # 2017/06/26
If your application is not based on spring boot, you need to configure HystrixMetricsStreamServlet by yourself. Because /hystrix.stream is auto-configured by spring cloud netflix and it is based on spring boot.
First, you need to add dependency of com.netflix.hystrix:hystrix-metrics-event-stream into your application.
Second, you should HystrixMetricsStreamServlet servlet into web.xml like below.
<servlet>
<description></description>
<display-name>HystrixMetricsStreamServlet</display-name>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<servlet-class>com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HystrixMetricsStreamServlet</servlet-name>
<url-pattern>/hystrix.stream</url-pattern>
</servlet-mapping
If you find the details about how to configure HystrixMetricsStreamServlet in your web application here.
I have a running app in vert.x. I have many missing features or I just can say missing spring.
How can I integrate vert.x and Spring MVC working on a Tomcat server?
With Vert.x 3 I would think you would want to use the Vert.x Web capabilities as described here instead of Spring MVC if you want to give Vertx a go. It provides a different approach to developing a web application using the Multi-Reactor pattern than the traditional multi-threaded Servlet model which Spring MVC is based on. With the Servlet model every request runs on its own thread. In Vert.x there is an event loop that is single threaded. All requests are run on the same thread, which requires blocking I/O code to be written in special blocks (see Core Manual).
Depends on which Vert.x version you are using. 2.x requires a module. like mod-spring-appcontext. In Vert.x 3.x just create a Spring ApplicationContext in your code, typically in the entry point of your application, like your public static void main method. I can't get into more detail. Vert.x questions rarely, if ever, get noticed here.
I would not recommend working with vert.x on a tomcat container as there philosophies are completely different. Tomcat is a servlet container which creates different thread for each incoming call whereas vert.x works on a event-loop. If you are missing spring and will like to use its bean you can integrate it in vert.x environment and run any blocking code in worker verticles.
You can see an example here : https://github.com/vert-x3/vertx-examples/tree/master/spring-examples/spring-example
In my recent project i started using maven , instead of depending on RAD to deploy and build ear, i have been coming across little things why to use , which one is best..
My question here is , below code i copied form web.xml and it us com.ibm.ws.websvcs.transport.http.WASAxis2Servlet servlet by ibm to route http request to web services, is there any servlet present from java that can replace the above one , we dont want our ear generation should be dependent on specific application server
<servlet>
<servlet-name>com.test.HelloWorld</servlet-name>
<servlet-class>com.ibm.ws.websvcs.transport.http.WASAxis2Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>com.test.HelloWorld</servlet-name>
<url-pattern>/HelloWorldService</url-pattern>
</servlet-mapping>
No.
The Servlet that you're seeing in the web.xml is an IBM-proprietary Servlet that routes HTTP requests to Web Services and, as far as I can tell, if you're running WAS 7.0 onwards you don't need it. You can simply use JAX-WS to annotate your Web Service class.
EDIT as per OP's comment
As you're using WAS 8.5, you have JavaEE 6.0 at your disposal. You don't need any router project anymore. IBM's proprietary router was needed in previous versions of WAS in order to route HTTP requests to Web Services and/or EJBs; however, with JavaEE 6.0, you can use JAX-WS in order to automatically intercept HTTP requests by Web Service classes as well as EJBs.
If you have a "router" project, you can safely throw it away.
I have one webapplciation, i deployed it in server,server uses Jvm.
How jvm know the whether servelt object is created or not?
and one more thing In my web application having more than 5 servlet classes,then how jvm know which servlet instance created.
Servlets are declared in web.xml, when an application server which is in compliance with Servlet API start, it try to look for this file. In web.xml you have listed the servlet you want to load and the classes you should load in order to start servlets.
Servlets has their own lifecycle, if application server can not start a servlet, exception could be thrown then application server know that the servlet is no available.
Try to read more about servlets there many good tutorial over the net.
according to this guide! I run servlet successfully, but some of actions of the servlet failed, because they need servlet-api 2.5+ support. how can I use my own servlet-api library instead of domino web server's old version.
thanks!
David Taieb (software architect at IBM) stated in a comment to a blog post:
In 8.5.2, Domino introduced support for Equinox Http Service which allows you to create lightweight servlets registered via extension points. I say lightweight because these servlets are not run within the context of a traditional J2EE Web App with web.xml support. However, the Equinox Http Service lets you associate an http context to different servlets so that they share the same http session object.
Starting in 8.5.3, Domino will start supporting the XPD Web Container which is a full fledged J2EE Web Container (although it does not support things like EJBs). With the XPD Web Container, you can transform almost any WAR into a WAB (Web Archive bundle) and run it in Domino.
You maybe also want to take a look at Servlet Sample at OpenNTF.
Otherwise, please state the version of Domino, you are currently using.