use of org.pentaho.platform.web.http.request.HttpRequestParameterProvider in project pentaho-platform by pentaho.
the class XactionUtil method executeXml.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeXml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession) throws Exception {
try {
HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
Map parameterProviders = new HashMap();
// $NON-NLS-1$
parameterProviders.put("request", requestParameters);
// $NON-NLS-1$
parameterProviders.put("session", sessionParameters);
List messages = new ArrayList();
IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
// $NON-NLS-1$
httpServletResponse.setContentType("text/xml");
httpServletResponse.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
OutputStream contentStream = new ByteArrayOutputStream();
SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
IRuntimeContext runtime = null;
try {
runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, messages);
OutputFormat format = OutputFormat.createCompactFormat();
format.setSuppressDeclaration(true);
// $NON-NLS-1$
format.setEncoding("utf-8");
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(outputStream, format);
writer.write(responseDoc);
writer.flush();
// $NON-NLS-1$
return outputStream.toString("utf-8");
} finally {
if (runtime != null) {
runtime.dispose();
}
}
} catch (Exception e) {
// $NON-NLS-1$
logger.warn(Messages.getInstance().getString("XactionUtil.XML_OUTPUT_NOT_SUPPORTED"));
throw e;
}
}
use of org.pentaho.platform.web.http.request.HttpRequestParameterProvider in project pentaho-platform by pentaho.
the class XactionUtil method executeScheduleUi.
/**
* This method executes an xaction with forcePrompt=true and outputPreference=PARAMETERS, allowing for the xaction to
* render the secure filter appropriately when being executed in the background or while being scheduled.
*
* @param file the location of the xaction
* @param httpServletRequest the request object
* @param httpServletResponse the response object
* @param userSession the user session
* @return potential response message
* @throws Exception
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeScheduleUi(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession, IMimeTypeListener mimeTypeListener) throws Exception {
IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
IRuntimeContext runtime = null;
try {
HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doMessages = "true".equalsIgnoreCase(requestParams.getStringParameter("debug", "false"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doWrapper = "true".equalsIgnoreCase(requestParams.getStringParameter("wrapper", "true"));
IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
if (mimeTypeListener == null) {
mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
}
outputHandler.setMimeTypeListener(mimeTypeListener);
outputHandler.setSession(userSession);
Map parameterProviders = new HashMap();
// $NON-NLS-1$
parameterProviders.put("request", requestParameters);
// $NON-NLS-1$
parameterProviders.put("session", sessionParameters);
createOutputFileName(file, outputHandler);
int outputPreference = IOutputHandler.OUTPUT_TYPE_PARAMETERS;
outputHandler.setOutputPreference(outputPreference);
List messages = new ArrayList();
// forcePrompt=true when displaying the scheduling UI
runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, true, messages);
String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, false);
return str;
} catch (Exception e) {
// $NON-NLS-1$
logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
throw e;
} finally {
if (runtime != null) {
runtime.dispose();
}
}
}
use of org.pentaho.platform.web.http.request.HttpRequestParameterProvider in project pentaho-platform by pentaho.
the class XactionUtil method executeHtml.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeHtml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession, IMimeTypeListener mimeTypeListener) throws Exception {
IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
IRuntimeContext runtime = null;
try {
HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doMessages = "true".equalsIgnoreCase(requestParams.getStringParameter("debug", "false"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doWrapper = "true".equalsIgnoreCase(requestParams.getStringParameter("wrapper", "true"));
IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
// disposition is set on the response header
if (mimeTypeListener == null) {
mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
}
outputHandler.setMimeTypeListener(mimeTypeListener);
outputHandler.setSession(userSession);
Map parameterProviders = new HashMap();
// $NON-NLS-1$
parameterProviders.put("request", requestParameters);
// $NON-NLS-1$
parameterProviders.put("session", sessionParameters);
createOutputFileName(file, outputHandler);
int outputPreference = IOutputHandler.OUTPUT_TYPE_DEFAULT;
outputHandler.setOutputPreference(outputPreference);
// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
List messages = new ArrayList();
runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, true);
return str;
} catch (Exception e) {
// $NON-NLS-1$
logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
throw e;
} finally {
if (runtime != null) {
runtime.dispose();
}
}
}
use of org.pentaho.platform.web.http.request.HttpRequestParameterProvider in project pentaho-platform by pentaho.
the class HttpServletRequestHandler method setRequest.
public void setRequest(final HttpServletRequest request) {
this.request = request;
IParameterProvider requestParameters = new HttpRequestParameterProvider(request);
setParameterProvider(HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters);
}
use of org.pentaho.platform.web.http.request.HttpRequestParameterProvider in project pentaho-platform by pentaho.
the class HttpWebService method doGetFixMe.
public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
try {
// $NON-NLS-1$
String actionPath = request.getParameter("path");
String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
String actionName = actionPath.substring(actionPath.lastIndexOf('/'));
String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
// $NON-NLS-1$
String component = request.getParameter("component");
String content = getPayloadAsString(request);
IParameterProvider parameterProvider = null;
HashMap parameters = new HashMap();
if ((content != null) && (content.length() > 0)) {
Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
// $NON-NLS-1$
List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
for (int i = 0; i < parameterNodes.size(); i++) {
Node parameterNode = (Node) parameterNodes.get(i);
String parameterName = parameterNode.getName();
String parameterValue = parameterNode.getText();
// if( "xml-data".equalsIgnoreCase( ) )
if ("action".equals(parameterName)) {
// $NON-NLS-1$
ActionInfo info = ActionInfo.parseActionString(parameterValue);
solutionName = info.getSolutionName();
actionPath = info.getPath();
actionName = info.getActionName();
} else if ("component".equals(parameterName)) {
// $NON-NLS-1$
component = parameterValue;
} else {
parameters.put(parameterName, parameterValue);
}
}
parameterProvider = new SimpleParameterProvider(parameters);
} else {
parameterProvider = new HttpRequestParameterProvider(request);
}
// $NON-NLS-1$
response.setContentType("text/xml");
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// PentahoHttpSession userSession = new PentahoHttpSession(
// request.getRemoteUser(), request.getSession(),
// request.getLocale() );
IPentahoSession userSession = getPentahoSession(request);
// $NON-NLS-1$
String instanceId = request.getParameter("instance-id");
String processId = this.getClass().getName();
OutputStream contentStream = new ByteArrayOutputStream();
SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
// send the header of the message to prevent time-outs while we are
// working
OutputStream outputStream = response.getOutputStream();
if ((component == null) || "action".equals(component)) {
// $NON-NLS-1$
// assume this is an action sequence execute
HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(userSession, null, outputHandler, parameterProvider, null);
requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, new HttpSessionParameterProvider(userSession));
requestHandler.setInstanceId(instanceId);
requestHandler.setProcessId(processId);
requestHandler.setActionPath(actionSeqPath);
if (ServletBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START"));
}
IRuntimeContext runtime = null;
try {
runtime = requestHandler.handleActionRequest(0, 0);
Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, requestHandler.getMessages());
XmlDom4JHelper.saveDom(responseDoc, outputStream, PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"), true);
} finally {
if (runtime != null) {
runtime.dispose();
}
}
} else if ("dial".equals(component)) {
// $NON-NLS-1$
doDial(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession);
} else if ("chart".equals(component)) {
// $NON-NLS-1$
doChart(actionPath, parameterProvider, outputStream, userSession);
} else if ("xaction-parameter".equals(component)) {
// $NON-NLS-1$
doParameter(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession, response);
}
} catch (Throwable t) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t);
}
if (ServletBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END"));
}
}
Aggregations