Source Code Cross Referenced for httpUPOC.java in  » ESB » cbesb-1.2 » packi » 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 » ESB » cbesb 1.2 » packi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package packi;
002:
003:        import java.io.InputStream;
004:        import java.net.HttpURLConnection;
005:        import java.net.MalformedURLException;
006:        import java.net.URL;
007:        import java.util.Calendar;
008:        import java.util.LinkedList;
009:        import java.util.Map;
010:
011:        import javax.jbi.component.ComponentContext;
012:        import javax.jbi.messaging.DeliveryChannel;
013:        import javax.jbi.messaging.MessageExchange;
014:        import javax.jbi.messaging.NormalizedMessage;
015:        import javax.swing.text.TabExpander;
016:        import javax.xml.transform.Source;
017:        import javax.xml.transform.dom.DOMSource;
018:        import javax.xml.transform.stream.StreamSource;
019:
020:        import org.apache.commons.logging.Log;
021:        import org.w3c.dom.Document;
022:        import org.w3c.dom.Element;
023:        import org.w3c.dom.Node;
024:
025:        import com.bostechcorp.cbesb.runtime.ccsl.lib.DumpNormalizedMessage;
026:        import com.bostechcorp.cbesb.runtime.ccsl.lib.IUpocInterface;
027:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.NormalizedMessageHandler;
028:        import com.bostechcorp.cbesb.runtime.ccsl.nmhandler.StringSource;
029:
030:        public class httpUPOC implements  IUpocInterface {
031:            /**
032:             * The httpPres is a Upoc method.
033:             * It returns a linked list of exchanges to be sent from the
034:             * endpoint.
035:             * @param logger - the loggger object
036:             * @param rootDir - the root direcory of the SU
037:             * @param componentContext - the componentContext object
038:             * @param channel - the delivery channel object
039:             * @param exchange - the MessageExchange object passed in
040:             * @param params - the user paramaters in name/value pair
041:             * @return - the LinkList containning one of many MessageExchange objects
042:             * @throws Exception
043:             */
044:
045:            public LinkedList httpPres(Log logger, String rootDir,
046:                    ComponentContext componentContext, DeliveryChannel channel,
047:                    MessageExchange exchange, Map<String, String> params)
048:                    throws Exception {
049:
050:                LinkedList<MessageExchange> sendList = new LinkedList<MessageExchange>();
051:                logger.debug("Running the beutiful Script :) ");
052:
053:                NormalizedMessage inMessage = exchange.getMessage("in");
054:                NormalizedMessageHandler nmh = new NormalizedMessageHandler(
055:                        inMessage);
056:
057:                Source content = nmh.getRecordAtIndex(0);
058:
059:                String zipCode = "";
060:
061:                //
062:                if (content instanceof  DOMSource) {
063:                    DOMSource domContent = (DOMSource) content;
064:                    Node node = domContent.getNode();
065:                    Element root = null;
066:                    if (node instanceof  Element) {
067:                        root = (Element) node;
068:                    } else {
069:                        root = ((Document) node).getDocumentElement();
070:                    }
071:
072:                    //                    Node zipNode = root.getFirstChild();
073:
074:                    //                    //getting the zip code
075:                    //                    System.out.println("ROOT Node"+root.getNodeName());
076:                    //                    Node message=root.getChildNodes().item(0);
077:                    //                    Node part=message.getChildNodes().item(0);
078:                    //                    Node dataEnvelope=part.getChildNodes().item(0);
079:                    //                    Node xmlRecord=dataEnvelope.getChildNodes().item(0);
080:                    //                    Node httpData=xmlRecord.getChildNodes().item(0);
081:
082:                    for (int i = 0; i < root.getChildNodes().getLength(); i++) {
083:                        Node child = root.getChildNodes().item(i);
084:                        logger.debug("Http data Nodes:" + child.getNodeName());
085:                        if (child.getNodeName().equals("zip")) {
086:                            zipCode = child.getNodeValue();
087:                            break;
088:                        }
089:                    }
090:
091:                    //asking yahoo info about zip code;
092:                    String zipcodeInfo = askYahooAboutZip(zipCode);
093:
094:                    // Doctor up the zip code info with today's date
095:                    Calendar today = Calendar.getInstance();
096:                    String todayString = "" + today.get(Calendar.YEAR) + "-"
097:                            + (today.get(Calendar.MONTH) + 1) + "-"
098:                            + today.get(Calendar.DAY_OF_MONTH);
099:                    zipcodeInfo = zipcodeInfo.replace("<Latitude",
100:                            "<DateToday>" + todayString
101:                                    + "</DateToday><Latitude");
102:
103:                    //update the message content
104:                    StringSource newStringSource = new StringSource(zipcodeInfo);
105:                    exchange.getMessage("in").setContent(null);
106:                    NormalizedMessageHandler nmh2 = new NormalizedMessageHandler(
107:                            exchange.getMessage("in"));
108:                    StreamSource newStreamSource = new StreamSource(
109:                            newStringSource.getInputStream());
110:                    nmh2.addRecord(newStreamSource);
111:                    nmh2.generateMessageContent();
112:                    logger.debug("\n\n\nNEW MESSAGE\n"
113:                            + DumpNormalizedMessage.dump(exchange
114:                                    .getMessage("in")) + "\n\n\n");
115:                } else {
116:                    logger.error("Impossible to get here");
117:                }
118:
119:                sendList.add(exchange);
120:                return sendList;
121:            }
122:
123:            private String askYahooAboutZip(String zipCode) throws Exception {
124:                URL url = new URL(
125:                        "http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&zip="
126:                                + zipCode);
127:                HttpURLConnection huc = (HttpURLConnection) url
128:                        .openConnection();
129:                huc.setRequestMethod("GET");
130:                huc.connect();
131:                InputStream is = huc.getInputStream();
132:                StringBuffer response = new StringBuffer();
133:                int code = huc.getResponseCode();
134:                System.out.print("Yahoo response is:" + code);
135:                if (code >= 200 && code < 300) {
136:                    int ch;
137:                    while ((ch = is.read()) > 0) {
138:                        //System.out.println((char)ch);
139:                        response.append((char) ch);
140:                    }
141:                    huc.disconnect();
142:                    return new String(response);
143:                }
144:
145:                return null;
146:            }
147:
148:            static int tabber = 0;
149:
150:            private void printAllNodes(Node root) {
151:                tabber++;
152:                if (root.getChildNodes() != null) {
153:                    org.w3c.dom.NodeList nodeList = root.getChildNodes();
154:                    for (int i = 0; i < nodeList.getLength(); i++) {
155:                        //Node child=nodeList.item(i);
156:                        //System.out.println("Child Node"+child.getNodeName());
157:                        printAllNodes(nodeList.item(i));
158:                    }
159:                } else {
160:                    String spaces = "";
161:                    for (int i = 0; i < tabber; i++) {
162:                        spaces += "-";
163:                    }
164:                    System.out.println("Node Name:" + spaces
165:                            + root.getNodeName());
166:                }
167:
168:            }
169:
170:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.