@Override
public void service(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
ProxyEndpointService proxyEndpointService = null;
// /files/<<endpointName>>/<<serviceType>>/fileName?args
String pathinfo = request.getPathInfo().substring(request.getPathInfo().indexOf("/files"));
String[] pathTokens = pathinfo.split("/");
if (pathTokens.length > 4) {
String serviceType = pathTokens[3];
Application application = Application.get();
// ProxyEndpointServiceProvider.PROXY_SERVICE_TYPE is the extension ID
List<Object> proxyServiceProviders = application.findServices(ProxyEndpointServiceProvider.PROXY_SERVICE_TYPE);
if(proxyServiceProviders != null && !proxyServiceProviders.isEmpty()){
for(Object o : proxyServiceProviders){
ProxyEndpointServiceProvider pvdr = (ProxyEndpointServiceProvider)o;
proxyEndpointService = pvdr.createProxyEndpointService(serviceType);
if(proxyEndpointService != null){
break;
}
}
}
else {
DefaultProxyEndpointServiceProvider proxyEndpointServiceProvider = new DefaultProxyEndpointServiceProvider();
proxyEndpointService = proxyEndpointServiceProvider.createProxyEndpointService(serviceType);
}
}
if(proxyEndpointService != null){
proxyEndpointService.service(request, response);
}
else{
logger.log(Level.SEVERE, "ProxyEndpoint Service could not be retrieved for PathInfo {0}", pathinfo);
ProxyService.writeErrorResponse(HttpServletResponse.SC_BAD_REQUEST, "ProxyEndpoint Service could not be retrieved", new String[] {}, new String[] {}, response, request);
}