Search in sources :

Example 66 with Servlet

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);
}
Also used : ServletInfo(io.undertow.servlet.api.ServletInfo) Servlet(javax.servlet.Servlet) DeploymentInfo(io.undertow.servlet.api.DeploymentInfo)

Example 67 with Servlet

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;
}
Also used : ArrayList(java.util.ArrayList) ServletEvent(org.ops4j.pax.web.service.spi.ServletEvent) Servlet(javax.servlet.Servlet)

Example 68 with Servlet

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);
    }
}
Also used : Hashtable(java.util.Hashtable) Servlet(javax.servlet.Servlet) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 69 with Servlet

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);
}
Also used : Expectations(org.jmock.Expectations) ServletRequest(javax.servlet.ServletRequest) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) ServletResponse(javax.servlet.ServletResponse) SlingHttpServletResponseImpl(org.apache.sling.engine.impl.SlingHttpServletResponseImpl) ServletConfig(javax.servlet.ServletConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) SlingHttpServletResponse(org.apache.sling.api.SlingHttpServletResponse) Mockery(org.jmock.Mockery) SlingHttpServletRequest(org.apache.sling.api.SlingHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) SlingHttpServletRequestImpl(org.apache.sling.engine.impl.SlingHttpServletRequestImpl) Servlet(javax.servlet.Servlet) Before(org.junit.Before)

Example 70 with Servlet

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;
}
Also used : ResourceCollector(org.apache.sling.servlets.resolver.internal.helper.ResourceCollector) AbstractResourceCollector(org.apache.sling.servlets.resolver.internal.helper.AbstractResourceCollector) NamedScriptResourceCollector(org.apache.sling.servlets.resolver.internal.helper.NamedScriptResourceCollector) ServletException(javax.servlet.ServletException) SlingServletConfig(org.apache.sling.servlets.resolver.internal.helper.SlingServletConfig) DefaultErrorHandlerServlet(org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet) HttpServlet(javax.servlet.http.HttpServlet) DefaultServlet(org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet) Servlet(javax.servlet.Servlet) OptingServlet(org.apache.sling.api.servlets.OptingServlet) DefaultErrorHandlerServlet(org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet)

Aggregations

Servlet (javax.servlet.Servlet)86 Test (org.junit.Test)18 HttpServlet (javax.servlet.http.HttpServlet)16 ServletException (javax.servlet.ServletException)15 IOException (java.io.IOException)11 OptingServlet (org.apache.sling.api.servlets.OptingServlet)11 GenericServlet (javax.servlet.GenericServlet)10 DefaultErrorHandlerServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultErrorHandlerServlet)9 DefaultServlet (org.apache.sling.servlets.resolver.internal.defaults.DefaultServlet)9 ServletContext (javax.servlet.ServletContext)8 UnavailableException (javax.servlet.UnavailableException)8 Resource (org.apache.sling.api.resource.Resource)8 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)8 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)7 MockServletWebServerFactory (org.springframework.boot.web.servlet.server.MockServletWebServerFactory)7 ServletInfo (io.undertow.servlet.api.ServletInfo)6 ArrayList (java.util.ArrayList)5 Filter (javax.servlet.Filter)5 Context (org.apache.catalina.Context)5 SlingHttpServletResponse (org.apache.sling.api.SlingHttpServletResponse)5