io.undertow.servlet.api.InstanceFactory Java Examples

The following examples show how to use io.undertow.servlet.api.InstanceFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UndertowRequestUpgradeStrategy.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private ConfiguredServerEndpoint createConfiguredServerEndpoint(String selectedProtocol,
		List<Extension> selectedExtensions, Endpoint endpoint, HttpServletRequest servletRequest) {

	String path = servletRequest.getRequestURI();  // shouldn't matter
	ServerEndpointRegistration endpointRegistration = new ServerEndpointRegistration(path, endpoint);
	endpointRegistration.setSubprotocols(Arrays.asList(selectedProtocol));
	endpointRegistration.setExtensions(selectedExtensions);

	EncodingFactory encodingFactory = new EncodingFactory(
			Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
			Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap(),
			Collections.<Class<?>, List<InstanceFactory<? extends Encoder>>>emptyMap(),
			Collections.<Class<?>, List<InstanceFactory<? extends Decoder>>>emptyMap());
	try {
		return (endpointConstructorWithEndpointFactory ?
				endpointConstructor.newInstance(endpointRegistration,
						new EndpointInstanceFactory(endpoint), null, encodingFactory, null) :
				endpointConstructor.newInstance(endpointRegistration,
						new EndpointInstanceFactory(endpoint), null, encodingFactory));
	}
	catch (Exception ex) {
		throw new HandshakeFailureException("Failed to instantiate ConfiguredServerEndpoint", ex);
	}
}
 
Example #2
Source File: ServletContextImpl.java    From quarkus-http with Apache License 2.0 6 votes vote down vote up
@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
    ensureNotInitialized();
    ensureNotProgramaticListener();
    if (ApplicationListeners.listenerState() != NO_LISTENER
            && ServletContextListener.class.isAssignableFrom(listenerClass)) {
        throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
    }
    InstanceFactory<? extends EventListener> factory = null;
    try {
        factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
    deploymentInfo.addListener(listener);
    deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
 
Example #3
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public RuntimeValue<ServletInfo> registerServlet(RuntimeValue<DeploymentInfo> deploymentInfo,
        String name,
        Class<?> servletClass,
        boolean asyncSupported,
        int loadOnStartup,
        BeanContainer beanContainer,
        InstanceFactory<? extends Servlet> instanceFactory) throws Exception {

    InstanceFactory<? extends Servlet> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(servletClass));
    ServletInfo servletInfo = new ServletInfo(name, (Class<? extends Servlet>) servletClass,
            factory);
    deploymentInfo.getValue().addServlet(servletInfo);
    servletInfo.setAsyncSupported(asyncSupported);
    if (loadOnStartup > 0) {
        servletInfo.setLoadOnStartup(loadOnStartup);
    }
    return new RuntimeValue<>(servletInfo);
}
 
Example #4
Source File: ServletContextImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void addListener(final Class<? extends EventListener> listenerClass) {
    ensureNotInitialized();
    ensureNotProgramaticListener();
    if (ApplicationListeners.listenerState() != NO_LISTENER
            && ServletContextListener.class.isAssignableFrom(listenerClass)) {
        throw UndertowServletMessages.MESSAGES.cannotAddServletContextListener();
    }
    InstanceFactory<? extends EventListener> factory = null;
    try {
        factory = deploymentInfo.getClassIntrospecter().createInstanceFactory(listenerClass);
    } catch (Exception e) {
        throw new IllegalArgumentException(e);
    }
    final ListenerInfo listener = new ListenerInfo(listenerClass, factory);
    deploymentInfo.addListener(listener);
    deployment.getApplicationListeners().addListener(new ManagedListener(listener, true));
}
 
