use of org.pentaho.platform.web.http.HttpOutputHandler in project pentaho-platform by pentaho.
the class UIServlet method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
PentahoSystem.systemEntryPoint();
try {
OutputStream outputStream = response.getOutputStream();
String path = request.getContextPath();
IPentahoSession userSession = getPentahoSession(request);
HttpSession session = request.getSession();
// $NON-NLS-1$
String type = MediaType.valueOf(request.getParameter("type")).toString();
if (type == null) {
// $NON-NLS-1$
type = "text/html";
}
// find out which component is going to fulfill this request
// $NON-NLS-1$
String componentName = StringEscapeUtils.escapeHtml(request.getParameter("component"));
if (componentName == null) {
// $NON-NLS-1$
response.setContentType("text/html");
StringBuffer buffer = new StringBuffer();
formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0001_COMPONENT_NOT_SPECIFIED");
outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
return;
}
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// TODO switch this to the interface once stable
IUIComponent component = (IUIComponent) session.getAttribute(componentName);
if (component == null) {
component = getComponent(componentName);
if (component == null) {
// $NON-NLS-1$
response.setContentType("text/html");
StringBuffer buffer = new StringBuffer();
formatErrorMessage(userSession, buffer, "UIServlet.ERROR_0002_COMPONENT_INVALID");
outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
return;
}
session.setAttribute(componentName, component);
}
if (!component.validate()) {
// TODO need an error here
return;
}
String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/content?type=" + type + "&component=" + componentName + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
"&";
response.setContentType(type);
HttpOutputHandler outputHandler = new HttpOutputHandler(response, outputStream, true);
SimpleUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
HttpServletRequestHandler requestHandler = new HttpServletRequestHandler(userSession, null, request, outputHandler, urlFactory);
requestHandler.handleUIRequest(component, type);
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.web.http.HttpOutputHandler in project pentaho-platform by pentaho.
the class SolutionEngineInteractivityService method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
PentahoSystem.systemEntryPoint();
try {
IPentahoSession userSession = getPentahoSession(request);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
// $NON-NLS-1$
String solutionName = request.getParameter("solution");
// $NON-NLS-1$
String actionPath = request.getParameter("path");
// $NON-NLS-1$
String actionName = request.getParameter("action");
IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
String fileName = null;
if (actionSequence != null) {
String title = actionSequence.getTitle();
if ((title != null) && (title.length() > 0)) {
fileName = title;
} else {
String sequenceName = actionSequence.getSequenceName();
if ((sequenceName != null) && (sequenceName.length() > 0)) {
fileName = sequenceName;
} else {
List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
int i = 0;
boolean done = false;
while ((actionDefinitionsList.size() > i) && !done) {
IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
String componentName = actionDefinition.getComponentName();
if ((componentName != null) && (componentName.length() > 0)) {
fileName = componentName;
done = true;
} else {
i++;
}
}
}
}
}
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
outputHandler.setSession(userSession);
IMimeTypeListener listener = new HttpMimeTypeListener(request, response);
listener.setName(fileName);
outputHandler.setMimeTypeListener(listener);
SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + // $NON-NLS-1$
"SolutionEngineInteractivityService?");
IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
setupOutputHandler(outputHandler, requestParameters);
HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
handleActionRequest(request, response, outputHandler, requestHandler, requestParameters, outputStream, null);
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.web.http.HttpOutputHandler in project pentaho-platform by pentaho.
the class GenericServlet method getOutputHandler.
protected IOutputHandler getOutputHandler(HttpServletResponse response, boolean allowFeedback) throws IOException {
OutputStream out = response.getOutputStream();
HttpOutputHandler handler = new HttpOutputHandler(response, out, allowFeedback);
return handler;
}
use of org.pentaho.platform.web.http.HttpOutputHandler in project pentaho-platform by pentaho.
the class ViewAction method doGet.
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
PentahoSystem.systemEntryPoint();
try {
IPentahoSession userSession = getPentahoSession(request);
if (!doBackgroundExecution(request, response, userSession)) {
OutputStream outputStream = getOutputStream(response, doMessages(request));
ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(userSession);
// $NON-NLS-1$
String actionPath = request.getParameter("path");
IActionSequence actionSequence = actionHelper.getActionSequence(actionPath, PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
String fileName = null;
if (actionSequence != null) {
String title = actionSequence.getTitle();
if ((title != null) && (title.length() > 0)) {
fileName = title;
} else {
String sequenceName = actionSequence.getSequenceName();
if ((sequenceName != null) && (sequenceName.length() > 0)) {
fileName = sequenceName;
} else {
List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
int i = 0;
boolean done = false;
while ((actionDefinitionsList.size() > i) && !done) {
IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
String componentName = actionDefinition.getComponentName();
if ((componentName != null) && (componentName.length() > 0)) {
fileName = componentName;
done = true;
} else {
i++;
}
}
}
}
}
IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
HttpOutputHandler outputHandler = createOutputHandler(response, outputStream);
outputHandler.setSession(userSession);
IMimeTypeListener listener = new HttpMimeTypeListener(request, response, fileName);
outputHandler.setMimeTypeListener(listener);
// $NON-NLS-1$
SimpleUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath() + "ViewAction?");
IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
HttpServletRequestHandler requestHandler = getRequestHandler(request, response, userSession, requestParameters, outputStream, outputHandler, urlFactory);
handleActionRequest(request, response, outputHandler, requestHandler, outputStream, null);
}
} finally {
PentahoSystem.systemExitPoint();
}
}
use of org.pentaho.platform.web.http.HttpOutputHandler 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);
}
}
Aggregations