Search in sources :

Example 36 with Application

use of javax.ws.rs.core.Application in project che by eclipse.

the class ProjectServiceTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    WorkspaceProjectsSyncer workspaceHolder = new WsAgentTestBase.TestWorkspaceHolder();
    File root = new File(FS_PATH);
    if (root.exists()) {
        IoUtil.deleteRecursive(root);
    }
    root.mkdir();
    File indexDir = new File(INDEX_PATH);
    if (indexDir.exists()) {
        IoUtil.deleteRecursive(indexDir);
    }
    indexDir.mkdir();
    Set<PathMatcher> filters = new HashSet<>();
    filters.add(path -> {
        for (java.nio.file.Path pathElement : path) {
            if (pathElement == null || EXCLUDE_SEARCH_PATH.equals(pathElement.toString())) {
                return true;
            }
        }
        return false;
    });
    FSLuceneSearcherProvider sProvider = new FSLuceneSearcherProvider(indexDir, filters);
    vfsProvider = new LocalVirtualFileSystemProvider(root, sProvider);
    final EventService eventService = new EventService();
    // PTs for test
    ProjectTypeDef chuck = new ProjectTypeDef("chuck_project_type", "chuck_project_type", true, false) {

        {
            addConstantDefinition("x", "attr description", new AttributeValue(Arrays.asList("a", "b")));
        }
    };
    Set<ProjectTypeDef> projectTypes = new HashSet<>();
    final LocalProjectType myProjectType = new LocalProjectType("my_project_type", "my project type");
    projectTypes.add(myProjectType);
    projectTypes.add(new LocalProjectType("module_type", "module type"));
    projectTypes.add(chuck);
    ptRegistry = new ProjectTypeRegistry(projectTypes);
    phRegistry = new ProjectHandlerRegistry(new HashSet<>());
    importerRegistry = new ProjectImporterRegistry(Collections.<ProjectImporter>emptySet());
    projectServiceLinksInjector = new ProjectServiceLinksInjector();
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, ptRegistry, phRegistry, eventService);
    projectRegistry.initProjects();
    FileWatcherNotificationHandler fileWatcherNotificationHandler = new DefaultFileWatcherNotificationHandler(vfsProvider);
    FileTreeWatcher fileTreeWatcher = new FileTreeWatcher(root, new HashSet<>(), fileWatcherNotificationHandler);
    pm = new ProjectManager(vfsProvider, ptRegistry, projectRegistry, phRegistry, importerRegistry, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
    pm.initWatcher();
    HttpJsonRequest httpJsonRequest = mock(HttpJsonRequest.class, new SelfReturningAnswer());
    //List<ProjectConfigDto> modules = new ArrayList<>();
    projects = new ArrayList<>();
    addMockedProjectConfigDto(myProjectType, "my_project");
    when(httpJsonRequestFactory.fromLink(any())).thenReturn(httpJsonRequest);
    when(httpJsonRequest.request()).thenReturn(httpJsonResponse);
    when(httpJsonResponse.asDto(WorkspaceDto.class)).thenReturn(usersWorkspaceMock);
    when(usersWorkspaceMock.getConfig()).thenReturn(workspaceConfigMock);
    when(workspaceConfigMock.getProjects()).thenReturn(projects);
    //        verify(httpJsonRequestFactory).fromLink(eq(DtoFactory.newDto(Link.class)
    //                                                             .withHref(apiEndpoint + "/workspace/" + workspace + "/project")
    //                                                             .withMethod(PUT)));
    DependencySupplierImpl dependencies = new DependencySupplierImpl();
    dependencies.addInstance(ProjectTypeRegistry.class, ptRegistry);
    dependencies.addInstance(UserDao.class, userDao);
    dependencies.addInstance(ProjectManager.class, pm);
    dependencies.addInstance(ProjectImporterRegistry.class, importerRegistry);
    dependencies.addInstance(ProjectHandlerRegistry.class, phRegistry);
    dependencies.addInstance(EventService.class, eventService);
    dependencies.addInstance(ProjectServiceLinksInjector.class, projectServiceLinksInjector);
    ResourceBinder resources = new ResourceBinderImpl();
    ProviderBinder providers = ProviderBinder.getInstance();
    EverrestProcessor processor = new EverrestProcessor(new EverrestConfiguration(), dependencies, new RequestHandlerImpl(new RequestDispatcher(resources), providers), null);
    launcher = new ResourceLauncher(processor);
    processor.addApplication(new Application() {

        @Override
        public Set<Class<?>> getClasses() {
            return java.util.Collections.<Class<?>>singleton(ProjectService.class);
        }

        @Override
        public Set<Object> getSingletons() {
            return new HashSet<>(Arrays.asList(new ApiExceptionMapper()));
        }
    });
    ApplicationContext.setCurrent(anApplicationContext().withProviders(providers).build());
    env = org.eclipse.che.commons.env.EnvironmentContext.getCurrent();
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) DependencySupplierImpl(org.everrest.core.tools.DependencySupplierImpl) AttributeValue(org.eclipse.che.api.project.server.type.AttributeValue) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) FileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.FileWatcherNotificationHandler) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) ProjectImporterRegistry(org.eclipse.che.api.project.server.importer.ProjectImporterRegistry) ProjectTypeDef(org.eclipse.che.api.project.server.type.ProjectTypeDef) ResourceLauncher(org.everrest.core.tools.ResourceLauncher) EverrestConfiguration(org.everrest.core.impl.EverrestConfiguration) EverrestProcessor(org.everrest.core.impl.EverrestProcessor) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet) ProjectHandlerRegistry(org.eclipse.che.api.project.server.handlers.ProjectHandlerRegistry) HttpJsonRequest(org.eclipse.che.api.core.rest.HttpJsonRequest) ApiExceptionMapper(org.eclipse.che.api.core.rest.ApiExceptionMapper) LocalVirtualFileSystemProvider(org.eclipse.che.api.vfs.impl.file.LocalVirtualFileSystemProvider) EventService(org.eclipse.che.api.core.notification.EventService) RequestDispatcher(org.everrest.core.impl.RequestDispatcher) ProjectImporter(org.eclipse.che.api.project.server.importer.ProjectImporter) ProviderBinder(org.everrest.core.impl.ProviderBinder) PathMatcher(java.nio.file.PathMatcher) DefaultFileWatcherNotificationHandler(org.eclipse.che.api.vfs.impl.file.DefaultFileWatcherNotificationHandler) SelfReturningAnswer(org.eclipse.che.commons.test.mockito.answer.SelfReturningAnswer) RequestHandlerImpl(org.everrest.core.impl.RequestHandlerImpl) ResourceBinderImpl(org.everrest.core.impl.ResourceBinderImpl) ResourceBinder(org.everrest.core.ResourceBinder) FileTreeWatcher(org.eclipse.che.api.vfs.impl.file.FileTreeWatcher) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File) Application(javax.ws.rs.core.Application) FSLuceneSearcherProvider(org.eclipse.che.api.vfs.search.impl.FSLuceneSearcherProvider) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 37 with Application

