JobManager { protected static Response.ResponseBuilder calculateContentDisposition( final Response.ResponseBuilder response, final IAsyncReportState state ) { final org.pentaho.reporting.libraries.base.util.IOUtils utils = org.pentaho.reporting.libraries .base.util.IOUtils.getInstance(); final String mimeType = state.getMimeType(); final String targetExt = MimeHelper.getExtension( mimeType ); final String fullPath = state.getPath(); final String sourceExt = utils.getFileExtension( fullPath ); String cleanFileName = utils.stripFileExtension( utils.getFileName( fullPath ) ); if ( StringUtil.isEmpty( cleanFileName ) ) { cleanFileName = "content"; } final String disposition = getDispositionType( mimeType ) + " filename*=UTF-8''" + RepositoryPathEncoder .encode( RepositoryPathEncoder.encodeRepositoryPath( cleanFileName + targetExt ) ); response.header( "Content-Disposition", disposition ); response.header( "Content-Description", cleanFileName + sourceExt ); return response; } JobManager();  JobManager( final boolean isSupportAsync, final long pollingIntervalMilliseconds,
                     final long dialogThresholdMillisecond );  JobManager( final boolean isSupportAsync, final long pollingIntervalMilliseconds,
                     final long dialogThresholdMillisecond, final boolean promptForLocation ); @GET @Path( "config" ) @Produces( APPLICATION_JSON ) Response getConfig(); @GET @Path( "{job_id}/content" ) Response getPDFContent( @PathParam( "job_id" ) final String job_id ); @SuppressWarnings( "unchecked" ) @POST @Path( "{job_id}/content" ) Response getContent( @PathParam( "job_id" ) final String jobId ); @GET @Path( "{job_id}/status" ) @Produces( APPLICATION_JSON ) Response getStatus( @PathParam( "job_id" ) final String jobId ); @SuppressWarnings( "unchecked" ) @GET @Path( "{job_id}/cancel" ) Response cancel( @PathParam( "job_id" ) final String jobId ); @GET @Path( "{job_id}/requestPage/{page}" ) @Produces( TEXT_PLAIN ) Response requestPage( @PathParam( "job_id" ) final String jobId, @PathParam( "page" ) final int page ); @GET @Path( "{job_id}/schedule" ) @Produces( TEXT_PLAIN ) Response schedule( @PathParam( "job_id" ) final String jobId, @DefaultValue( "true" )
                            @QueryParam( "confirm" ) final boolean confirm ); @POST @Path( "{job_id}/schedule" ) @Produces( APPLICATION_JSON ) Response confirmSchedule( @PathParam( "job_id" ) final String jobId,
                                   @DefaultValue( "true" )
                                   @QueryParam( "confirm" ) final boolean confirm,
                                   @DefaultValue( "false" )
                                   @QueryParam( "recalculateFinished" ) final boolean recalculateFinished,
                                   @QueryParam( "folderId" ) final String folderId,
                                   @QueryParam( "newName" ) final String newName ); ExecutionContext getContext( final String jobId ); @POST @Path( "reserveId" ) @Produces( APPLICATION_JSON ) Response reserveId();  }
@Test public void calculateContentDisposition() throws Exception { final IAsyncReportState state1 = new AsyncReportState( UUID.randomUUID(), "/somepath/anotherlevel/file.prpt", AsyncExecutionStatus.FINISHED, 0, 0, 0, 0, 0, 0, "", MimeHelper.MIMETYPE_CSV, "", false ); final Response.ResponseBuilder builder1 = mock( Response.ResponseBuilder.class ); JobManager.calculateContentDisposition( builder1, state1 ); ArgumentCaptor<String> argument = ArgumentCaptor.forClass( String.class ); verify( builder1, times( 1 ) ).header( eq( "Content-Description" ), argument.capture() ); assertTrue( argument.getValue().contains( "file.prpt" ) ); verify( builder1, times( 1 ) ).header( eq( "Content-Disposition" ), argument.capture() ); assertTrue( argument.getValue().contains( "attachment; filename*=UTF-8''file.csv" ) ); final IAsyncReportState state2 = new AsyncReportState( UUID.randomUUID(), "/somepath/anotherlevel/file.prpt", AsyncExecutionStatus.FINISHED, 0, 0, 0, 0, 0, 0, "", MimeHelper.MIMETYPE_PDF, "", false ); final Response.ResponseBuilder builder2 = mock( Response.ResponseBuilder.class ); JobManager.calculateContentDisposition( builder2, state2 ); argument = ArgumentCaptor.forClass( String.class ); verify( builder2, times( 1 ) ).header( eq( "Content-Description" ), argument.capture() ); assertTrue( argument.getValue().contains( "file.prpt" ) ); verify( builder2, times( 1 ) ).header( eq( "Content-Disposition" ), argument.capture() ); assertTrue( argument.getValue().contains( "inline; filename*=UTF-8''file.pdf" ) ); }