Source Code Cross Referenced for TestServlet.java in  » Portal » Open-Portal » com » sun » portal » wsrp » producer » test » 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 » Portal » Open Portal » com.sun.portal.wsrp.producer.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Copyright 2003 Sun Microsystems, Inc. All
003:         * rights reserved. Use of this product is subject
004:         * to license terms. Federal Acquisitions:
005:         * Commercial Software -- Government Users
006:         * Subject to Standard License Terms and
007:         * Conditions.
008:         *
009:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010:         * are trademarks or registered trademarks of Sun Microsystems,
011:         * Inc. in the United States and other countries.
012:         */package com.sun.portal.wsrp.producer.test;
013:
014:        import java.util.Set;
015:        import java.util.Iterator;
016:        import java.util.HashSet;
017:        import java.util.StringTokenizer;
018:        import java.util.Locale;
019:        import java.util.logging.Level;
020:        import java.util.logging.Logger;
021:
022:        import java.io.PrintWriter;
023:
024:        import javax.servlet.ServletException;
025:        import javax.servlet.ServletRequest;
026:        import javax.servlet.ServletContext;
027:
028:        import javax.servlet.http.HttpServlet;
029:        import javax.servlet.http.HttpServletRequest;
030:        import javax.servlet.http.HttpServletResponse;
031:
032:        import com.iplanet.sso.SSOToken;
033:
034:        import com.sun.identity.sm.ServiceListener;
035:
036:        import com.iplanet.am.util.Debug;
037:
038:        import com.sun.portal.providers.context.ProviderContext;
039:
040:        import com.sun.portal.desktop.dp.DPRoot;
041:
042:        import com.sun.portal.wsrp.producer.Producer;
043:        import com.sun.portal.wsrp.producer.ISConnection;
044:        import com.sun.portal.wsrp.producer.ISConstants;
045:        import com.sun.portal.wsrp.producer.ProducerRegistryManager;
046:        import com.sun.portal.wsrp.producer.DPConnection;
047:
048:        import com.sun.portal.wsrp.producer.impl.ProducerImpl;
049:
050:        import com.sun.portal.wsrp.producer.filter.ProducerThreadLocalizer;
051:
052:        import com.sun.portal.wsrp.producer.servicedescription.ServiceDescriptionManager;
053:
054:        import com.sun.portal.wsrp.producer.registration.RegistrationManager;
055:        import com.sun.portal.wsrp.producer.registration.RegistrationRecord;
056:
057:        import com.sun.portal.wsrp.producer.UserManager;
058:
059:        import com.sun.portal.wsrp.producer.registration.validator.RegistrationValidator;
060:
061:        import com.sun.portal.wsrp.common.stubs.ServiceDescription;
062:        import com.sun.portal.wsrp.common.stubs.PropertyDescription;
063:        import com.sun.portal.wsrp.common.stubs.LocalizedString;
064:        import com.sun.portal.wsrp.common.stubs.RegistrationContext;
065:        import com.sun.portal.wsrp.common.stubs.RegistrationData;
066:        import com.sun.portal.wsrp.common.stubs.ModifyRegistration;
067:        import com.sun.portal.wsrp.common.stubs.Property;
068:
069:        import com.sun.portal.wsrp.common.WSRPFactory;
070:        import com.sun.portal.log.common.PortalLogger;
071:
072:        public class TestServlet extends HttpServlet implements  ISConstants,
073:                ServiceListener {
074:            private static Logger logger = PortalLogger
075:                    .getLogger(TestServlet.class);
076:
077:            protected void doGet(HttpServletRequest req, HttpServletResponse res)
078:                    throws ServletException, java.io.IOException {
079:                res.setContentType("text/plain");
080:                PrintWriter out = res.getWriter();
081:
082:                try {
083:                    SSOToken adminToken = ISConnection.getAdminToken();
084:                    ProducerRegistryManager registry = ProducerRegistryManager
085:                            .getRegistryManager();
086:                    ServletContext ctx = ProducerThreadLocalizer.getContext();
087:
088:                    String test = req.getParameter("test");
089:                    if (test == null) {
090:                        out.println("please specify test to run");
091:                    } else if (test.equals("tl.get")) {
092:                        ServletRequest sreq = ProducerThreadLocalizer
093:                                .getRequest();
094:                        out.println("sreq=" + sreq);
095:                    } else if (test.equals("registry.getkeys")) {
096:                        //
097:                        // producer registry tests
098:                        //
099:                        Set keys = registry.getKeys();
100:                        out.println(keys);
101:                    } else if (test.equals("registry.remove")) {
102:                        String key = req.getParameter("registry.key");
103:                        registry.remove(key);
104:                        out.println("producer registry producer key=" + key
105:                                + " removed");
106:                    } else if (test.equals("registry.add")) {
107:                        String key = req.getParameter("registry.key");
108:                        String org = req.getParameter("registry.org");
109:                        String instance = req.getParameter("registry.instance");
110:                        registry.add(key, org, instance);
111:                    } else if (test.equals("registry.getxml")) {
112:                        String s = registry.getXML();
113:                        out.println(s);
114:                    } else if (test.equals("usermanager.getprovidercontext")) {
115:                        //
116:                        // user manager tests
117:                        //
118:                        String userContextKey = req
119:                                .getParameter("usermanager.usercontextkey");
120:                        String producerKey = req
121:                                .getParameter("usermanager.producerkey");
122:                        String consumerName = req
123:                                .getParameter("usermanager.consumername");
124:                        String expiresString = req
125:                                .getParameter("usermanager.expires");
126:                        if (expiresString == null) {
127:                            expiresString = "300";
128:                        }
129:                        int expires = Integer.parseInt(expiresString);
130:                        UserManager um = new UserManager(getServletConfig()
131:                                .getServletContext(), req, adminToken,
132:                                producerKey, consumerName);
133:                        ProviderContext pc = um.getProviderContext(
134:                                userContextKey, expires);
135:                        if (pc == null) {
136:                            out
137:                                    .println("could not get provider context for userContextKey="
138:                                            + userContextKey
139:                                            + ", producerKey="
140:                                            + producerKey
141:                                            + ", consumerName="
142:                                            + consumerName);
143:                        } else {
144:                            out
145:                                    .println("got provider context for userContextKey="
146:                                            + userContextKey
147:                                            + ", producerKey="
148:                                            + producerKey
149:                                            + ", consumerName="
150:                                            + consumerName);
151:                            out.println("userID=" + pc.getUserID());
152:                            out.println("sessionID=" + pc.getSessionID());
153:                        }
154:
155:                        String key = req.getParameter("usermanager.cpkey");
156:                        String val = req.getParameter("usermanager.cpval");
157:
158:                        if (key != null) {
159:                            if (val == null) {
160:                                String v = pc.getClientProperty(key);
161:                                out.println("GOT client property key=" + key
162:                                        + ", value=" + v);
163:                            } else {
164:                                pc.setClientProperty(key, val);
165:                                out.println("SET client property key=" + key
166:                                        + ", value=" + val);
167:                            }
168:                        }
169:
170:                        um.store(userContextKey);
171:                    } else if (test.equals("sd.get")) {
172:                        //
173:                        // service description manager tests
174:                        //
175:                        String key = req.getParameter("sd.key");
176:                        String m = req.getParameter("sd.min");
177:                        boolean min = new Boolean(m).booleanValue();
178:
179:                        Producer producer = new ProducerImpl(req, ctx,
180:                                adminToken, key);
181:                        ServiceDescriptionManager sdm = producer
182:                                .getServiceDescriptionManager();
183:                        ServiceDescription sd = sdm.getServiceDescription(null,
184:                                min);
185:                        out.println(WSRPFactory.getInstance()
186:                                .getServiceDescriptionXML(sd, true));
187:                    } else if (test.equals("sd.getopnames")) {
188:                        String key = req.getParameter("sd.key");
189:                        Producer producer = new ProducerImpl(req, ctx,
190:                                adminToken, key);
191:                        ServiceDescriptionManager sdm = producer
192:                                .getServiceDescriptionManager();
193:
194:                        Set opNames = sdm.getOfferedPortletNames();
195:                        out.println("opNames=" + opNames);
196:                    } else if (test.equals("sd.setopnames")) {
197:                        String key = req.getParameter("sd.key");
198:                        String names = req.getParameter("sd.names");
199:                        Set opNames = parseURLParameterList(names);
200:                        out.println("opNames=" + opNames);
201:
202:                        Producer producer = new ProducerImpl(req, ctx,
203:                                adminToken, key);
204:                        ServiceDescriptionManager sdm = producer
205:                                .getServiceDescriptionManager();
206:                        sdm.setOfferedPortletNames(opNames);
207:                    } else if (test.equals("sd.addrpd")) {
208:                        String key = req.getParameter("sd.key");
209:                        String name = req.getParameter("sd.rpdname");
210:                        String lang = req.getParameter("sd.lang");
211:                        if (lang == null) {
212:                            lang = Locale.getDefault().toString().replace('_',
213:                                    '-');
214:                        }
215:
216:                        javax.xml.namespace.QName type = new javax.xml.namespace.QName(
217:                                req.getParameter("sd.rpdtype"));
218:                        LocalizedString label = new LocalizedString(lang, name,
219:                                "aLabel");
220:                        LocalizedString hint = new LocalizedString(lang, name,
221:                                "aHint");
222:
223:                        PropertyDescription pd = new PropertyDescription(name,
224:                                type, label, hint, null);
225:
226:                        Producer producer = new ProducerImpl(req, ctx,
227:                                adminToken, key);
228:                        ServiceDescriptionManager sdm = producer
229:                                .getServiceDescriptionManager();
230:                        sdm.addRegistrationPropertyDescription(pd);
231:                    } else if (test.equals("dp.get")) {
232:                        //
233:                        // display profile tests
234:                        //
235:                        String org = req.getParameter("dp.org");
236:                        DPConnection dpc = new DPConnection(req);
237:                        DPRoot dpr = dpc.getDPRoot(org);
238:                        out.println(dpr.toDebugString());
239:                    } else if (test.equals("producer.getpch")) {
240:                        //
241:                        // producer tests
242:                        //
243:                        String key = req.getParameter("producer.key");
244:                        Producer producer = new ProducerImpl(req, ctx,
245:                                adminToken, key);
246:                        Set portletChannelNames = producer
247:                                .getPortletChannelNames();
248:                        out.println("portletChannelNames="
249:                                + portletChannelNames);
250:                    } else if (test.equals("reg.add")) {
251:                        //
252:                        // registration manager tests
253:                        //
254:                        String key = req.getParameter("reg.key");
255:                        String name = req.getParameter("reg.name");
256:                        String agent = req.getParameter("reg.agent");
257:
258:                        Producer producer = new ProducerImpl(req, ctx,
259:                                adminToken, key);
260:
261:                        RegistrationManager rm = producer
262:                                .getRegistrationManager();
263:
264:                        RegistrationData rd = getRegistrationData(name, agent);
265:                        String rdXML = WSRPFactory.getInstance()
266:                                .getRegistrationDataXML(rd, true);
267:                        out.println("rd=\n" + rdXML);
268:
269:                        RegistrationContext rc = rm.register(rd);
270:
271:                        String rcXML = WSRPFactory.getInstance()
272:                                .getRegistrationContextXML(rc, true);
273:                        out.println("rc=\n" + rcXML);
274:                    } else if (test.equals("reg.delete")) {
275:                        String key = req.getParameter("reg.key");
276:                        String handle = req.getParameter("reg.handle");
277:
278:                        RegistrationContext rc = new RegistrationContext(
279:                                handle, null, null);
280:                        Producer producer = new ProducerImpl(req, ctx,
281:                                adminToken, key);
282:                        RegistrationManager rm = producer
283:                                .getRegistrationManager();
284:                        rm.deregister(rc);
285:
286:                        out.println("handle=" + handle + ", deregistered");
287:                    } else if (test.equals("reg.modify")) {
288:                        String key = req.getParameter("reg.key");
289:                        String handle = req.getParameter("reg.handle");
290:                        String name = req.getParameter("reg.name");
291:                        String agent = req.getParameter("reg.agent");
292:
293:                        Producer producer = new ProducerImpl(req, ctx,
294:                                adminToken, key);
295:                        RegistrationManager rm = producer
296:                                .getRegistrationManager();
297:
298:                        RegistrationData rd = getRegistrationData(name, agent);
299:                        String rdXML = WSRPFactory.getInstance()
300:                                .getRegistrationDataXML(rd, true);
301:                        out.println("rd=\n" + rdXML);
302:
303:                        RegistrationContext rc = new RegistrationContext(
304:                                handle, null, null);
305:                        ModifyRegistration mr = new ModifyRegistration(rc, rd);
306:                        rm.modifyRegistration(mr);
307:                    } else if (test.equals("reg.getall")) {
308:                        String key = req.getParameter("reg.key");
309:
310:                        Producer producer = new ProducerImpl(req, ctx,
311:                                adminToken, key);
312:                        RegistrationManager rm = producer
313:                                .getRegistrationManager();
314:
315:                        Set rrs = rm.getRegistrationRecords();
316:                        for (Iterator i = rrs.iterator(); i.hasNext();) {
317:                            RegistrationRecord rr = (RegistrationRecord) i
318:                                    .next();
319:                            out.println(rr);
320:                            out.println();
321:                        }
322:                    } else if (test.equals("reg.validate")) {
323:                        String key = req.getParameter("reg.key");
324:                        String handle = req.getParameter("reg.handle");
325:
326:                        Producer producer = new ProducerImpl(req, ctx,
327:                                adminToken, key);
328:                        RegistrationManager rm = producer
329:                                .getRegistrationManager();
330:                        ServiceDescriptionManager sdm = producer
331:                                .getServiceDescriptionManager();
332:
333:                        RegistrationRecord rr = rm
334:                                .getRegistrationRecord(handle);
335:                        RegistrationData rd = rr.getRegistrationData();
336:                        ServiceDescription sd = sdm.getServiceDescription(null);
337:
338:                        RegistrationValidator rv = rm
339:                                .getRegistrationValidator();
340:                        if (!(rv.validate(rd, sd) < 0)) {
341:                            out.println("handle=" + handle + " is valid");
342:                        } else {
343:                            out.println("handle=" + handle + " is not valid");
344:                        }
345:                    } else if (test.equals("sl")) {
346:                        ISConnection isConnection = new ISConnection(adminToken);
347:                        isConnection.addConfigListener(this );
348:                        if (logger.isLoggable(Level.SEVERE))
349:                            logger.log(Level.SEVERE, "PSWS_CSPWPT0001");
350:                    } else {
351:                        out.println("unknown test=" + test);
352:                    }
353:                } catch (Throwable t) {
354:                    t.printStackTrace(out);
355:                } finally {
356:                    out.close();
357:                }
358:            }
359:
360:            private static RegistrationData getRegistrationData(String name,
361:                    String agent) {
362:                String[] modes = new String[3];
363:                modes[0] = "wsrp:view";
364:                modes[1] = "wsrp:edit";
365:                modes[2] = "wsrp:help";
366:
367:                String[] userScopes = null;
368:                userScopes = new String[1];
369:                userScopes[0] = "wsrp:perUser";
370:
371:                Property[] properties = null;
372:                properties = new Property[0];
373:
374:                String[] customUserProfileData = null;
375:                //customUserProfileData = new String[0];
376:
377:                String[] windowStates = new String[3];
378:                windowStates[0] = "wsrp:normal";
379:                windowStates[1] = "wsrp:minimize";
380:                windowStates[2] = "wsrp:maximize";
381:
382:                RegistrationData rd = new RegistrationData(name, agent, false,
383:                        modes, windowStates, userScopes, customUserProfileData,
384:                        properties, null);
385:
386:                return rd;
387:            }
388:
389:            private static Set parseURLParameterList(String list) {
390:                StringTokenizer tok = new StringTokenizer(list, ",");
391:                Set set = new HashSet();
392:                while (tok.hasMoreTokens()) {
393:                    String element = tok.nextToken();
394:                    set.add(element);
395:                }
396:
397:                return set;
398:            }
399:
400:            public void schemaChanged(String serviceName, String version) {
401:                if (logger.isLoggable(Level.SEVERE))
402:                    logger.log(Level.SEVERE, "PSWS_CSPWPT0002", serviceName);
403:            }
404:
405:            public void globalConfigChanged(String serviceName, String version,
406:                    String groupName, String serviceComponent, int type) {
407:            }
408:
409:            public void organizationConfigChanged(String serviceName,
410:                    String version, String orgName, String groupName,
411:                    String serviceComponent, int type) {
412:            }
413:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.