@Test( expected = IOException.class ) public void testLoadApplicationTemplate_zip_inexistingZip() throws Exception { File targetFile = new File( "not/existing/file" ); this.client.getManagementDelegate().uploadZippedApplicationTemplate( targetFile ); }
public void uploadZippedApplicationTemplate( File applicationFile ) throws ManagementWsException, IOException { if( applicationFile == null || ! applicationFile.exists() || ! applicationFile.isFile()) throw new IOException( "Expected an existing file as parameter." ); this.logger.finer( "Loading an application from " + applicationFile.getAbsolutePath() + "..." ); FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FileDataBodyPart( "file", applicationFile, MediaType.APPLICATION_OCTET_STREAM_TYPE)); WebResource path = this.resource.path( UrlConstants.APPLICATIONS ).path( "templates" ); ClientResponse response = this.wsClient.createBuilder( path ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( ClientResponse.class, part ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new ManagementWsException( response.getStatusInfo().getStatusCode(), value ); } this.logger.finer( String.valueOf( response.getStatusInfo())); }
ManagementWsDelegate { public void uploadZippedApplicationTemplate( File applicationFile ) throws ManagementWsException, IOException { if( applicationFile == null || ! applicationFile.exists() || ! applicationFile.isFile()) throw new IOException( "Expected an existing file as parameter." ); this.logger.finer( "Loading an application from " + applicationFile.getAbsolutePath() + "..." ); FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FileDataBodyPart( "file", applicationFile, MediaType.APPLICATION_OCTET_STREAM_TYPE)); WebResource path = this.resource.path( UrlConstants.APPLICATIONS ).path( "templates" ); ClientResponse response = this.wsClient.createBuilder( path ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( ClientResponse.class, part ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new ManagementWsException( response.getStatusInfo().getStatusCode(), value ); } this.logger.finer( String.valueOf( response.getStatusInfo())); } }
ManagementWsDelegate { public void uploadZippedApplicationTemplate( File applicationFile ) throws ManagementWsException, IOException { if( applicationFile == null || ! applicationFile.exists() || ! applicationFile.isFile()) throw new IOException( "Expected an existing file as parameter." ); this.logger.finer( "Loading an application from " + applicationFile.getAbsolutePath() + "..." ); FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FileDataBodyPart( "file", applicationFile, MediaType.APPLICATION_OCTET_STREAM_TYPE)); WebResource path = this.resource.path( UrlConstants.APPLICATIONS ).path( "templates" ); ClientResponse response = this.wsClient.createBuilder( path ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( ClientResponse.class, part ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new ManagementWsException( response.getStatusInfo().getStatusCode(), value ); } this.logger.finer( String.valueOf( response.getStatusInfo())); } ManagementWsDelegate( WebResource resource, WsClient wsClient ); }
ManagementWsDelegate { public void uploadZippedApplicationTemplate( File applicationFile ) throws ManagementWsException, IOException { if( applicationFile == null || ! applicationFile.exists() || ! applicationFile.isFile()) throw new IOException( "Expected an existing file as parameter." ); this.logger.finer( "Loading an application from " + applicationFile.getAbsolutePath() + "..." ); FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FileDataBodyPart( "file", applicationFile, MediaType.APPLICATION_OCTET_STREAM_TYPE)); WebResource path = this.resource.path( UrlConstants.APPLICATIONS ).path( "templates" ); ClientResponse response = this.wsClient.createBuilder( path ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( ClientResponse.class, part ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new ManagementWsException( response.getStatusInfo().getStatusCode(), value ); } this.logger.finer( String.valueOf( response.getStatusInfo())); } ManagementWsDelegate( WebResource resource, WsClient wsClient ); void uploadZippedApplicationTemplate( File applicationFile ); void loadUnzippedApplicationTemplate( String localFilePath ); void loadZippedApplicationTemplate( String url ); List<ApplicationTemplate> listApplicationTemplates( String exactName, String exactQualifier ); List<ApplicationTemplate> listApplicationTemplates(); void deleteApplicationTemplate( String templateName, String templateQualifier ); Application createApplication( String applicationName, String templateName, String templateQualifier ); List<Application> listApplications( String exactName ); List<Application> listApplications(); void shutdownApplication( String applicationName ); void deleteApplication( String applicationName ); }
ManagementWsDelegate { public void uploadZippedApplicationTemplate( File applicationFile ) throws ManagementWsException, IOException { if( applicationFile == null || ! applicationFile.exists() || ! applicationFile.isFile()) throw new IOException( "Expected an existing file as parameter." ); this.logger.finer( "Loading an application from " + applicationFile.getAbsolutePath() + "..." ); FormDataMultiPart part = new FormDataMultiPart(); part.bodyPart( new FileDataBodyPart( "file", applicationFile, MediaType.APPLICATION_OCTET_STREAM_TYPE)); WebResource path = this.resource.path( UrlConstants.APPLICATIONS ).path( "templates" ); ClientResponse response = this.wsClient.createBuilder( path ) .type( MediaType.MULTIPART_FORM_DATA_TYPE ) .post( ClientResponse.class, part ); if( Family.SUCCESSFUL != response.getStatusInfo().getFamily()) { String value = response.getEntity( String.class ); this.logger.finer( response.getStatusInfo() + ": " + value ); throw new ManagementWsException( response.getStatusInfo().getStatusCode(), value ); } this.logger.finer( String.valueOf( response.getStatusInfo())); } ManagementWsDelegate( WebResource resource, WsClient wsClient ); void uploadZippedApplicationTemplate( File applicationFile ); void loadUnzippedApplicationTemplate( String localFilePath ); void loadZippedApplicationTemplate( String url ); List<ApplicationTemplate> listApplicationTemplates( String exactName, String exactQualifier ); List<ApplicationTemplate> listApplicationTemplates(); void deleteApplicationTemplate( String templateName, String templateQualifier ); Application createApplication( String applicationName, String templateName, String templateQualifier ); List<Application> listApplications( String exactName ); List<Application> listApplications(); void shutdownApplication( String applicationName ); void deleteApplication( String applicationName );  }