Search in sources :

Example 1 with ApplicationInstallResultJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.

the class ApplicationResourceTest method install_exception.

@Test
public void install_exception() throws Exception {
    ApplicationResource resource = getResourceInstance();
    MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
    ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
    String fileName = "app-name";
    Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
    Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq("app-name"))).thenThrow(new RuntimeException());
    Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
    ApplicationInstallResultJson result = resource.install(multipartForm);
    assertEquals("Failed to process application app-name", result.getFailure());
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ByteSource(com.google.common.io.ByteSource) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Test(org.junit.jupiter.api.Test)

Example 2 with ApplicationInstallResultJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final URL url, byte[] sha512) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(url, sha512);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application from " + url;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 3 with ApplicationInstallResultJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.

the class ApplicationResource method installUrl.

@POST
@Path("installUrl")
@Consumes(MediaType.APPLICATION_JSON)
public ApplicationInstallResultJson installUrl(final ApplicationInstallParams params) {
    final String urlString = params.getUrl();
    final byte[] sha512 = Optional.ofNullable(params.getSha512()).map(HexEncoder::fromHex).orElse(null);
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    String failure;
    try {
        final URL url = new URL(urlString);
        if (ALLOWED_PROTOCOLS.contains(url.getProtocol())) {
            return installApplication(url, sha512);
        } else {
            failure = "Illegal protocol: " + url.getProtocol();
            result.setFailure(failure);
            return result;
        }
    } catch (IOException e) {
        LOG.error(failure = "Failed to upload application from " + urlString, e);
        result.setFailure(failure);
        return result;
    }
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) IOException(java.io.IOException) URL(java.net.URL) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 4 with ApplicationInstallResultJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.

the class ApplicationResource method installApplication.

private ApplicationInstallResultJson installApplication(final ByteSource byteSource, final String applicationName) {
    final ApplicationInstallResultJson result = new ApplicationInstallResultJson();
    try {
        final Application application = this.applicationService.installGlobalApplication(byteSource, applicationName);
        result.setApplicationInstalledJson(new ApplicationInstalledJson(application, false));
    } catch (Exception e) {
        final String failure = "Failed to process application " + applicationName;
        LOG.error(failure, e);
        result.setFailure(failure);
    }
    return result;
}
Also used : ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) Application(com.enonic.xp.app.Application) IOException(java.io.IOException)

Example 5 with ApplicationInstallResultJson

use of com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson in project xp by enonic.

the class ApplicationResourceTest method install.

@Test
public void install() throws Exception {
    ApplicationResource resource = getResourceInstance();
    ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
    Application application = createApplication();
    MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
    Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
    String fileName = application.getDisplayName();
    Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq(fileName))).thenReturn(application);
    Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
    ApplicationInstallResultJson result = resource.install(multipartForm);
    assertEquals(new ApplicationInstalledJson(application, false), result.getApplicationInstalledJson());
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ApplicationInstalledJson(com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson) ByteSource(com.google.common.io.ByteSource) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Application(com.enonic.xp.app.Application) Test(org.junit.jupiter.api.Test)

Aggregations

ApplicationInstallResultJson (com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson)5 Application (com.enonic.xp.app.Application)3 ApplicationInstalledJson (com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson)3 IOException (java.io.IOException)3 MultipartForm (com.enonic.xp.web.multipart.MultipartForm)2 MultipartItem (com.enonic.xp.web.multipart.MultipartItem)2 ByteSource (com.google.common.io.ByteSource)2 Test (org.junit.jupiter.api.Test)2 URL (java.net.URL)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1