Example #5
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<FilterInfo> registerFilter(RuntimeValue<DeploymentInfo> info,
        String name, Class<?> filterClass,
        boolean asyncSupported,
        BeanContainer beanContainer,
        InstanceFactory<? extends Filter> instanceFactory) throws Exception {

    InstanceFactory<? extends Filter> factory = instanceFactory != null ? instanceFactory
            : new QuarkusInstanceFactory(beanContainer.instanceFactory(filterClass));
    FilterInfo filterInfo = new FilterInfo(name, (Class<? extends Filter>) filterClass, factory);
    info.getValue().addFilter(filterInfo);
    filterInfo.setAsyncSupported(asyncSupported);
    return new RuntimeValue<>(filterInfo);
}
 
Example #6
Source File: EncodingFactory.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
private static <T> InstanceFactory<? extends T> createInstanceFactory(final ClassIntrospecter classIntrospecter, final Class<? extends T> decoder) throws DeploymentException {
    try {
        return classIntrospecter.createInstanceFactory(decoder);
    } catch (NoSuchMethodException e) {
        throw JsrWebSocketMessages.MESSAGES.classDoesNotHaveDefaultConstructor(decoder, e);
    }
}
 
Example #7
Source File: ConfiguredServerEndpoint.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public ConfiguredServerEndpoint(final ServerEndpointConfig endpointConfiguration, final InstanceFactory<?> endpointFactory, final PathTemplate pathTemplate, final EncodingFactory encodingFactory, AnnotatedEndpointFactory annotatedEndpointFactory, List<Extension> installed) {
    this.endpointConfiguration = endpointConfiguration;
    this.endpointFactory = endpointFactory;
    this.pathTemplate = pathTemplate;
    this.encodingFactory = encodingFactory;
    this.annotatedEndpointFactory = annotatedEndpointFactory;
    this.extensions = installed;
}
 
Example #8
Source File: ConfiguredServerEndpoint.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public ConfiguredServerEndpoint(final ServerEndpointConfig endpointConfiguration, final InstanceFactory<?> endpointFactory, final PathTemplate pathTemplate, final EncodingFactory encodingFactory) {
    this.endpointConfiguration = endpointConfiguration;
    this.endpointFactory = endpointFactory;
    this.pathTemplate = pathTemplate;
    this.encodingFactory = encodingFactory;
    this.annotatedEndpointFactory = null;
    this.extensions = endpointConfiguration.getExtensions();
}
 
Example #9
Source File: DefaultContainerConfigurator.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
@Override
public <T> T getEndpointInstance(final Class<T> endpointClass) throws InstantiationException {
    InstanceFactory<?> factory = currentInstanceFactory.get();
    if(factory != null) {
        InstanceHandle<?> instance = factory.createInstance();
        currentInstanceHandle.set(instance);
        return (T) instance.getInstance();
    }
    try {
        return endpointClass.newInstance();
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #10
Source File: Servlets.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static ListenerInfo listener(final Class<? extends EventListener> listenerClass, final InstanceFactory<? extends EventListener> instanceFactory) {
    return new ListenerInfo(listenerClass, instanceFactory);
}
 
Example #11
Source File: DefaultClassIntrospector.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public <T> InstanceFactory<T> createInstanceFactory(final Class<T> clazz) throws NoSuchMethodException {
    return new ConstructorInstanceFactory<>(clazz.getDeclaredConstructor());
}
 
Example #12
Source File: ManagedServlet.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
DefaultInstanceStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) {
    this.factory = factory;
    this.servletInfo = servletInfo;
    this.servletContext = servletContext;
}
 
Example #13
Source File: UndertowDeploymentRecorder.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public void registerListener(RuntimeValue<DeploymentInfo> info, Class<?> listenerClass, BeanContainer factory) {
    info.getValue()
            .addListener(new ListenerInfo((Class<? extends EventListener>) listenerClass,
                    (InstanceFactory<? extends EventListener>) new QuarkusInstanceFactory<>(
                            factory.instanceFactory(listenerClass))));
}
 
Example #14
Source File: ManagedServlet.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private SingleThreadModelPoolStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) {
    this.factory = factory;
    this.servletInfo = servletInfo;
    this.servletContext = servletContext;
}
 
