Search in sources :

Example 1 with MimeMappings

use of io.undertow.util.MimeMappings in project keycloak by keycloak.

the class SecureServerDefinition method createHttpManagementConfigContextService.

private static Service<Void> createHttpManagementConfigContextService(final String factoryName, final InjectedValue<ExtensibleHttpManagement> httpConfigContext) {
    final String contextName = "/keycloak/adapter/" + factoryName + "/";
    return new Service<Void>() {

        public void start(StartContext startContext) throws StartException {
            ExtensibleHttpManagement extensibleHttpManagement = (ExtensibleHttpManagement) httpConfigContext.getValue();
            extensibleHttpManagement.addStaticContext(contextName, new ResourceManager() {

                public Resource getResource(final String path) throws IOException {
                    KeycloakAdapterConfigService adapterConfigService = KeycloakAdapterConfigService.getInstance();
                    final String config = adapterConfigService.getJSON(factoryName);
                    if (config == null) {
                        return null;
                    }
                    return new Resource() {

                        public String getPath() {
                            return null;
                        }

                        public Date getLastModified() {
                            return null;
                        }

                        public String getLastModifiedString() {
                            return null;
                        }

                        public ETag getETag() {
                            return null;
                        }

                        public String getName() {
                            return null;
                        }

                        public boolean isDirectory() {
                            return false;
                        }

                        public List<Resource> list() {
                            return Collections.emptyList();
                        }

                        public String getContentType(MimeMappings mimeMappings) {
                            return "application/json";
                        }

                        public void serve(Sender sender, HttpServerExchange exchange, IoCallback completionCallback) {
                            sender.send(config);
                        }

                        public Long getContentLength() {
                            return Long.valueOf((long) config.length());
                        }

                        public String getCacheKey() {
                            return null;
                        }

                        public File getFile() {
                            return null;
                        }

                        public Path getFilePath() {
                            return null;
                        }

                        public File getResourceManagerRoot() {
                            return null;
                        }

                        public Path getResourceManagerRootPath() {
                            return null;
                        }

                        public URL getUrl() {
                            return null;
                        }
                    };
                }

                public boolean isResourceChangeListenerSupported() {
                    return false;
                }

                public void registerResourceChangeListener(ResourceChangeListener listener) {
                }

                public void removeResourceChangeListener(ResourceChangeListener listener) {
                }

                public void close() throws IOException {
                }
            });
        }

        public void stop(StopContext stopContext) {
            ((ExtensibleHttpManagement) httpConfigContext.getValue()).removeContext(contextName);
        }

        public Void getValue() throws IllegalStateException, IllegalArgumentException {
            return null;
        }
    };
}
Also used : Path(java.nio.file.Path) StopContext(org.jboss.msc.service.StopContext) Resource(io.undertow.server.handlers.resource.Resource) Service(org.jboss.msc.service.Service) ResourceManager(io.undertow.server.handlers.resource.ResourceManager) IOException(java.io.IOException) MimeMappings(io.undertow.util.MimeMappings) Date(java.util.Date) URL(java.net.URL) Sender(io.undertow.io.Sender) HttpServerExchange(io.undertow.server.HttpServerExchange) StartContext(org.jboss.msc.service.StartContext) ETag(io.undertow.util.ETag) IoCallback(io.undertow.io.IoCallback) ResourceChangeListener(io.undertow.server.handlers.resource.ResourceChangeListener) List(java.util.List) ExtensibleHttpManagement(org.jboss.as.server.mgmt.domain.ExtensibleHttpManagement) File(java.io.File)

Aggregations

IoCallback (io.undertow.io.IoCallback)1 Sender (io.undertow.io.Sender)1 HttpServerExchange (io.undertow.server.HttpServerExchange)1 Resource (io.undertow.server.handlers.resource.Resource)1 ResourceChangeListener (io.undertow.server.handlers.resource.ResourceChangeListener)1 ResourceManager (io.undertow.server.handlers.resource.ResourceManager)1 ETag (io.undertow.util.ETag)1 MimeMappings (io.undertow.util.MimeMappings)1 File (java.io.File)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 Date (java.util.Date)1 List (java.util.List)1 ExtensibleHttpManagement (org.jboss.as.server.mgmt.domain.ExtensibleHttpManagement)1 Service (org.jboss.msc.service.Service)1 StartContext (org.jboss.msc.service.StartContext)1 StopContext (org.jboss.msc.service.StopContext)1