Source Code Cross Referenced for HttpWebService.java in  » Report » pentaho-report » org » pentaho » ui » servlet » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Report » pentaho report » org.pentaho.ui.servlet 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved. 
003:         * This software was developed by Pentaho Corporation and is provided under the terms 
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use 
005:         * this file except in compliance with the license. If you need a copy of the license, 
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho 
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS" 
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to 
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Jul 12, 2005 
014:         * @author James Dixon
015:         * 
016:         */
017:
018:        package org.pentaho.ui.servlet;
019:
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.IOException;
022:        import java.io.InputStream;
023:        import java.io.OutputStream;
024:        import java.util.ArrayList;
025:        import java.util.HashMap;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.Set;
030:
031:        import javax.servlet.ServletException;
032:        import javax.servlet.http.HttpServletRequest;
033:        import javax.servlet.http.HttpServletResponse;
034:
035:        import org.apache.commons.logging.Log;
036:        import org.apache.commons.logging.LogFactory;
037:        import org.dom4j.Document;
038:        import org.dom4j.Node;
039:        import org.pentaho.core.runtime.IRuntimeContext;
040:        import org.pentaho.core.services.HttpWebServiceRequestHandler;
041:        import org.pentaho.core.session.IPentahoSession;
042:        import org.pentaho.core.solution.HttpRequestParameterProvider;
043:        import org.pentaho.core.solution.IParameterProvider;
044:        import org.pentaho.core.solution.SimpleOutputHandler;
045:        import org.pentaho.core.solution.SimpleParameterProvider;
046:        import org.pentaho.core.system.PentahoSystem;
047:        import org.pentaho.core.ui.SimpleUrlFactory;
048:        import org.pentaho.core.util.SoapUtil;
049:        import org.pentaho.core.util.UIUtil;
050:        import org.pentaho.core.util.XmlHelper;
051:        import org.pentaho.messages.Messages;
052:        import org.pentaho.messages.util.LocaleHelper;
053:        import org.pentaho.plugin.jfreechart.ChartDefinition;
054:        import org.pentaho.ui.ChartHelper;
055:        import org.pentaho.ui.component.INavigationComponent;
056:        import org.pentaho.ui.component.NavigationComponentFactory;
057:
058:        import com.pentaho.security.UserDetailsRoleListService;
059:        import com.pentaho.security.acls.PentahoAclEntry;
060:
061:        /**
062:         * Servlet Class
063:         * 
064:         * web.servlet name="ViewAction" display-name="Name for ViewAction"
065:         * description="Description for ViewAction" web.servlet-mapping
066:         * url-pattern="/ViewAction" web.servlet-init-param name="A parameter" value="A
067:         * value"
068:         */
069:        public class HttpWebService extends ServletBase {
070:
071:            /**
072:             * 
073:             */
074:            private static final long serialVersionUID = -2011812808062152707L;
075:
076:            private static final Log logger = LogFactory
077:                    .getLog(HttpWebService.class);
078:
079:            public Log getLogger() {
080:                return logger;
081:            }
082:
083:            /**
084:             * 
085:             */
086:            public HttpWebService() {
087:                super ();
088:            }
089:
090:            public String getPayloadAsString(HttpServletRequest request)
091:                    throws IOException {
092:                InputStream is = request.getInputStream();
093:                ByteArrayOutputStream os = new ByteArrayOutputStream();
094:                String content = null;
095:                try {
096:                    byte buffer[] = new byte[2048];
097:                    int b = is.read(buffer);
098:                    while (b > 0) {
099:                        os.write(buffer, 0, b);
100:                        b = is.read(buffer);
101:                    }
102:                    content = os.toString(LocaleHelper.getSystemEncoding());
103:                } catch (Exception e) {
104:                    // TODO Auto-generated catch block
105:                    e.printStackTrace();
106:                }
107:                return content;
108:            }
109:
110:            public void doGetFixMe(HttpServletRequest request,
111:                    HttpServletResponse response) throws ServletException,
112:                    IOException {
113:
114:                PentahoSystem.systemEntryPoint();
115:                try {
116:
117:                    String solutionName = request.getParameter("solution"); //$NON-NLS-1$
118:                    String actionPath = request.getParameter("path"); //$NON-NLS-1$
119:                    String actionName = request.getParameter("action"); //$NON-NLS-1$
120:                    String component = request.getParameter("component"); //$NON-NLS-1$
121:                    String content = getPayloadAsString(request);
122:
123:                    IParameterProvider parameterProvider = null;
124:                    HashMap parameters = new HashMap();
125:                    if (content != null && content.length() > 0) {
126:                        Document doc = org.pentaho.core.util.XmlHelper
127:                                .getDocFromString(content);
128:                        List parameterNodes = doc
129:                                .selectNodes("//SOAP-ENV:Body/*/*"); //$NON-NLS-1$
130:                        for (int i = 0; i < parameterNodes.size(); i++) {
131:                            Node parameterNode = (Node) parameterNodes.get(i);
132:                            String parameterName = parameterNode.getName();
133:                            String parameterValue = parameterNode.getText();
134:                            //                    String type = parameterNode.selectSingleNode( "@type" );
135:                            //                   if(  "xml-data".equalsIgnoreCase(  ) )
136:                            if ("action".equals(parameterName)) { //$NON-NLS-1$
137:                                PentahoSystem.ActionInfo info = PentahoSystem
138:                                        .parseActionString(parameterValue);
139:                                solutionName = info.getSolutionName();
140:                                actionPath = info.getPath();
141:                                actionName = info.getActionName();
142:                            } else if ("component".equals(parameterName)) { //$NON-NLS-1$
143:                                component = parameterValue;
144:                            } else {
145:                                parameters.put(parameterName, parameterValue);
146:                            }
147:
148:                        }
149:                        parameterProvider = new SimpleParameterProvider(
150:                                parameters);
151:                    } else {
152:                        parameterProvider = new HttpRequestParameterProvider(
153:                                request);
154:                    }
155:
156:                    response.setContentType("text/xml"); //$NON-NLS-1$
157:                    response.setCharacterEncoding(LocaleHelper
158:                            .getSystemEncoding());
159:                    // PentahoHttpSession userSession = new PentahoHttpSession(
160:                    // request.getRemoteUser(), request.getSession(),
161:                    // request.getLocale() );
162:                    IPentahoSession userSession = getPentahoSession(request);
163:
164:                    String instanceId = request.getParameter("instance-id"); //$NON-NLS-1$
165:                    String processId = this .getClass().getName();
166:
167:                    OutputStream contentStream = new ByteArrayOutputStream();
168:
169:                    SimpleOutputHandler outputHandler = new SimpleOutputHandler(
170:                            contentStream, false);
171:
172:                    // send the header of the message to prevent time-outs while we are
173:                    // working
174:                    OutputStream outputStream = response.getOutputStream();
175:                    if (component == null || "action".equals(component)) { //$NON-NLS-1$
176:                        // assume this is an action sequence execute
177:                        HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(
178:                                userSession, null, outputHandler,
179:                                parameterProvider, null);
180:
181:                        requestHandler.setInstanceId(instanceId);
182:                        requestHandler.setProcessId(processId);
183:                        requestHandler.setAction(actionPath, actionName);
184:                        requestHandler.setSolutionName(solutionName);
185:
186:                        if (debug)
187:                            debug(Messages
188:                                    .getString("HttpWebService.DEBUG_WEB_SERVICE_START")); //$NON-NLS-1$
189:                        IRuntimeContext runtime = null;
190:                        outputStream.write(SoapUtil.getSoapHeader().getBytes(
191:                                LocaleHelper.getSystemEncoding()));
192:                        try {
193:                            runtime = requestHandler.handleActionRequest(0, 0);
194:                            SoapUtil.generateSoapResponse(runtime,
195:                                    outputStream, outputHandler, contentStream,
196:                                    requestHandler.getMessages());
197:                            outputStream
198:                                    .write(SoapUtil.getSoapFooter().getBytes(
199:                                            LocaleHelper.getSystemEncoding()));
200:                        } finally {
201:                            if (runtime != null) {
202:                                runtime.dispose();
203:                            }
204:                        }
205:                    } else if ("dial".equals(component)) { //$NON-NLS-1$
206:                        doDial(solutionName, actionPath, actionName,
207:                                parameterProvider, outputStream, userSession);
208:                    } else if ("chart".equals(component)) { //$NON-NLS-1$
209:                        doChart(solutionName, actionPath, actionName,
210:                                parameterProvider, outputStream, userSession);
211:                    } else if ("navigate".equals(component)) { //$NON-NLS-1$
212:                        doNavigate(solutionName, actionPath, actionName,
213:                                parameterProvider, outputStream, userSession);
214:                    }
215:
216:                } catch (Throwable t) {
217:                    error(
218:                            Messages
219:                                    .getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t); //$NON-NLS-1$
220:                } finally {
221:                    PentahoSystem.systemExitPoint();
222:                }
223:                if (debug)
224:                    debug(Messages
225:                            .getString("HttpWebService.DEBUG_WEB_SERVICE_END")); //$NON-NLS-1$
226:
227:            }
228:
229:            protected void doPost(HttpServletRequest request,
230:                    HttpServletResponse response) throws ServletException,
231:                    IOException {
232:
233:                doGet(request, response);
234:
235:            }
236:
237:            private void doNavigate(String solutionName, String actionPath,
238:                    String actionName, IParameterProvider parameterProvider,
239:                    OutputStream outputStream, IPentahoSession userSession) {
240:
241:                String baseUrl = PentahoSystem.getApplicationContext()
242:                        .getBaseUrl();
243:                String hrefUrl = baseUrl;
244:                String onClick = ""; //$NON-NLS-1$
245:                String this Url = baseUrl + "./Navigate?"; //$NON-NLS-1$
246:
247:                SimpleUrlFactory urlFactory = new SimpleUrlFactory(this Url);
248:                ArrayList messages = new ArrayList();
249:
250:                if ("".equals(solutionName)) { //$NON-NLS-1$
251:                    solutionName = null;
252:                }
253:
254:                INavigationComponent navigate = NavigationComponentFactory
255:                        .getNavigationComponent();
256:                navigate.setHrefUrl(hrefUrl);
257:                navigate.setOnClick(onClick);
258:                navigate.setSolutionParamName("solution"); //$NON-NLS-1$
259:                navigate.setPathParamName("path"); //$NON-NLS-1$
260:                navigate.setAllowNavigation(new Boolean(false));
261:                navigate.setOptions(""); //$NON-NLS-1$
262:                navigate.setUrlFactory(urlFactory);
263:                navigate.setMessages(messages);
264:                // This line will override the default setting of the navigate component
265:                // to allow debugging of the generated HTML.
266:                // navigate.setLoggingLevel( org.pentaho.util.logging.ILogger.DEBUG );
267:                navigate.validate(userSession, null);
268:                navigate.setParameterProvider(
269:                        HttpRequestParameterProvider.SCOPE_REQUEST,
270:                        parameterProvider);
271:
272:                Document doc = navigate.getXmlContent();
273:                try {
274:                    writeDocumentAsSoapResponse(outputStream, doc);
275:                } catch (IOException e) {
276:                    // not much we can do here...
277:                }
278:
279:            }
280:
281:            public void writeDocumentAsSoapResponse(OutputStream outputStream,
282:                    Document doc) throws IOException {
283:                // we wrap the root element of the document rather than the document, otherwise the result
284:                // will be invalid, as it may contain XML encoding information at a point when specifying this
285:                // not allowed
286:                writeStringAsSoapResponse(outputStream, doc.getRootElement()
287:                        .asXML());
288:            }
289:
290:            public void writeStringAsSoapResponse(OutputStream outputStream,
291:                    String doc) throws IOException {
292:                outputStream.write(SoapUtil.getSoapHeader().getBytes(
293:                        LocaleHelper.getSystemEncoding()));
294:                outputStream.write(SoapUtil.openSoapResponse().getBytes(
295:                        LocaleHelper.getSystemEncoding()));
296:                outputStream
297:                        .write("<content>".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
298:                outputStream.write(doc.getBytes(LocaleHelper
299:                        .getSystemEncoding()));
300:                outputStream
301:                        .write("</content>".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
302:                outputStream.write(SoapUtil.closeSoapResponse().getBytes(
303:                        LocaleHelper.getSystemEncoding()));
304:                outputStream.write(SoapUtil.getSoapFooter().getBytes(
305:                        LocaleHelper.getSystemEncoding()));
306:            }
307:
308:            private void doDial(String solutionName, String actionPath,
309:                    String actionName, IParameterProvider parameterProvider,
310:                    OutputStream outputStream, IPentahoSession userSession) {
311:
312:                ArrayList messages = new ArrayList();
313:                StringBuffer buffer = new StringBuffer();
314:                boolean ok = ChartHelper.doDial(solutionName, actionPath,
315:                        actionName, parameterProvider, buffer, userSession,
316:                        messages, this );
317:                if (!ok) {
318:                    UIUtil
319:                            .formatErrorMessage(
320:                                    "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
321:                }
322:
323:                try {
324:                    writeStringAsSoapResponse(outputStream, buffer.toString());
325:                } catch (IOException e) {
326:                    // not much we can do here...
327:                }
328:
329:                /*
330:                 String linkUrl = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$
331:                 String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$
332:                 if (imageUrl == null) {
333:                 imageUrl = PentahoSystem.getApplicationContext().getBaseUrl();
334:                 }
335:
336:                 if (linkUrl == null) {
337:                 linkUrl = ""; //$NON-NLS-1$
338:                 }
339:
340:                 int width = (int) parameterProvider.getLongParameter("image-width", 150); //$NON-NLS-1$
341:                 int height = (int) parameterProvider.getLongParameter("image-height", 150); //$NON-NLS-1$
342:
343:                 SimpleUrlFactory urlFactory = new SimpleUrlFactory(linkUrl);
344:
345:                 ArrayList messages = new ArrayList();
346:                 DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, solutionName + File.separator + actionPath + File.separator + actionName, width, height, urlFactory, messages); //$NON-NLS-1$
347:                 widget.validate(userSession, null);
348:
349:                 widget.setParameterProvider("request", parameterProvider); //$NON-NLS-1$
350:
351:                 double value = Double.parseDouble(parameterProvider.getStringParameter("value", "0")); //$NON-NLS-1$ //$NON-NLS-2$
352:                 widget.setValue(value);
353:
354:                 String title = parameterProvider.getStringParameter("title", ""); //$NON-NLS-1$ //$NON-NLS-2$
355:                 widget.setTitle(title); //$NON-NLS-1$
356:
357:                 String content = widget.getContent("text/html"); //$NON-NLS-1$
358:
359:                 if (content == null) {
360:                 StringBuffer buffer = new StringBuffer();
361:                 UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
362:                 content = buffer.toString();
363:                 }
364:
365:                 if (content == null || content.equals("")) { //$NON-NLS-1$
366:                 content = "&nbsp;"; //$NON-NLS-1$
367:                 }
368:                 try {
369:                 outputStream.write(SoapUtil.getSoapHeader().getBytes(LocaleHelper.getSystemEncoding()));
370:                 outputStream.write(SoapUtil.openSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
371:                 outputStream.write("<content><![CDATA[".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
372:                 outputStream.write(content.getBytes(LocaleHelper.getSystemEncoding()));
373:                 outputStream.write("]]></content>".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
374:                 outputStream.write(SoapUtil.closeSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
375:                 outputStream.write(SoapUtil.getSoapFooter().getBytes(LocaleHelper.getSystemEncoding()));
376:                 } catch (IOException e) {
377:                 // not much we acn do here...
378:                 }
379:                 */
380:            }
381:
382:            private void doChart(String solutionName, String actionPath,
383:                    String actionName, IParameterProvider parameterProvider,
384:                    OutputStream outputStream, IPentahoSession userSession) {
385:
386:                String chartTypeStr = parameterProvider.getStringParameter(
387:                        "chart-type", ""); //$NON-NLS-1$ //$NON-NLS-2$
388:                if (ChartDefinition.PIE_CHART_STR.equals(chartTypeStr)) {
389:                    doPieChart(solutionName, actionPath, actionName,
390:                            parameterProvider, outputStream, userSession);
391:                } else {
392:                    doOtherChart(solutionName, actionPath, actionName,
393:                            parameterProvider, outputStream, userSession);
394:                }
395:            }
396:
397:            private void doPieChart(String solutionName, String actionPath,
398:                    String actionName, IParameterProvider parameterProvider,
399:                    OutputStream outputStream, IPentahoSession userSession) {
400:
401:                ArrayList messages = new ArrayList();
402:                StringBuffer buffer = new StringBuffer();
403:                boolean ok = ChartHelper.doPieChart(solutionName, actionPath,
404:                        actionName, parameterProvider, buffer, userSession,
405:                        messages, this );
406:                if (!ok) {
407:                    UIUtil
408:                            .formatErrorMessage(
409:                                    "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
410:                }
411:
412:                try {
413:                    writeStringAsSoapResponse(outputStream, buffer.toString());
414:                } catch (IOException e) {
415:                    // not much we can do here...
416:                }
417:
418:                /*
419:                 String outerParams = parameterProvider.getStringParameter("outer-params", null); //$NON-NLS-1$
420:                 String innerParam = parameterProvider.getStringParameter("inner-param", null); //$NON-NLS-1$
421:
422:                 String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$
423:                 String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$
424:                 if (imageUrl == null) {
425:                 imageUrl = PentahoSystem.getApplicationContext().getBaseUrl();
426:                 }
427:
428:                 if (urlDrillTemplate == null) {
429:                 urlDrillTemplate = ""; //$NON-NLS-1$
430:                 }
431:
432:                 SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate);
433:
434:                 PieDatasetChartComponent chartComponent = null;
435:                 try {
436:                 ArrayList messages = new ArrayList();
437:                 String chartDefinitionStr = solutionName + File.separator + actionPath + File.separator + actionName;
438:                 chartComponent = new PieDatasetChartComponent(chartDefinitionStr, urlFactory, messages); //$NON-NLS-1$
439:                 chartComponent.setUrlTemplate(urlDrillTemplate);
440:                 if (outerParams != null) {
441:                 StringTokenizer tokenizer = new StringTokenizer(outerParams, ";"); //$NON-NLS-1$
442:                 while (tokenizer.hasMoreTokens()) {
443:                 chartComponent.addOuterParamName(tokenizer.nextToken());
444:                 }
445:                 }
446:                 chartComponent.setParamName(innerParam);
447:
448:                 chartComponent.setDataAction(chartDefinitionStr);
449:                 chartComponent.validate(userSession, null);
450:
451:                 chartComponent.setParameterProvider("request", parameterProvider); //$NON-NLS-1$
452:
453:                 String content = chartComponent.getContent("text/html"); //$NON-NLS-1$
454:
455:                 if (content == null || content.equals("")) { //$NON-NLS-1$
456:                 content = "&nbsp;"; //$NON-NLS-1$
457:                 }
458:                 if (content == null) {
459:                 StringBuffer buffer = new StringBuffer();
460:                 UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
461:                 content = buffer.toString();
462:                 }
463:
464:                 try {
465:                 outputStream.write(SoapUtil.getSoapHeader().getBytes(LocaleHelper.getSystemEncoding()));
466:                 outputStream.write(SoapUtil.openSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
467:                 outputStream.write("<content><![CDATA[".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
468:                 outputStream.write(content.getBytes(LocaleHelper.getSystemEncoding()));
469:                 outputStream.write("]]></content>".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
470:                 outputStream.write(SoapUtil.closeSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
471:                 outputStream.write(SoapUtil.getSoapFooter().getBytes(LocaleHelper.getSystemEncoding()));
472:                 } catch (IOException e) {
473:                 // not much we acn do here...
474:                 }
475:                 } finally {
476:                 if (chartComponent != null)
477:                 chartComponent.dispose();
478:                 }
479:                 */
480:            }
481:
482:            private void doOtherChart(String solutionName, String actionPath,
483:                    String actionName, IParameterProvider parameterProvider,
484:                    OutputStream outputStream, IPentahoSession userSession) {
485:
486:                ArrayList messages = new ArrayList();
487:                StringBuffer buffer = new StringBuffer();
488:                boolean ok = ChartHelper.doChart(solutionName, actionPath,
489:                        actionName, parameterProvider, buffer, userSession,
490:                        messages, this );
491:                if (!ok) {
492:                    UIUtil
493:                            .formatErrorMessage(
494:                                    "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
495:                }
496:
497:                try {
498:                    writeStringAsSoapResponse(outputStream, buffer.toString());
499:                } catch (IOException e) {
500:                    // not much we can do here...
501:                }
502:
503:                /*
504:                 String outerParams = parameterProvider.getStringParameter("outer-params", null); //$NON-NLS-1$
505:                 String innerParam = parameterProvider.getStringParameter("inner-param", null); //$NON-NLS-1$
506:
507:                 String urlDrillTemplate = parameterProvider.getStringParameter("drill-url", null); //$NON-NLS-1$
508:                 String imageUrl = parameterProvider.getStringParameter("image-url", null); //$NON-NLS-1$
509:                 if (imageUrl == null) {
510:                 imageUrl = PentahoSystem.getApplicationContext().getBaseUrl();
511:                 }
512:
513:                 if (urlDrillTemplate == null) {
514:                 urlDrillTemplate = ""; //$NON-NLS-1$
515:                 }
516:
517:                 int width = (int) parameterProvider.getLongParameter("image-width", 150); //$NON-NLS-1$
518:                 int height = (int) parameterProvider.getLongParameter("image-height", 150); //$NON-NLS-1$
519:
520:                 SimpleUrlFactory urlFactory = new SimpleUrlFactory(urlDrillTemplate);
521:
522:                 CategoryDatasetChartComponent chartComponent = null;
523:                 try {
524:                 String content = null;
525:                 ArrayList messages = new ArrayList();
526:                 try {
527:                 String chartDefinitionStr = solutionName + File.separator + actionPath + File.separator + actionName;
528:                 String chartTypeStr = parameterProvider.getStringParameter("chart-type", null); //$NON-NLS-1$
529:                 int chartType = CategoryDatasetChartDefinition.getChartType(chartTypeStr);
530:                 chartComponent = new CategoryDatasetChartComponent(chartType, chartDefinitionStr, width, height, urlFactory, messages); //$NON-NLS-1$
531:
532:                 String connectionName = parameterProvider.getStringParameter("connection", null); //$NON-NLS-1$
533:                 String query = parameterProvider.getStringParameter("query", null); //$NON-NLS-1$
534:                 String dataAction = parameterProvider.getStringParameter("data-process", null); //$NON-NLS-1$
535:                 IPentahoConnection connection = null; //$NON-NLS-1$
536:                 try {
537:                 if (connectionName != null && query != null) {
538:                 connection = new SQLConnection(connectionName, this); //$NON-NLS-1$ 
539:                 try {
540:                 query = TemplateUtil.applyTemplate(query, TemplateUtil.parametersToProperties(parameterProvider));
541:                 IPentahoResultSet results = connection.executeQuery(query);
542:                 chartComponent.setValues(results);
543:                 } finally {
544:                 }
545:                 chartComponent.setUrlTemplate(urlDrillTemplate);
546:                 if (outerParams != null) {
547:                 StringTokenizer tokenizer = new StringTokenizer(outerParams, ";"); //$NON-NLS-1$
548:                 while (tokenizer.hasMoreTokens()) {
549:                 chartComponent.addOuterParamName(tokenizer.nextToken());
550:                 }
551:                 }
552:
553:                 chartComponent.setParamName(innerParam);
554:
555:                 chartComponent.setDataAction(chartDefinitionStr);
556:                 chartComponent.validate(userSession, null);
557:
558:                 chartComponent.setParameterProvider("request", parameterProvider); //$NON-NLS-1$
559:
560:                 content = chartComponent.getContent("text/html"); //$NON-NLS-1$
561:                 } else if (dataAction != null) {
562:                 String actionInfo[] = PentahoSystem.parseActionString(dataAction);
563:                 if (actionInfo != null && actionInfo.length == 3) {
564:                 chartComponent.setDataAction(actionInfo[0], actionInfo[1], actionInfo[2], "rule-result"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
565:                 }
566:                 } else {
567:                 error("'query' and 'connection' must be specified");
568:                 }
569:
570:                 } finally {
571:                 if (connection != null) {
572:                 connection.close();
573:                 }
574:                 }
575:
576:                 // String query = "select department, actual, budget, variance
577:                 // from quadrant_actuals"; //$NON-NLS-1$
578:
579:                 } catch (Exception e) {
580:                 // not much we can do here...
581:                 }
582:                 try {
583:                 if (content == null) {
584:                 StringBuffer buffer = new StringBuffer();
585:                 UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
586:                 content = buffer.toString();
587:                 }
588:                 outputStream.write(SoapUtil.getSoapHeader().getBytes(LocaleHelper.getSystemEncoding()));
589:                 outputStream.write(SoapUtil.openSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
590:                 outputStream.write("<content><![CDATA[".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
591:                 outputStream.write(content.getBytes(LocaleHelper.getSystemEncoding()));
592:                 outputStream.write("]]></content>".getBytes(LocaleHelper.getSystemEncoding())); //$NON-NLS-1$
593:                 outputStream.write(SoapUtil.closeSoapResponse().getBytes(LocaleHelper.getSystemEncoding()));
594:                 outputStream.write(SoapUtil.getSoapFooter().getBytes(LocaleHelper.getSystemEncoding()));
595:                 } catch (Exception e) {
596:
597:                 }
598:                 } finally {
599:                 if (chartComponent != null)
600:                 chartComponent.dispose();
601:                 }
602:                 */
603:            }
604:
605:            //
606:            // FIXME: Copied straight from something else - make this nice
607:            //
608:            /**
609:             * <ol>
610:             * <li>Make sure this request has required parameters either on query
611:             * string or in body of post.</li>
612:             * <li>Make calls into <code>UserDetailsRoleListService</code> instance
613:             * for users and roles.</li>
614:             * <li>Make static call into <code>PentahoAclEntry</code> for ACLs.</li>
615:             * <li>Construct SOAP response.</li>
616:             * </ol>
617:             */
618:            public void doGet(HttpServletRequest request,
619:                    HttpServletResponse response) throws ServletException,
620:                    IOException {
621:
622:                if (!isSecurityDetailsRequest(request)) {
623:                    if (logger.isDebugEnabled()) {
624:                        logger
625:                                .debug(Messages
626:                                        .getString("HttpWebService.DEBUG_MISSING_ACTION_PARAMETER")); //$NON-NLS-1$
627:                    }
628:                    doGetFixMe(request, response);
629:                    return;
630:                }
631:
632:                response.setContentType("text/xml"); //$NON-NLS-1$
633:                response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
634:
635:                String details = getDetailsParameter(request);
636:                if ("users".equalsIgnoreCase(details)) { //$NON-NLS-1$
637:
638:                    // Send users and ACLs
639:                    StringBuffer buf = new StringBuffer();
640:                    doUsers(request, response, buf);
641:                    doACLs(request, response, buf);
642:                    writeStringAsSoapResponse(response.getOutputStream(), buf
643:                            .toString());
644:
645:                } else if ("roles".equalsIgnoreCase(details)) { //$NON-NLS-1$
646:
647:                    // Send roles and ACLs
648:                    StringBuffer buf = new StringBuffer();
649:                    doRoles(request, response, buf);
650:                    doACLs(request, response, buf);
651:                    writeStringAsSoapResponse(response.getOutputStream(), buf
652:                            .toString());
653:
654:                } else if ("acls".equalsIgnoreCase(details)) { //$NON-NLS-1$
655:                    StringBuffer buf = new StringBuffer();
656:                    doACLs(request, response, buf);
657:                    writeStringAsSoapResponse(response.getOutputStream(), buf
658:                            .toString());
659:
660:                } else {
661:
662:                    if (!"all".equalsIgnoreCase(details)) { //$NON-NLS-1$
663:                        if (logger.isWarnEnabled()) {
664:                            logger
665:                                    .warn(Messages
666:                                            .getString("HttpWebService.WARN_MISSING_DETAILS_PARAMETER")); //$NON-NLS-1$
667:                        }
668:                    }
669:                    StringBuffer buf = new StringBuffer();
670:                    doAll(request, response, buf);
671:                    writeStringAsSoapResponse(response.getOutputStream(), buf
672:                            .toString());
673:
674:                }
675:            }
676:
677:            /**
678:             * Returns true if the required parameter is either in the query string or
679:             * body.
680:             */
681:            protected boolean isSecurityDetailsRequest(
682:                    final HttpServletRequest request) {
683:                return hasActionInQueryString(request)
684:                        || hasActionInBody(request);
685:            }
686:
687:            /**
688:             * Returns parameter named <code>details</code> either from query string
689:             * or body. This parameter specifies how much information the caller wants
690:             * returned.
691:             */
692:            protected String getDetailsParameter(
693:                    final HttpServletRequest request) {
694:                // check query string first
695:                String details = request.getParameter("details"); //$NON-NLS-1$
696:                if (null != details) {
697:                    return details;
698:                }
699:
700:                // now check body
701:                String payload;
702:                try {
703:                    payload = getPayloadAsString(request);
704:                } catch (IOException e) {
705:                    if (logger.isErrorEnabled()) {
706:                        logger.error(e);
707:                    }
708:                    return null;
709:                }
710:                if (null != payload && payload.length() > 0) {
711:                    Map parameters = getParameterMapFromPayload(payload);
712:                    Object obj = parameters.get("details"); //$NON-NLS-1$
713:                    if (null != obj) {
714:                        return obj.toString();
715:                    }
716:                }
717:                return null;
718:            }
719:
720:            /**
721:             * Returns true if required parameter is in body of request.
722:             */
723:            protected boolean hasActionInBody(final HttpServletRequest request) {
724:                String payload;
725:                try {
726:                    payload = getPayloadAsString(request);
727:                } catch (IOException e) {
728:                    if (logger.isErrorEnabled()) {
729:                        logger.error(e);
730:                    }
731:                    return false;
732:                }
733:                if (null != payload && payload.length() > 0) {
734:                    Map parameters = getParameterMapFromPayload(payload);
735:                    Object obj = parameters.get("action"); //$NON-NLS-1$
736:                    if (null != obj
737:                            && obj.toString().equalsIgnoreCase(
738:                                    "securitydetails")) { //$NON-NLS-1$
739:                        return true;
740:                    }
741:
742:                }
743:                return false;
744:            }
745:
746:            /**
747:             * Returns true if required parameter named <code>action</code> is in
748:             * query string.
749:             */
750:            protected boolean hasActionInQueryString(
751:                    final HttpServletRequest request) {
752:                String action = request.getParameter("action"); //$NON-NLS-1$
753:                if (("securitydetails").equalsIgnoreCase(action)) { //$NON-NLS-1$
754:                    return true;
755:                } else {
756:                    return false;
757:                }
758:            }
759:
760:            protected Map getParameterMapFromPayload(final String xml) {
761:                Document doc = XmlHelper.getDocFromString(xml);
762:                Map parameters = new HashMap();
763:                List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*"); //$NON-NLS-1$
764:                for (int i = 0; i < parameterNodes.size(); i++) {
765:                    Node parameterNode = (Node) parameterNodes.get(i);
766:                    String parameterName = parameterNode.getName();
767:                    String parameterValue = parameterNode.getText();
768:                    parameters.put(parameterName, parameterValue);
769:                }
770:                return parameters;
771:            }
772:
773:            /**
774:             * Returns XML for lists of users, roles, and ACLs.
775:             */
776:            protected void doAll(HttpServletRequest request,
777:                    HttpServletResponse response, StringBuffer buf)
778:                    throws ServletException, IOException {
779:                doUsers(request, response, buf);
780:                doRoles(request, response, buf);
781:                doACLs(request, response, buf);
782:            }
783:
784:            /**
785:             * Returns XML for list of users.
786:             */
787:            protected void doUsers(HttpServletRequest request,
788:                    HttpServletResponse response, StringBuffer buf)
789:                    throws ServletException, IOException {
790:                UserDetailsRoleListService service = PentahoSystem
791:                        .getUserDetailsRoleListService();
792:                buf.append("<users>"); //$NON-NLS-1$
793:                if (service != null) {
794:                    List users = service.getAllUsers();
795:                    for (Iterator usersIterator = users.iterator(); usersIterator
796:                            .hasNext();) {
797:                        String username = usersIterator.next().toString();
798:                        if (null != username && username.length() > 0) {
799:                            buf.append("<user>" + username + "</user>"); //$NON-NLS-1$ //$NON-NLS-2$
800:                        }
801:                    }
802:                }
803:                buf.append("</users>"); //$NON-NLS-1$
804:            }
805:
806:            /**
807:             * Returns XML for list of roles.
808:             */
809:            protected void doRoles(HttpServletRequest request,
810:                    HttpServletResponse response, StringBuffer buf)
811:                    throws ServletException, IOException {
812:                UserDetailsRoleListService service = PentahoSystem
813:                        .getUserDetailsRoleListService();
814:                buf.append("<roles>"); //$NON-NLS-1$
815:                if (service != null) {
816:                    List roles = service.getAllRoles();
817:                    for (Iterator rolesIterator = roles.iterator(); rolesIterator
818:                            .hasNext();) {
819:                        String roleName = rolesIterator.next().toString();
820:                        if (null != roleName && roleName.length() > 0) {
821:                            buf.append("<role>" + roleName + "</role>"); //$NON-NLS-1$ //$NON-NLS-2$
822:                        }
823:                    }
824:                }
825:                buf.append("</roles>"); //$NON-NLS-1$
826:            }
827:
828:            /**
829:             * Returns XML for list of ACLs.
830:             */
831:            protected void doACLs(HttpServletRequest request,
832:                    HttpServletResponse response, StringBuffer buf)
833:                    throws ServletException, IOException {
834:                Map validPermissionsNameMap = PentahoAclEntry
835:                        .getValidPermissionsNameMap(PentahoAclEntry.PERMISSIONS_LIST_ALL);
836:                buf.append("<acls>"); //$NON-NLS-1$
837:                if (validPermissionsNameMap != null) {
838:                    Set aclsKeySet = validPermissionsNameMap.keySet();
839:                    for (Iterator aclsIterator = aclsKeySet.iterator(); aclsIterator
840:                            .hasNext();) {
841:                        String aclName = aclsIterator.next().toString();
842:                        String aclMask = null != validPermissionsNameMap
843:                                .get(aclName) ? validPermissionsNameMap.get(
844:                                aclName).toString() : null;
845:
846:                        if (null != aclName && aclName.length() > 0
847:                                && null != aclMask && aclMask.length() > 0) {
848:                            buf.append("<acl>"); //$NON-NLS-1$
849:                            buf.append("<name>"); //$NON-NLS-1$
850:                            buf.append(aclName);
851:                            buf.append("</name>"); //$NON-NLS-1$
852:                            buf.append("<mask>"); //$NON-NLS-1$
853:                            buf.append(aclMask);
854:                            buf.append("</mask>"); //$NON-NLS-1$
855:                            buf.append("</acl>"); //$NON-NLS-1$
856:                        }
857:
858:                    }
859:                }
860:                buf.append("</acls>"); //$NON-NLS-1$
861:            }
862:
863:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.