use of javax.ws.rs.core.Application in project swagger-core by swagger-api.

the class DefaultJaxrsScannerTest method classesFromContextTest.

@Test(description = "should return singletones")
public void classesFromContextTest() {
    Application app = mock(Application.class);
    Set<Object> singletons = Sets.newHashSet(new io.swagger.jaxrs.listing.ApiListingResource(), new DefaultJaxrsScannerTest());
    when(app.getClasses()).thenReturn(null);
    when(app.getSingletons()).thenReturn(singletons);
    DefaultJaxrsScanner scanner = new DefaultJaxrsScanner();
    Set<Class<?>> output = scanner.classesFromContext(app, null);
    Set<Class<?>> classes = Sets.newHashSet(Iterables.transform(singletons, new Function<Object, Class<?>>() {

        @Override
        public Class<?> apply(Object o) {
            return o.getClass();
        }
    }));
    assertEquals(output, classes);
}
Also used : Function(com.google.common.base.Function) DefaultJaxrsScanner(io.swagger.jaxrs.config.DefaultJaxrsScanner) Application(javax.ws.rs.core.Application) Test(org.testng.annotations.Test)

Example 38 with Application

use of javax.ws.rs.core.Application in project cxf by apache.

the class BookServer20 method run.

protected void run() {
    Bus bus = BusFactory.getDefaultBus();
    setBus(bus);
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setResourceClasses(BookStore.class);
    List<Object> providers = new ArrayList<>();
    providers.add(new PreMatchContainerRequestFilter2());
    providers.add(new PreMatchContainerRequestFilter());
    providers.add(new PostMatchContainerResponseFilter());
    providers.add((Feature) context -> {
        context.register(new PostMatchContainerResponseFilter3());
        return true;
    });
    providers.add(new PostMatchContainerResponseFilter2());
    providers.add(new CustomReaderBoundInterceptor());
    providers.add(new CustomReaderInterceptor());
    providers.add(new CustomWriterInterceptor());
    providers.add(new CustomDynamicFeature());
    providers.add(new PostMatchContainerRequestFilter());
    providers.add(new FaultyContainerRequestFilter());
    providers.add(new PreMatchReplaceStreamOrAddress());
    providers.add(new ServerTestFeature());
    providers.add(new JacksonJaxbJsonProvider());
    providers.add(new IOExceptionMapper());
    sf.setApplication(new Application());
    sf.setProviders(providers);
    sf.setResourceProvider(BookStore.class, new SingletonResourceProvider(new BookStore(), true));
    sf.setAddress("http://localhost:" + PORT + "/");
    server = sf.create();
    BusFactory.setDefaultBus(null);
    BusFactory.setThreadDefaultBus(null);
}
Also used : StringUtils(org.apache.cxf.common.util.StringUtils) ExceptionMapper(javax.ws.rs.ext.ExceptionMapper) Application(javax.ws.rs.core.Application) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) MediaType(javax.ws.rs.core.MediaType) ByteArrayInputStream(java.io.ByteArrayInputStream) ReaderInterceptor(javax.ws.rs.ext.ReaderInterceptor) Map(java.util.Map) URI(java.net.URI) Method(java.lang.reflect.Method) Context(javax.ws.rs.core.Context) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) PreMatching(javax.ws.rs.container.PreMatching) Priority(javax.annotation.Priority) DynamicFeature(javax.ws.rs.container.DynamicFeature) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) WriterInterceptorContext(javax.ws.rs.ext.WriterInterceptorContext) Response(javax.ws.rs.core.Response) Type(java.lang.reflect.Type) Annotation(java.lang.annotation.Annotation) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) ContainerResponseContext(javax.ws.rs.container.ContainerResponseContext) Bus(org.apache.cxf.Bus) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) Feature(javax.ws.rs.core.Feature) ReaderInterceptorContext(javax.ws.rs.ext.ReaderInterceptorContext) HashMap(java.util.HashMap) Retention(java.lang.annotation.Retention) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) FeatureContext(javax.ws.rs.core.FeatureContext) ResourceInfo(javax.ws.rs.container.ResourceInfo) WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOUtils(org.apache.cxf.helpers.IOUtils) IOException(java.io.IOException) Target(java.lang.annotation.Target) ElementType(java.lang.annotation.ElementType) NameBinding(javax.ws.rs.NameBinding) BusFactory(org.apache.cxf.BusFactory) AbstractBusTestServerBase(org.apache.cxf.testutil.common.AbstractBusTestServerBase) InjectionUtils(org.apache.cxf.jaxrs.utils.InjectionUtils) InputStream(java.io.InputStream) RetentionPolicy(java.lang.annotation.RetentionPolicy) Bus(org.apache.cxf.Bus) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) ArrayList(java.util.ArrayList) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) JacksonJaxbJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider) Application(javax.ws.rs.core.Application)