Example #15
Source File: FilterBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public Builder setInstanceFactory(InstanceFactory<? extends Filter> instanceFactory) {
    this.instanceFactory = instanceFactory;
    return this;
}
 
Example #16
Source File: DefaultContainerConfigurator.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
static void setCurrentInstanceFactory(InstanceFactory<?> factory) {
     currentInstanceFactory.set(factory);
}
 
Example #17
Source File: FilterBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<? extends Filter> getInstanceFactory() {
    return instanceFactory;
}
 
Example #18
Source File: FilterBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<? extends Filter> getInstanceFactory() {
    return instanceFactory;
}
 
Example #19
Source File: ServletBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public Builder setInstanceFactory(InstanceFactory<? extends Servlet> instanceFactory) {
    this.instanceFactory = instanceFactory;
    return this;
}
 
Example #20
Source File: ServletBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<? extends Servlet> getInstanceFactory() {
    return instanceFactory;
}
 
Example #21
Source File: ServletBuildItem.java    From quarkus with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<? extends Servlet> getInstanceFactory() {
    return instanceFactory;
}
 
Example #22
Source File: ConfiguredServerEndpoint.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<?> getEndpointFactory() {
    return endpointFactory;
}
 
Example #23
Source File: EncodingFactory.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public EncodingFactory(final Map<Class<?>, List<InstanceFactory<? extends Encoder>>> binaryEncoders, final Map<Class<?>, List<InstanceFactory<? extends Decoder>>> binaryDecoders, final Map<Class<?>, List<InstanceFactory<? extends Encoder>>> textEncoders, final Map<Class<?>, List<InstanceFactory<? extends Decoder>>> textDecoders) {
    this.binaryEncoders = binaryEncoders;
    this.binaryDecoders = binaryDecoders;
    this.textEncoders = textEncoders;
    this.textDecoders = textDecoders;
}
 
Example #24
Source File: UndertowContainerProvider.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public <T> InstanceFactory<T> createInstanceFactory(Class<T> clazz) throws NoSuchMethodException {
    return introspecter.createInstanceFactory(clazz);
}
 
Example #25
Source File: ConfiguredClientEndpoint.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public InstanceFactory<?> getInstanceFactory() {
    return instanceFactory;
}
 
Example #26
Source File: ConfiguredClientEndpoint.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public ConfiguredClientEndpoint(final ClientEndpointConfig config, final AnnotatedEndpointFactory factory, final EncodingFactory encodingFactory, InstanceFactory<?> instanceFactory) {
    this.config = config;
    this.factory = factory;
    this.encodingFactory = encodingFactory;
    this.instanceFactory = instanceFactory;
}
 
Example #27
Source File: TestClassIntrospector.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
@Override
public <T> InstanceFactory<T> createInstanceFactory(final Class<T> clazz) throws NoSuchMethodException {
    return new ConstructorInstanceFactory<>(clazz.getDeclaredConstructor());
}
 
Example #28
Source File: ManagedServlet.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
private SingleThreadModelPoolStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) {
    this.factory = factory;
    this.servletInfo = servletInfo;
    this.servletContext = servletContext;
}
 
Example #29
Source File: ManagedServlet.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
DefaultInstanceStrategy(final InstanceFactory<? extends Servlet> factory, final ServletInfo servletInfo, final ServletContextImpl servletContext) {
    this.factory = factory;
    this.servletInfo = servletInfo;
    this.servletContext = servletContext;
}
 
Example #30
Source File: Servlets.java    From quarkus-http with Apache License 2.0 4 votes vote down vote up
public static ListenerInfo listener(final Class<? extends EventListener> listenerClass, final InstanceFactory<? extends EventListener> instanceFactory) {
    return new ListenerInfo(listenerClass, instanceFactory);
}