How to configure ambient framework within a Tridion CWA web app - tridion

I'm adding ambient framework within an existing Tridion CWA Java web application and I have some questions regarding the mapping of java filters (ambient framework filter vs CWA filters)
In the SDL CWA 2011 SP1 documentation (online portal) they say:
16 - If you intend to use the Ambient Data Framework in combination
with CWA, also open the web.xml file in the WEB-INF/ folder and add
the following:
<filter>
<filter-name>Ambient Data Framework</filter-name>
<filter-class>com.tridion.ambientdata.web.AmbientDataServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Ambient Data Framework</filter-name>
<servlet-name>Content Delivery Web service</servlet-name>
</filter-mapping>
I don't understand this filter-mapping. In my web-app there is no Content Delivery Web Service.
My questions:
1 - Does it means Ambient Data Framework requires the installation of the Content Delivery Web Service to work ? For me the filter-mapping of Ambient Data filter should be the same as the mapping of CWA request filter
<filter-mapping>
<filter-name>cwa</filter-name>
<url-pattern>my-mapping</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>Ambient Data Framework</filter-name>
<servlet-name>my-maping</servlet-name>
</filter-mapping>
2 - What about PageFileDistributionFilter & BinaryFileDistributionFilter ?
3 - Is there a recommanded filter order ? CWA filters configured before Ambient Data filter for ex ?
Any help would be much appreciated. Thanks in advance.

On #1: It's a documentation defect, it should be this instead:
<filter>
<filter-name>Ambient Data Framework</filter-name>
<filter-class>com.tridion.ambientdata.web.AmbientDataServletFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Ambient Data Framework</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
On #2, yes you still need those two of course.
On #3, I suspect you should have the Ambient Framework loaded first, as that is the recommendation for non-CWA web apps (your filters could use the Ambient Framework, for instance)

Related

"Hystrix stream is not generating for my spring mvc application"

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.

XML-based Spring MVC argument resolver

I'm trying to migrate a big web app from Spring 2.5 to Spring 4. The whole context and MVCs are being configured using XML files, not annotated. Does anybody know if it's possible to declare argument resolvers to MVC beans injected using XML files? When using annotated controllers, the solution is to inject argument resolvers:
<mvc:annotation-driven>
<mvc:argument-resolvers>
<bean class="com.company.CustomResolver" />
</mvc:argument-resolvers>
</mvc:annotation-driven>
But I can't implement this solution because, due to size and legacy reasons, I can't migrate the app whole set of MVCs to annotated controllers.

Router servlet for webservice project

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.

Maven ignores #WebServlet annotation

I had a Dynamic Web project which had a few #WebServlet annotations, all of which worked fine. I have since switched my Dynamic Web project to a Maven web project. Since doing so, I can't access any of my servlets by what I defined in my #WebServlet annotations. I should also note that some of my servlets are overlay from other Maven projects. Do I have to now define my servlet mappings in the web.xml file?
Thanks
The Maven story aside, the #WebServlet annotation was introduced in Servlet 3.0. If they are not initialized, then it simply means that either the web application descriptor (the web.xml) is not declared conform Servlet 3.0 or that the target container does not support Servlet 3.0.
You need to verify if your web.xml conforms Servlet 3.0. I.e., the <web-app> root declaration must match that:
<web-app
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

How to initialize a web app?

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.

Resources