flipkart-incubator / phantom

Phantom is a high performance proxy for accessing distributed services. It is an RPC system with support for different transports and protocols. Phantom is inspired by Twitter Finagle clients and builds on the capabilities of technologies like Netty, Unix Domain Sockets, Netflix Hystrix and Spring. Phantom proxies have been used to serve several hundred million API calls in production deployments at Flipkart.
49 stars 27 forks source link

the JettyWebAppContextFactory replace the first and not the last occurrence #57

Closed mestachs closed 8 years ago

mestachs commented 8 years ago

I'm bundling phantom in war (just to make start and stop easier for ops)

One thing that blocks me is that the JetteyWebAppContextFactory does'nt work well when the path contains WEB-INF

eg ....workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/phantom-war/WEB-INF/lib/runtime-1.4.4.jar!/WEB-INF is transformed to ...workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/phantom-war//lib/runtime-1.4.4.jar!/WEB-INF and not ...workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/phantom-war/WEB-INF/lib/runtime-1.4.4.jar!/

The code looks like

// trim off the "WEB-INF" part as the WebAppContext path should refer to the parent directory
        if (path.endsWith("WEB-INF")) {
            path = path.replace("WEB-INF", "");
        }

is it possible to modify it to something like

    // trim off the "WEB-INF" part as the WebAppContext path should refer to the parent directory
        if (path.endsWith("WEB-INF")) {
            path = path.substring(0, path.length() - "WEB-INF".length());
        }

or is there a way to override the common-proxy-server-nature-config.xml with my own definition ?

regunathb commented 8 years ago

Phantom is opinionated in that it does not run as an app inside a web container. In fact, it inverts the control where it is the uber container that brings up a number of socket listeners(Netty based), Jetty based admin interface and Spring ApplicationContexts - one for each deployed "Handler". We have production deployments with upto 6 such socket listeners running on the same JVM instance.

For the above design to work and also externalize configurations that can be edited independently of code, Phantom needs to be deployed in exploded form and not as a single war file. Moreover, I am not sure if this is the only change required for you to be able to run Phantom as a web app inside a servlet container.

Were you able to test if Phantom works well with the change you have proposed? If it does work, I don't see much of a problem in making the change you have requested.

Unfortunately, you cannot replace or change the beans loaded from common-proxy-server-nature-config.xml in a straightforward manner. It is picked up from the classpath. So, a workaround will be to have another file with the same name on the classpath that can be scanned before the bundled one.

regunathb commented 8 years ago

Btw, the classpath scan happens for "packaged/common-proxy-server-nature-config.xml". You need to have the replacement file follow the same path.

mestachs commented 8 years ago

My colleague will prepare a pullrequest. We still have one issue between windows and linux to investigate.

mestachs commented 8 years ago

Thanks for the explanation we found a way to override both context and code. For the record lookup in WEB-INF/classes is done before WEB-INF/lib/*.jar, and override the FileLocator to allow non unique location to the "packaged/common-proxy-server-nature-config.xml".