use of javax.servlet.Servlet in project indy by Commonjava.
the class DotMavenDeploymentProvider method getDeploymentInfo.
@Override
public DeploymentInfo getDeploymentInfo() {
final ServletInfo servletInfo = Servlets.servlet("DotMaven", DotMavenServlet.class).setAsyncSupported(true).setLoadOnStartup(3).addMapping("/mavdav*").addMapping("/mavdav/*");
servletInfo.setInstanceFactory(new ImmediateInstanceFactory<Servlet>(servlet));
return new DeploymentInfo().addServlet(servletInfo);
}
use of javax.servlet.Servlet in project karaf by apache.
the class HttpPlugin method getServletDetails.
protected List<ServletDetails> getServletDetails() {
Collection<ServletEvent> events = servletEventHandler.getServletEvents();
List<ServletDetails> result = new ArrayList<>(events.size());
for (ServletEvent event : events) {
Servlet servlet = event.getServlet();
String servletClassName = " ";
if (servlet != null) {
servletClassName = servlet.getClass().getName();
servletClassName = servletClassName.substring(servletClassName.lastIndexOf(".") + 1, servletClassName.length());
}
String servletName = event.getServletName() != null ? event.getServletName() : " ";
if (servletName.contains(".")) {
servletName = servletName.substring(servletName.lastIndexOf(".") + 1, servletName.length());
}
String alias = event.getAlias() != null ? event.getAlias() : " ";
String[] urls = event.getUrlParameter() != null ? event.getUrlParameter() : new String[] { "" };
ServletDetails details = new ServletDetails();
details.setId(event.getBundle().getBundleId());
details.setAlias(alias);
details.setServlet(servletClassName);
details.setServletName(servletName);
details.setState(getStateString(event.getType()));
details.setUrls(urls);
result.add(details);
}
return result;
}
use of javax.servlet.Servlet in project sling by apache.
the class ModelPackageBundleListener method registerExporter.
private void registerExporter(Bundle bundle, Class<?> annotatedClass, String resourceType, Exporter exporterAnnotation, List<ServiceRegistration> regs, ExportServlet.ExportedObjectAccessor accessor) {
if (accessor != null) {
Map<String, String> baseOptions = getOptions(exporterAnnotation);
ExportServlet servlet = new ExportServlet(bundle.getBundleContext(), factory, bindingsValuesProvidersByContext, scriptEngineFactory, annotatedClass, exporterAnnotation.selector(), exporterAnnotation.name(), accessor, baseOptions);
Dictionary<String, Object> registrationProps = new Hashtable<String, Object>();
registrationProps.put("sling.servlet.resourceTypes", resourceType);
registrationProps.put("sling.servlet.selectors", exporterAnnotation.selector());
registrationProps.put("sling.servlet.extensions", exporterAnnotation.extensions());
registrationProps.put(PROP_EXPORTER_SERVLET_CLASS, annotatedClass.getName());
registrationProps.put(PROP_EXPORTER_SERVLET_NAME, exporterAnnotation.name());
log.info("registering servlet for {}, {}, {}", new Object[] { resourceType, exporterAnnotation.selector(), exporterAnnotation.extensions() });
ServiceRegistration reg = bundleContext.registerService(Servlet.class.getName(), servlet, registrationProps);
regs.add(reg);
}
}
use of javax.servlet.Servlet in project sling by apache.
the class RequestDataTest method setup.
@Before
public void setup() throws Exception {
context = new Mockery() {
{
setImposteriser(ClassImposteriser.INSTANCE);
}
};
req = context.mock(HttpServletRequest.class);
resp = context.mock(HttpServletResponse.class);
final ContentData contentData = context.mock(ContentData.class);
final Servlet servlet = context.mock(Servlet.class);
final ServletConfig servletConfig = context.mock(ServletConfig.class);
context.checking(new Expectations() {
{
allowing(req).getServletPath();
will(returnValue("/"));
allowing(req).getPathInfo();
will(returnValue(""));
allowing(req).getMethod();
will(returnValue("GET"));
allowing(req).setAttribute(with(any(String.class)), with(any(Object.class)));
allowing(req).setAttribute(with(any(String.class)), with(aNull(Object.class)));
allowing(contentData).getServlet();
will(returnValue(servlet));
allowing(servlet).getServletConfig();
will(returnValue(servletConfig));
allowing(servlet).service(with(any(ServletRequest.class)), with(any(ServletResponse.class)));
allowing(servletConfig).getServletName();
will(returnValue("SERVLET_NAME"));
allowing(req).getAttribute(RequestProgressTracker.class.getName());
will(returnValue(null));
}
});
requestData = new RequestData(null, req, resp) {
@Override
public ContentData getContentData() {
return contentData;
}
};
slingRequest = new SlingHttpServletRequestImpl(requestData, req);
slingResponse = new SlingHttpServletResponseImpl(requestData, resp);
RequestData.setMaxCallCounter(2);
}
use of javax.servlet.Servlet in project sling by apache.
the class SlingServletResolver method getDefaultErrorServlet.
/**
* Returns the default error handler servlet, which is called in case there
* is no other - better matching - servlet registered to handle an error or
* exception.
* <p>
* The default error handler servlet is registered for the resource type
* "sling/servlet/errorhandler" and method "default". This may be
* overwritten by applications globally or according to the resource type
* hierarchy of the resource.
* <p>
* If no default error handler servlet can be found an adhoc error handler
* is used as a final fallback.
*/
private Servlet getDefaultErrorServlet(final SlingHttpServletRequest request, final Resource resource, final ResourceResolver resolver) {
// find a default error handler according to the resource type
// tree of the given resource
final ResourceCollector locationUtil = new ResourceCollector(ServletResolverConstants.DEFAULT_ERROR_HANDLER_METHOD, DEFAULT_ERROR_HANDLER_RESOURCE_TYPE, resource, this.executionPaths);
final Servlet servlet = getServletInternal(locationUtil, request, resolver);
if (servlet != null) {
return servlet;
}
// the DefaultErrorHandlerServlet as an ad-hoc fallback
if (fallbackErrorServlet == null) {
// if the actual service is not registered (yet ?)
try {
final Servlet defaultServlet = new DefaultErrorHandlerServlet();
defaultServlet.init(new SlingServletConfig(servletContext, null, "Sling (Ad Hoc) Default Error Handler Servlet"));
fallbackErrorServlet = defaultServlet;
} catch (ServletException se) {
LOGGER.error("Failed to initialize error servlet", se);
}
}
return fallbackErrorServlet;
}
Aggregations