// content generators defined in plugin.xml are registered with 2 aliases, one is the id, the other is type
// so, we can still retrieve a content generator by id, even though this is not the correct way to find
// it. the correct way is to look up a content generator by pluginManager.getContentGenerator(type,
// perspectiveName)
IContentGenerator contentGenerator = (IContentGenerator) pluginManager.getBean( contentGeneratorId );
if ( contentGenerator == null ) {
OutputStream out = response.getOutputStream();
String message =
Messages.getInstance().getErrorString(
"GenericServlet.ERROR_0002_BAD_GENERATOR",
ESAPI.encoder().encodeForHTML( contentGeneratorId ) ); //$NON-NLS-1$
error( message );
out.write( message.getBytes() );
return;
}
// set the classloader of the current thread to the class loader of
// the plugin so that it can load its libraries
// Note: we cannot ask the contentGenerator class for it's classloader, since the cg may
// actually be a proxy object loaded by main the WebAppClassloader
Thread.currentThread().setContextClassLoader( pluginManager.getClassLoader( pluginId ) );
// String proxyClass = PentahoSystem.getSystemSetting( module+"/plugin.xml" ,
// "plugin/content-generators/"+contentGeneratorId,
// "content generator not found");
IParameterProvider requestParameters = new HttpRequestParameterProvider( request );
// see if this is an upload
// File uploading is a service provided by UploadFileServlet where appropriate protections
// are in place to prevent uploads that are too large.
// boolean isMultipart = ServletFileUpload.isMultipartContent(request);
// if (isMultipart) {
// requestParameters = new SimpleParameterProvider();
// // Create a factory for disk-based file items
// FileItemFactory factory = new DiskFileItemFactory();
//
// // Create a new file upload handler
// ServletFileUpload upload = new ServletFileUpload(factory);
//
// // Parse the request
// List<?> /* FileItem */items = upload.parseRequest(request);
// Iterator<?> iter = items.iterator();
// while (iter.hasNext()) {
// FileItem item = (FileItem) iter.next();
//
// if (item.isFormField()) {
// ((SimpleParameterProvider) requestParameters).setParameter(item.getFieldName(), item.getString());
// } else {
// String name = item.getName();
// ((SimpleParameterProvider) requestParameters).setParameter(name, item.getInputStream());
// }
// }
// }
response.setCharacterEncoding( LocaleHelper.getSystemEncoding() );
IMimeTypeListener listener = new HttpMimeTypeListener( request, response );
outputHandler = getOutputHandler( response, true );
outputHandler.setMimeTypeListener( listener );
IParameterProvider sessionParameters = new HttpSessionParameterProvider( session );
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
parameterProviders.put( IParameterProvider.SCOPE_REQUEST, requestParameters );
parameterProviders.put( IParameterProvider.SCOPE_SESSION, sessionParameters );
parameterProviders.put( "headers", headerParams ); //$NON-NLS-1$
parameterProviders.put( "path", pathParams ); //$NON-NLS-1$
SimpleUrlFactory urlFactory =
new SimpleUrlFactory( requestContext.getContextPath() + urlPath + "?" ); //$NON-NLS-1$ //$NON-NLS-2$
List<String> messages = new ArrayList<String>();
contentGenerator.setOutputHandler( outputHandler );
contentGenerator.setMessagesList( messages );
contentGenerator.setParameterProviders( parameterProviders );
contentGenerator.setSession( session );
contentGenerator.setUrlFactory( urlFactory );
// String contentType = request.getContentType();
// contentGenerator.setInput(input);
contentGenerator.createContent();
if ( PentahoSystem.debug ) {
debug( "Generic Servlet content generate successfully" ); //$NON-NLS-1$
}
} catch ( Exception e ) {