-
Notifications
You must be signed in to change notification settings - Fork 27
Web APIs using Phantom
While Phantom is designed as a Reverse Proxy, it may also be used as an API container i.e. for deploying a Http service/API endpoint - by far the most common use of Phantom.
A Jetty Servlet container may be launched inside Phantom using Trooper Bootstrap Extensions. Web APIs are deployed as MVC controllers on the Jetty instance. Any deployed Phantom handler can be invoked from the API controllers using the TaskContext
interface as described here : Nesting calls. A example API endpoint that invokes a Phantom handler:
@Controller
public class DefaultController {
@RequestMapping(value = {"/getProductInfo"}, method = RequestMethod.GET)
public String getProductInfo(ModelMap model, HttpServletRequest request) {
Map<String,String> paramsMap = new HashMap<String,String>();
paramsMap.put("productId", request.getParameter("productId"));
TaskContextFactory.getTaskContext().executeCommand("getProductRequest", null, paramsMap);
...
}
}
The Phantom Dashboard web app uses an embedded Jetty instance as described above. Note however that the dashboard neither deploys any Phantom handlers nor invokes any since it is just an aggregator of Hystrix metrics from one or more running Phantom instances. The dashboard module can be extended, for example, to function as a Web API container by:
- Adding/Configuring
ServiceProxyComponentContainer
as the component container inbootstrap.xml
as shown here : Proxy Bootstrap Config . - Deploying handler binaries like (Sample Task Handler) with the respective handler (
spring-proxy-handler-config.xml
) and listener (spring-proxy-listener-config.xml
) configurations.