Search in sources :

Example 71 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class StackLoaderTest method predefinedStackWithValidJsonShouldBeCreated2.

@Test
public void predefinedStackWithValidJsonShouldBeCreated2() throws ServerException, NotFoundException, ConflictException {
    URL url = Resources.getResource("stacks.json");
    URL urlFolder = Thread.currentThread().getContextClassLoader().getResource("stack_img");
    doThrow(new ServerException("Internal server error")).when(stackDao).update(any());
    stackLoader = new StackLoader(url.getPath(), urlFolder.getPath(), stackDao, null);
    stackLoader.start();
    verify(stackDao, times(5)).update(any());
    verify(stackDao, times(5)).create(any());
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 72 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class WorkspaceDaoTest method shouldNotRemoveWorkspaceWhenSubscriberThrowsExceptionOnWorkspaceRemoving.

@Test(dependsOnMethods = "shouldGetWorkspaceById")
public void shouldNotRemoveWorkspaceWhenSubscriberThrowsExceptionOnWorkspaceRemoving() throws Exception {
    final WorkspaceImpl workspace = workspaces[0];
    CascadeEventSubscriber<BeforeWorkspaceRemovedEvent> subscriber = mockCascadeEventSubscriber();
    doThrow(new ServerException("error")).when(subscriber).onCascadeEvent(any());
    eventService.subscribe(subscriber, BeforeWorkspaceRemovedEvent.class);
    try {
        workspaceDao.remove(workspace.getId());
        fail("WorkspaceDao#remove had to throw server exception");
    } catch (ServerException ignored) {
    }
    assertEquals(workspaceDao.get(workspace.getId()), workspace);
    eventService.unsubscribe(subscriber, BeforeWorkspaceRemovedEvent.class);
}
Also used : WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) ServerException(org.eclipse.che.api.core.ServerException) BeforeWorkspaceRemovedEvent(org.eclipse.che.api.workspace.server.event.BeforeWorkspaceRemovedEvent) Test(org.testng.annotations.Test)

Example 73 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class JpaPreferenceDao method getPreferences.

@Override
@Transactional
public Map<String, String> getPreferences(String userId) throws ServerException {
    requireNonNull(userId);
    try {
        final EntityManager manager = managerProvider.get();
        final PreferenceEntity prefs = manager.find(PreferenceEntity.class, userId);
        return prefs == null ? new HashMap<>() : prefs.getPreferences();
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getLocalizedMessage(), ex);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) ServerException(org.eclipse.che.api.core.ServerException) Transactional(com.google.inject.persist.Transactional)

Example 74 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ComposerProjectInitializer method onProjectInitialized.

@Override
public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder) throws ServerException, ForbiddenException, ConflictException, NotFoundException {
    String[] commandLine = { "composer", "install" };
    File workDir = projectFolder.getVirtualFile().toIoFile();
    try {
        ComposerCommandExecutor.execute(commandLine, workDir);
    } catch (TimeoutException | IOException | InterruptedException e) {
        throw new ServerException(e);
    }
}
Also used : ServerException(org.eclipse.che.api.core.ServerException) IOException(java.io.IOException) File(java.io.File) TimeoutException(java.util.concurrent.TimeoutException)

Example 75 with ServerException

use of org.eclipse.che.api.core.ServerException in project che by eclipse.

the class ApiInfoService method readApiInfo.

private ApiInfo readApiInfo() throws ServerException {
    try {
        URL url = ApiInfoService.class.getProtectionDomain().getCodeSource().getLocation();
        try (JarFile jar = new JarFile(new File(url.toURI()))) {
            final Manifest manifest = requireNonNull(jar.getManifest(), "Manifest must not be null");
            final Attributes mainAttributes = manifest.getMainAttributes();
            final DtoFactory dtoFactory = DtoFactory.getInstance();
            return dtoFactory.createDto(ApiInfo.class).withSpecificationVendor(mainAttributes.getValue("Specification-Vendor")).withImplementationVendor(mainAttributes.getValue("Implementation-Vendor")).withSpecificationTitle("Codenvy REST API").withSpecificationVersion(mainAttributes.getValue("Specification-Version")).withImplementationVersion(mainAttributes.getValue("Implementation-Version")).withScmRevision(mainAttributes.getValue("SCM-Revision"));
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
        throw new ServerException("Unable read info about API. Contact support for assistance.");
    }
}
Also used : DtoFactory(org.eclipse.che.dto.server.DtoFactory) ServerException(org.eclipse.che.api.core.ServerException) Attributes(java.util.jar.Attributes) JarFile(java.util.jar.JarFile) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) File(java.io.File) URL(java.net.URL) ServerException(org.eclipse.che.api.core.ServerException)

Aggregations

ServerException (org.eclipse.che.api.core.ServerException)143 IOException (java.io.IOException)51 ForbiddenException (org.eclipse.che.api.core.ForbiddenException)37 NotFoundException (org.eclipse.che.api.core.NotFoundException)37 ConflictException (org.eclipse.che.api.core.ConflictException)32 File (java.io.File)22 Test (org.testng.annotations.Test)20 ArrayList (java.util.ArrayList)19 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)19 List (java.util.List)15 WorkspaceImpl (org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl)15 Map (java.util.Map)13 Transactional (com.google.inject.persist.Transactional)12 BadRequestException (org.eclipse.che.api.core.BadRequestException)12 InputStream (java.io.InputStream)11 Unlocker (org.eclipse.che.commons.lang.concurrent.Unlocker)10 String.format (java.lang.String.format)9 Path (javax.ws.rs.Path)9 Produces (javax.ws.rs.Produces)9 HashMap (java.util.HashMap)8