use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.
the class GeneratorStreamingOutput method generateContent.
protected void generateContent(OutputStream outputStream, final MimeTypeCallback callback) throws Exception {
try {
httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
} catch (Throwable t) {
// $NON-NLS-1$
logger.warn("could not set encoding, servlet-api is likely too old. are we in a unit test?");
}
IOutputHandler outputHandler = new HttpOutputHandler(httpServletResponse, outputStream, true);
outputHandler.setMimeTypeListener(new HttpMimeTypeListener(httpServletRequest, httpServletResponse) {
/*
* This content generator is setting the mimeType
*/
@Override
public void setMimeType(String mimeType) {
try {
if (!MIMETYPE_MUTABLE && GeneratorStreamingOutput.this.getMimeType() != null) {
mimeTrace(// $NON-NLS-1$
"Content generator is trying to set response mime type to [{0}], but mime type [{1}] has already been imposed. Content generator request to change mime type will be ignored.", mimeType, GeneratorStreamingOutput.this.getMimeType());
return;
} else {
// $NON-NLS-1$
mimeTrace("Content generator is setting response mime type to [{0}]", mimeType);
if (callback != null) {
callback.setMimeType(mimeType);
}
GeneratorStreamingOutput.this.setMimeType(mimeType);
}
} catch (Throwable th) {
mimeTrace("Failed to set mime type: {0}", th.getMessage());
// $NON-NLS-1$
logger.error(MessageFormat.format("Failed to set mime type: {0}", th.getMessage()));
}
super.setMimeType(mimeType);
}
});
Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, createRequestParamProvider());
parameterProviders.put(IParameterProvider.SCOPE_SESSION, createSessionParameterProvider());
// $NON-NLS-1$
parameterProviders.put("headers", createHeaderParamProvider());
// $NON-NLS-1$
parameterProviders.put("path", createPathParamProvider());
String pluginId = contentGeneratorDescriptor.getPluginId();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(PentahoRequestContextHolder.getRequestContext().getContextPath() + "api/repos/" + pluginId + "/" + contentGeneratorID + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"?");
// 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
ClassLoader origContextClassloader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(pluginMgr.getClassLoader(pluginId));
try {
contentGenerator.setOutputHandler(outputHandler);
contentGenerator.setMessagesList(new ArrayList<String>());
contentGenerator.setParameterProviders(parameterProviders);
contentGenerator.setSession(PentahoSessionHolder.getSession());
if (urlFactory != null) {
contentGenerator.setUrlFactory(urlFactory);
}
contentGenerator.createContent();
} finally {
Thread.currentThread().setContextClassLoader(origContextClassloader);
}
}
use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project data-access by pentaho.
the class DSWDatasourceServiceImpl method listDatasourceNames.
public List<String> listDatasourceNames() throws IOException {
synchronized (CsvDatasourceServiceImpl.lock) {
// $NON-NLS-1$
IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
PMDUIComponent component = new PMDUIComponent(urlFactory, new ArrayList());
component.validate(PentahoSessionHolder.getSession(), null);
component.setAction(PMDUIComponent.ACTION_LIST_MODELS);
Document document = component.getXmlContent();
// $NON-NLS-1$
List<DefaultElement> modelElements = document.selectNodes("//model_name");
ArrayList<String> datasourceNames = new ArrayList<String>();
for (DefaultElement element : modelElements) {
datasourceNames.add(element.getText());
}
return datasourceNames;
}
}
Aggregations