use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.
the class AxisServiceExecutorTest method setUp.
@Before
public void setUp() throws Exception {
StandaloneSession session = new StandaloneSession("test");
StubServiceSetup serviceSetup = new StubServiceSetup();
serviceSetup.setSession(session);
AxisConfiguration axisCfg = serviceSetup.getAxisConfiguration();
ConfigurationContext configContext = new ConfigurationContext(axisCfg);
serviceSetup.loadServices();
TransportInDescription tIn = new TransportInDescription(DEAFULT_TRANSPOT_PROTOCOL);
StubTransportListener receiver = new StubTransportListener();
tIn.setReceiver(receiver);
axisCfg.addTransportIn(tIn);
TransportOutDescription tOut = new TransportOutDescription(DEAFULT_TRANSPOT_PROTOCOL);
StubTransportSender sender = new StubTransportSender();
tOut.setSender(sender);
axisCfg.addTransportOut(tOut);
AxisWebServiceManager.currentAxisConfiguration = axisCfg;
AxisWebServiceManager.currentAxisConfigContext = configContext;
out = new ByteArrayOutputStream();
IOutputHandler outputHandler = new SimpleOutputHandler(out, false);
outputHandler.setMimeTypeListener(new MimeTypeListener());
contentGenerator = new AxisServiceExecutor();
contentGenerator.setOutputHandler(outputHandler);
contentGenerator.setMessagesList(new ArrayList<String>());
contentGenerator.setSession(session);
contentGenerator.setUrlFactory(new SimpleUrlFactory(BASE_URL + "?"));
assertNotNull("contentGenerator is null", contentGenerator);
assertNotNull("Logger is null", contentGenerator.getLogger());
}
use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.
the class ActionSequenceAction method execute.
public void execute() throws Exception {
IOutputHandler outputHandler = null;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
} else {
outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
}
IRuntimeContext rt = null;
try {
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
solutionEngine.setCreateFeedbackParameterCallback(null);
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.setForcePrompt(false);
ArrayList messages = new ArrayList();
HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
String xactionPath = null;
if (xactionDefInputStream instanceof RepositoryFileInputStream) {
xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
}
rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
if (!outputHandler.contentDone()) {
if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
// set content which generated by sequence for pass it to caller
List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
setActionOutputContents(components);
boolean isFlushed = false;
boolean isEmpty;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
isFlushed = repositoryFileOutputStream.isFlushed();
isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
if (mimeTypeFromExtension == null) {
// unknown type, treat it not as an extension but part of the name
extension = "";
}
if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
}
} else {
isEmpty = xactionResultsOutputStream.toString().isEmpty();
}
if (!isFlushed) {
if (isEmpty) {
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
}
xactionResultsOutputStream.close();
}
} else {
// we need an error message...
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
xactionResultsOutputStream.close();
}
}
} finally {
if (rt != null) {
rt.dispose();
}
}
}
use of org.pentaho.platform.api.engine.IOutputHandler in project pentaho-platform by pentaho.
the class SoapHelperTest method testCreateSoapResponseDocumentFromContext.
/**
* Tests for SoapHelper.createSoapResponseDocument(IRuntimeContext, IOutputHandler, OutputStream, List)
*/
public void testCreateSoapResponseDocumentFromContext() {
// Set up test data
Set<Object> outputNames = new HashSet<>();
IActionParameter actionParameter = mock(IActionParameter.class);
when(actionParameter.getValue()).thenReturn("testValue");
IRuntimeContext context = mock(IRuntimeContext.class);
when(context.getOutputNames()).thenReturn(outputNames);
when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
when(context.getOutputParameter(anyString())).thenReturn(actionParameter);
List messages = new ArrayList();
IOutputHandler outputHandler = mock(IOutputHandler.class);
IContentItem contentItem = mock(IContentItem.class);
when(outputHandler.getOutputContentItem(anyString(), anyString(), anyString(), anyString())).thenReturn(contentItem);
when(contentItem.getMimeType()).thenReturn("text/xml");
OutputStream contentStream = mock(OutputStream.class);
when(contentStream.toString()).thenReturn("contentStreamTestString");
// Tests for document with two output names
outputNames.add("outputName1");
outputNames.add("outputName2");
Document d1 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse1 = d1.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertEquals(activityResponse1.elements().size(), 2);
assertNotNull(activityResponse1.element("outputName1"));
assertNotNull(activityResponse1.element("outputName2"));
// Test for document with one output name (different branch in createSoapResponseDocument())
outputNames.clear();
outputNames.add("outputName1");
Document d2 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse2 = d2.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertEquals(activityResponse2.elements().size(), 1);
assertNotNull(activityResponse2.element("outputName1"));
// Tests for document with no output names
outputNames.clear();
Document d3 = SoapHelper.createSoapResponseDocument(context, outputHandler, contentStream, messages);
Element activityResponse3 = d3.getRootElement().element("SOAP-ENV:Body").element("ExecuteActivityResponse");
assertTrue(activityResponse3.elements().isEmpty());
}
use of org.pentaho.platform.api.engine.IOutputHandler 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.api.engine.IOutputHandler 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();
}
}
}
Aggregations