Source Code Cross Referenced for ConvertGateway.java in  » Portal » Open-Portal » migration » modules » srap » erproxy » 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 » migration.modules.srap.erproxy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:        package migration.modules.srap.erproxy;
006:
007:        import javax.xml.parsers.*;
008:        import org.xml.sax.*;
009:        import org.xml.sax.helpers.*;
010:        import org.w3c.dom.*;
011:        import java.io.*;
012:        import java.util.*;
013:        import java.net.URL;
014:        import java.net.MalformedURLException;
015:
016:        public class ConvertGateway extends ConvertSRAP {
017:            public static final String COMPONENT = "Gateway : ";
018:            private String serverDomain;
019:            private String forwardCookieURL;
020:            private String portalServerUrl;
021:            private String portalServerHost;
022:
023:            public static void main(String args[]) {
024:                if (args.length < 10) {
025:                    System.out
026:                            .println("Usage : java ConvertGateway input-file output-file idsame-basedir report-file deploy_uri server_domain forward_cookie_url portal_server_url portal_server_host dsame_amserver_url");
027:                    System.exit(1);
028:                }
029:
030:                File file = new File(args[0]);
031:                if (!file.exists()) {
032:                    System.out
033:                            .println("Usage : java ConvertGateway input-file output-file idsame-basedir report-file deploy_uri server_domain forward_cookie_url portal_server_url portal_server_host dsame_amserver_url");
034:                    System.out.println("Specify a valid input-file.");
035:                    System.exit(1);
036:                }
037:
038:                ConvertGateway ConvertGW = new ConvertGateway(args[0], args[1],
039:                        args[2], args[3], args[4], args[5], args[6], args[7],
040:                        args[8], args[9]);
041:
042:                try {
043:                    ConvertGW.init();
044:                } catch (SRAPInitException ex) {
045:                    SRAPUtil
046:                            .writelog("Gateway conversion tool initialization failed"
047:                                    + "\n\tException : "
048:                                    + ex.toString()
049:                                    + "\n\n");
050:                    System.exit(1);
051:                }
052:
053:                try {
054:                    ConvertGW.convert();
055:                } catch (SRAPConvertException ex) {
056:                    SRAPUtil
057:                            .writelog("Gateway conversion tool conversion failed"
058:                                    + "\n\tException : "
059:                                    + ex.toString()
060:                                    + "\n\n");
061:                    System.exit(1);
062:                }
063:
064:                SRAPUtil
065:                        .writelog(COMPONENT
066:                                + "Conversion from iPS 3.0 to iPS 6.0 completed successfully at "
067:                                + SRAPUtil.getCurrentDateTime() + "\n\n");
068:
069:            }
070:
071:            public ConvertGateway(String infile, String outfile,
072:                    String idsameBasedir, String reportfile, String deployURI,
073:                    String serverDomain, String forwardCookieURL,
074:                    String portalServerUrl, String portalServerHost,
075:                    String dsameAmserver) {
076:
077:                super (infile, outfile, idsameBasedir, reportfile, COMPONENT);
078:                GatewayElements.DEPLOY_URI = deployURI;
079:                GatewayElements.IDSAME_AMSERVER = dsameAmserver;
080:                this .serverDomain = serverDomain;
081:                this .forwardCookieURL = forwardCookieURL;
082:                this .portalServerUrl = portalServerUrl;
083:                this .portalServerHost = portalServerHost;
084:            }
085:
086:            private boolean enableDOMWorkAround = false;
087:
088:            protected void createDocTypeNode() {
089:                enableDOMWorkAround = false;
090:                try {
091:                    DOMImplementation domImpl = destDocument
092:                            .getImplementation();
093:                    Node doc = domImpl
094:                            .createDocumentType(
095:                                    "ServicesConfiguration",
096:                                    "=//iPlanet//Service Management Services (SMS) 1.0 DTD//EN",
097:                                    "file:" + idsameBasedir
098:                                            + "/SUNWam/dtd/sms.dtd");
099:                    destDocument.appendChild(doc);
100:                } catch (Exception ex) {
101:                    enableDOMWorkAround = true;
102:                }
103:                /*
104:                DOMImplementation domImpl = destDocument.getImplementation();
105:                Node doc = domImpl.createDocumentType("Requests", "-//iPlanet//iDSAME 5.0 Admin CLI DTD//EN", "file://"+idsameBasedir+"/SUNWam/dtd/amAdmin.dtd");
106:                //doc = destDocument.importNode(doc , false);
107:                destDocument.appendChild(doc);
108:                 */
109:            }
110:
111:            protected void convert() throws SRAPConvertException {
112:                String eproxyProtocol = "https";
113:                String eproxyPort = "INST_EPROXY_PORT";
114:                String netletProxyPort = null;
115:
116:                ips3AttributeMappings = GatewayElements
117:                        .getIPS3AttributeMappings();
118:                ips6InstAttributes = GatewayElements.getIPS6InstAttributes();
119:                ips6NewInstAttributes = GatewayElements
120:                        .getIPS6NewInstAttributes();
121:
122:                createCommentNode();
123:                createDocTypeNode();
124:                Node ips6Root = createRootNode("Requests");
125:                Node ips6GWInstNode = buildDefualtGWInstNodes(ips6Root);
126:
127:                //Handle IPS 3.0 attributes
128:                SRAPNode[] srcNodes = getAllNodes(srcDocument, "iwt:Att");
129:                int len = srcNodes.length;
130:                for (int i = 0; i < len; i++) {
131:                    String attr = srcNodes[i].getAttributeValue("name");
132:                    if (attr != null) {
133:                        attr = attr.trim();
134:                        if (attr.equals("iwtGateway-EProxyProtocol")
135:                                && srcNodes[i].getChildNodes("Val").length > 0) {
136:                            eproxyProtocol = srcNodes[i].getChildNodes("Val")[0]
137:                                    .getValue();
138:                        } else if (attr.equals("iwtGateway-EProxyPort")
139:                                && srcNodes[i].getChildNodes("Val").length > 0) {
140:                            eproxyPort = srcNodes[i].getChildNodes("Val")[0]
141:                                    .getValue();
142:                        } else if (attr.equals("iwtGateway-netletproxy-port")
143:                                && srcNodes[i].getChildNodes("Val").length > 0) {
144:                            netletProxyPort = srcNodes[i].getChildNodes("Val")[0]
145:                                    .getValue();
146:                        } else {
147:                            if (ips3AttributeMappings.containsKey(attr)) {
148:                                ArrayList values = new ArrayList();
149:                                InstAttribute ips6InstAttr = (InstAttribute) ips6InstAttributes
150:                                        .get((Integer) ips3AttributeMappings
151:                                                .get(attr));
152:                                SRAPNode[] nodes = srcNodes[i]
153:                                        .getChildNodes("Val");
154:                                if (nodes != null) {
155:                                    int val = nodes.length;
156:                                    for (int j = 0; j < val; j++) {
157:                                        if (!nodes[j].getValue().trim().equals(
158:                                                ""))
159:                                            values.add(nodes[j].getValue());
160:                                    }
161:                                } else {
162:                                    values = ips6InstAttr.getValue();
163:                                }
164:                                if (attr
165:                                        .equals("iwtGateway-NonAuthenticatedURLPaths")) {
166:                                    Object[] vals = (ips6InstAttr.getValue()
167:                                            .toArray());
168:                                    int length = vals.length;
169:                                    for (int j = 0; j < length; j++) {
170:                                        if (!values.contains(vals[j])) {
171:                                            values.add(vals[j]);
172:                                        }
173:                                    }
174:                                } else if (attr
175:                                        .equals("iwtGateway-ForwardCookieURL")) {
176:                                    try {
177:                                        URL tmpUrl = new URL(forwardCookieURL);
178:                                        if ((tmpUrl.getPort() == 80 && tmpUrl
179:                                                .getProtocol()
180:                                                .equalsIgnoreCase("http"))
181:                                                || (tmpUrl.getPort() == 443 && tmpUrl
182:                                                        .getProtocol()
183:                                                        .equalsIgnoreCase(
184:                                                                "https"))) {
185:                                            String nonPortVersion = tmpUrl
186:                                                    .getProtocol()
187:                                                    + "://"
188:                                                    + tmpUrl.getHost()
189:                                                    + tmpUrl.getPath();
190:                                            if (!values
191:                                                    .contains(nonPortVersion)) {
192:                                                values.add(nonPortVersion);
193:                                            }
194:                                        }
195:                                    } catch (MalformedURLException exp) {
196:                                    }
197:
198:                                    if (!values.contains(forwardCookieURL)) {
199:                                        values.add(forwardCookieURL);
200:                                    }
201:                                } else if (attr
202:                                        .equals("iwtGateway-MimeTypeTranslatorClass")
203:                                        && nodes != null) {
204:                                    values = handleMimeTypeConversion(
205:                                            (ips6InstAttr.getValue().toArray()),
206:                                            values);
207:                                }
208:                                values.trimToSize();
209:                                if (values.size() > 0)
210:                                    buildGWInstNode(ips6GWInstNode,
211:                                            ips6InstAttr.getKey(), values);
212:                            }
213:                            //else Ignore IPS 3.0 obselete attibute(s)
214:                        }
215:                    }
216:                }
217:                //Handle IPS3.0 EProxy-Port & EProxy-Protocol attributes
218:                handleEProxyPortProtocolAttribute(ips6GWInstNode, eproxyPort,
219:                        eproxyProtocol);
220:
221:                // Netlet proxy is now a list and not a single port value.
222:                if (netletProxyPort != null) {
223:                    ArrayList tmpList = new ArrayList();
224:                    tmpList.add(portalServerHost + ":" + netletProxyPort);
225:                    tmpList.trimToSize();
226:                    buildGWInstNode(ips6GWInstNode,
227:                            "sunPortalGatewayNetletProxyHost", tmpList);
228:                }
229:
230:                //Handle new IPS 6.0 attributes
231:                int size = ips6NewInstAttributes.size();
232:                for (int i = 0; i < size; i++) {
233:                    InstAttribute attrib = (InstAttribute) ips6NewInstAttributes
234:                            .get(i);
235:                    if (attrib.getKey().equals(
236:                            "sunPortalGatewayDefaultDomainAndSubdomains"))
237:                        attrib.getValue().add(serverDomain);
238:                    else if (attrib.getKey().equals(
239:                            "sunPortalGatewayDomainsAndRulesets"))
240:                        attrib.getValue().add(
241:                                portalServerHost + "|default_gateway_ruleset");
242:                    else if (attrib.getKey().equals(
243:                            "sunPortalGatewayPortalServerList"))
244:                        attrib.getValue().add(portalServerUrl);
245:
246:                    buildGWInstNode(ips6GWInstNode, attrib.getKey(), attrib
247:                            .getValue());
248:                }
249:
250:                try {
251:                    FileOutputStream fos = new FileOutputStream(outfile);
252:                    if (enableDOMWorkAround) {
253:                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
254:                        SRAPUtil.serializeDOMTree(destDocument, baos);
255:                        String strContents = new String(baos.toByteArray(),
256:                                SRAPUtil.ENCODING);
257:                        int indx = strContents.indexOf('>');
258:                        // Insert Doctype immediately after the xml tag.
259:                        if (indx != -1) {
260:                            StringBuffer sb = new StringBuffer();
261:                            sb
262:                                    .append(strContents.substring(0, indx + 1))
263:                                    .append("\n<!DOCTYPE Requests\n")
264:                                    .append(
265:                                            "PUBLIC \"=//iPlanet//Service Management Services (SMS) 1.0 DTD//EN\"")
266:                                    .append(
267:                                            "\"file:"
268:                                                    + idsameBasedir
269:                                                    + "/SUNWam/dtd/amAdmin.dtd\">\n");
270:                            sb.append(strContents.substring(indx + 1));
271:                            strContents = sb.toString();
272:                        }
273:                        // Write strContents to fos
274:                        fos.write(strContents.getBytes(SRAPUtil.ENCODING));
275:                    } else {
276:                        SRAPUtil.serializeDOMTree(destDocument, fos);
277:                    }
278:                    fos.close();
279:                } catch (Exception ex) {
280:                    throw new SRAPConvertException(
281:                            "Could not serialize the iPS 6.0 document to the specified output file : "
282:                                    + outfile + "\n\tException : "
283:                                    + ex.toString());
284:                }
285:            }
286:
287:            private ArrayList handleMimeTypeConversion(Object defaultValues[],
288:                    ArrayList oldValues) {
289:                // Convert Old values to new values.
290:                HashMap newAttrMap = new HashMap();
291:                HashMap conversionMap = new HashMap();
292:                int index = 0;
293:
294:                // Everything to HTML as of now !!
295:                conversionMap
296:                        .put(
297:                                "com.iplanet.portalserver.gateway.connectionhandler.URLTranslator",
298:                                "HTML");
299:                conversionMap
300:                        .put(
301:                                "com.iplanet.portalserver.gateway.connectionhandler.HTMLTranslator",
302:                                "HTML");
303:                while (index < defaultValues.length) {
304:                    int tmpIndex = defaultValues[index].toString().indexOf('=');
305:                    newAttrMap.put(defaultValues[index].toString().substring(0,
306:                            tmpIndex).toUpperCase(), defaultValues[index]
307:                            .toString().substring(tmpIndex + 1).trim());
308:                    index++;
309:                }
310:                // Now iterate through the list of old entries.
311:                Iterator iter = oldValues.iterator();
312:                String value;
313:                String attribute;
314:                String newAttribute;
315:                String newValue;
316:                Object tmp;
317:                while (iter.hasNext()) {
318:                    attribute = iter.next().toString().trim();
319:                    index = attribute.indexOf('=');
320:                    if (index == -1) {
321:                        continue;
322:                    }
323:                    value = attribute.substring(index + 1).trim();
324:                    attribute = attribute.substring(0, index).trim();
325:                    tmp = conversionMap.get(attribute);
326:                    if (tmp == null) {
327:                        continue;
328:                    }
329:                    newAttribute = tmp.toString();
330:                    newValue = newAttrMap.get(newAttribute).toString();
331:                    StringBuffer mergedAttributeValue = new StringBuffer(
332:                            newValue);
333:                    StringTokenizer tok2 = new StringTokenizer(value);
334:                    while (tok2.hasMoreTokens()) {
335:                        String token = tok2.nextToken();
336:                        StringTokenizer tok1 = new StringTokenizer(newValue,
337:                                ";,", false);
338:                        boolean present = false;
339:                        while (tok1.hasMoreElements()) {
340:                            if (tok1.nextToken().equalsIgnoreCase(token)) {
341:                                present = true;
342:                                break;
343:                            }
344:                        }
345:                        if (!present) {
346:                            mergedAttributeValue.append(";").append(token);
347:                        }
348:                    }
349:                    newValue = mergedAttributeValue.toString();
350:                    newAttrMap.put(newAttribute, newValue);
351:                }
352:                ArrayList returnList = new ArrayList();
353:                Set keys = newAttrMap.keySet();
354:                Object keyArray[] = keys.toArray();
355:                index = 0;
356:                while (index < keyArray.length) {
357:                    returnList.add(keyArray[index].toString() + "="
358:                            + newAttrMap.get(keyArray[index]).toString());
359:                    index++;
360:                }
361:                return returnList;
362:            }
363:
364:            private void handleEProxyPortProtocolAttribute(Node parent,
365:                    String eproxyPort, String eproxyProtocol) {
366:                String enableHttps = "true";
367:                String enableHttp = "false";
368:                String httpPort = "80";
369:                String httpsPort = "INST_EPROXY_PORT";
370:
371:                if (eproxyProtocol.trim().equalsIgnoreCase("https")) {
372:                    httpsPort = eproxyPort;
373:                } else if (eproxyProtocol.trim().equalsIgnoreCase("http")) {
374:                    enableHttp = "true";
375:                    enableHttps = "false";
376:                    httpPort = eproxyPort;
377:                }
378:
379:                ArrayList list1 = new ArrayList();
380:                list1.add(enableHttp);
381:                list1.trimToSize();
382:                buildGWInstNode(parent, "sunPortalGatewayEProxyEnableHTTP",
383:                        list1);
384:
385:                ArrayList list2 = new ArrayList();
386:                list2.add(enableHttps);
387:                list2.trimToSize();
388:                buildGWInstNode(parent, "sunPortalGatewayEProxyEnableHTTPS",
389:                        list2);
390:
391:                ArrayList list3 = new ArrayList();
392:                list3.add(httpPort);
393:                list3.trimToSize();
394:                buildGWInstNode(parent, "sunPortalGatewayEProxyHTTPPort", list3);
395:
396:                ArrayList list4 = new ArrayList();
397:                list4.add(httpsPort);
398:                list4.trimToSize();
399:                buildGWInstNode(parent, "sunPortalGatewayEProxyHTTPSPort",
400:                        list4);
401:
402:            }
403:
404:            private Node buildDefualtGWInstNodes(Node parent) {
405:                ArrayList attribList = new ArrayList();
406:                //Create child
407:                attribList.add(SRAPUtil.getAttribute("serviceName",
408:                        "srapGatewayService"));
409:                attribList.trimToSize();
410:                Node child1 = createChildNode("ServiceConfigurationRequests",
411:                        attribList);
412:                parent.appendChild(child1);
413:                attribList.clear();
414:                //Create child
415:                attribList.add(SRAPUtil.getAttribute("subConfigName",
416:                        "/Gateway-Profiles/migrated"));
417:                attribList.add(SRAPUtil.getAttribute("subConfigId",
418:                        "One-Instance-Profile"));
419:                attribList.add(SRAPUtil.getAttribute("priority", "0"));
420:                attribList.trimToSize();
421:                Node child11 = createChildNode("AddSubConfiguration",
422:                        attribList);
423:                child1.appendChild(child11);
424:                attribList.clear();
425:                return child11;
426:            }
427:
428:            private void buildGWInstNode(Node parent, String name,
429:                    ArrayList values) {
430:
431:                ArrayList attribList = new ArrayList();
432:                Node child1 = createChildNode("AttributeValuePair", attribList);
433:                parent.appendChild(child1);
434:                attribList.add(SRAPUtil.getAttribute("name", name));
435:                attribList.trimToSize();
436:                Node child11 = createChildNode("Attribute", attribList);
437:                child1.appendChild(child11);
438:                attribList.clear();
439:
440:                int size = values.size();
441:                for (int i = 0; i < size; i++) {
442:                    Node child12 = createChildNode("Value", attribList);
443:                    Node child121 = destDocument.createTextNode((String) values
444:                            .get(i));
445:                    child1.appendChild(child12);
446:                    child12.appendChild(child121);
447:                }
448:            }
449:
450:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.