Example 39 with Application

use of javax.ws.rs.core.Application in project cxf by apache.

the class OpenApiFeature method getApplicationOrDefault.

/**
 * Detects the application (if present) or creates the default application (in case the scan is disabled).
 */
protected Application getApplicationOrDefault(final Server server, final ServerProviderFactory factory, final JAXRSServiceFactoryBean sfb, final Bus bus) {
    ApplicationInfo appInfo = null;
    if (!isScan()) {
        appInfo = factory.getApplicationProvider();
        if (appInfo == null) {
            appInfo = new ApplicationInfo(new DefaultApplication(sfb.getClassResourceInfo(), resourcePackages), bus);
            server.getEndpoint().put(Application.class.getName(), appInfo);
        }
    }
    return (appInfo == null) ? null : appInfo.getProvider();
}
Also used : ApplicationInfo(org.apache.cxf.jaxrs.model.ApplicationInfo) Application(javax.ws.rs.core.Application)

Example 40 with Application

use of javax.ws.rs.core.Application in project cxf by apache.

the class OpenApiFeature method initialize.

@Override
public void initialize(Server server, Bus bus) {
    final JAXRSServiceFactoryBean sfb = (JAXRSServiceFactoryBean) server.getEndpoint().get(JAXRSServiceFactoryBean.class.getName());
    final ServerProviderFactory factory = (ServerProviderFactory) server.getEndpoint().get(ServerProviderFactory.class.getName());
    final Set<String> packages = new HashSet<>();
    if (resourcePackages != null) {
        packages.addAll(resourcePackages);
    }
    Properties swaggerProps = null;
    GenericOpenApiContextBuilder<?> openApiConfiguration;
    final Application application = getApplicationOrDefault(server, factory, sfb, bus);
    if (StringUtils.isEmpty(getConfigLocation())) {
        swaggerProps = getSwaggerProperties(propertiesLocation, bus);
        if (isScan()) {
            packages.addAll(scanResourcePackages(sfb));
        }
        final OpenAPI oas = new OpenAPI().info(getInfo(swaggerProps));
        registerComponents(securityDefinitions).ifPresent(oas::setComponents);
        final SwaggerConfiguration config = new SwaggerConfiguration().openAPI(oas).prettyPrint(getOrFallback(isPrettyPrint(), swaggerProps, PRETTY_PRINT_PROPERTY)).readAllResources(isReadAllResources()).ignoredRoutes(getIgnoredRoutes()).filterClass(getOrFallback(getFilterClass(), swaggerProps, FILTER_CLASS_PROPERTY)).resourceClasses(getResourceClasses()).resourcePackages(getOrFallback(packages, swaggerProps, RESOURCE_PACKAGE_PROPERTY));
        openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).openApiConfiguration(config);
    } else {
        openApiConfiguration = new JaxrsOpenApiContextBuilder<>().application(application).configLocation(getConfigLocation());
    }
    try {
        final OpenApiContext context = openApiConfiguration.buildContext(true);
        final Properties userProperties = getUserProperties(context.getOpenApiConfiguration().getUserDefinedOptions());
        registerOpenApiResources(sfb, packages, context.getOpenApiConfiguration());
        registerSwaggerUiResources(sfb, combine(swaggerProps, userProperties), factory, bus);
        if (customizer != null) {
            customizer.setApplicationInfo(factory.getApplicationProvider());
        }
    } catch (OpenApiConfigurationException ex) {
        throw new RuntimeException("Unable to initialize OpenAPI context", ex);
    }
}
Also used : ServerProviderFactory(org.apache.cxf.jaxrs.provider.ServerProviderFactory) OpenApiConfigurationException(io.swagger.v3.oas.integration.OpenApiConfigurationException) Properties(java.util.Properties) SwaggerConfiguration(io.swagger.v3.oas.integration.SwaggerConfiguration) JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) Application(javax.ws.rs.core.Application) OpenAPI(io.swagger.v3.oas.models.OpenAPI) HashSet(java.util.HashSet) OpenApiContext(io.swagger.v3.oas.integration.api.OpenApiContext)

Aggregations

Application (javax.ws.rs.core.Application)63 HashSet (java.util.HashSet)14 HashMap (java.util.HashMap)12 ApplicationInfo (org.apache.cxf.jaxrs.model.ApplicationInfo)12 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 Set (java.util.Set)7 ServletException (javax.servlet.ServletException)7 Annotation (java.lang.annotation.Annotation)5 List (java.util.List)5 Map (java.util.Map)5 ApplicationPath (javax.ws.rs.ApplicationPath)4 WebApplicationException (javax.ws.rs.WebApplicationException)4 ClassResourceInfo (org.apache.cxf.jaxrs.model.ClassResourceInfo)4 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)3 Method (java.lang.reflect.Method)3 Type (java.lang.reflect.Type)3 Collection (java.util.Collection)3