Source Code Cross Referenced for SoapClient.java in  » ESB » open-esb » jbidemo » 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 » open esb » jbidemo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)SoapClient.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package jbidemo;
030:
031:        import java.io.File;
032:        import java.io.FileInputStream;
033:        import java.io.FileOutputStream;
034:        import java.io.IOException;
035:        import java.util.Properties;
036:        import javax.xml.soap.MessageFactory;
037:        import javax.xml.soap.MimeHeaders;
038:        import javax.xml.soap.SOAPConnection;
039:        import javax.xml.soap.SOAPConnectionFactory;
040:        import javax.xml.soap.SOAPException;
041:        import javax.xml.soap.SOAPMessage;
042:        import javax.xml.soap.SOAPPart;
043:        import javax.xml.transform.Source;
044:        import javax.xml.transform.Transformer;
045:        import javax.xml.transform.TransformerConfigurationException;
046:        import javax.xml.transform.TransformerException;
047:        import javax.xml.transform.TransformerFactory;
048:        import javax.xml.transform.stream.StreamResult;
049:        import javax.xml.transform.stream.StreamSource;
050:
051:        public class SoapClient {
052:            /**
053:             * Test of inbound SOAP Request processing.
054:             */
055:            private static MessageFactory messageFactory;
056:            private static SOAPConnectionFactory soapConnFactory;
057:            private static SOAPConnection connection;
058:
059:            static {
060:                try {
061:                    messageFactory = MessageFactory.newInstance();
062:                    soapConnFactory = SOAPConnectionFactory.newInstance();
063:                    connection = soapConnFactory.createConnection();
064:                } catch (SOAPException ex) {
065:                    ex.printStackTrace();
066:                }
067:            }
068:
069:            public static void testInboundSOAPRequest(String propFilePath)
070:                    throws Exception {
071:                try {
072:                    FileInputStream fis = null;
073:                    Properties props = null;
074:                    try {
075:                        fis = new FileInputStream(new File(propFilePath));
076:                        props = new java.util.Properties();
077:                        props.load(fis);
078:                    } finally {
079:                        try {
080:                            if (fis != null) {
081:                                fis.close();
082:                            }
083:                        } catch (Exception ex) {
084:                            // ignore
085:                        }
086:                    }
087:
088:                    String soapAction = (String) props.get("soapaction");
089:                    String destination = (String) props.get("destination");
090:                    String inputFilePath = (String) props.get("input");
091:                    String outputFilePath = (String) props.get("output");
092:
093:                    sendAndCheck(destination, inputFilePath, outputFilePath,
094:                            soapAction);
095:                } catch (Exception ex) {
096:                    System.out.println(" Failed.");
097:                    throw ex;
098:                } catch (Error er) {
099:                    System.out.println(" Failed.");
100:                    throw er;
101:                }
102:            }
103:
104:            /**
105:             * Send a soap message read in from the given input file, compare the output 
106:             * to the given output file
107:             */
108:            private static void sendAndCheck(String destination,
109:                    String inputFilePath, String outputFilePath,
110:                    String soapAction) throws Exception {
111:                SOAPMessage message = loadMessage(inputFilePath);
112:                SOAPMessage response = sendMessage(destination, message,
113:                        soapAction);
114:                outputResponse(response, inputFilePath, outputFilePath);
115:            }
116:
117:            private static void outputResponse(SOAPMessage response,
118:                    String inputFilePath, String outputFilePath) {
119:                try {
120:                    if (outputFilePath == null || outputFilePath.equals("")) {
121:                        outputFilePath = inputFilePath + ".out";
122:                    }
123:                    System.out.println("output file: " + outputFilePath);
124:                    File outputFile = new File(outputFilePath);
125:                    FileOutputStream fos = new FileOutputStream(outputFile);
126:                    TransformerFactory transformerFactory = TransformerFactory
127:                            .newInstance();
128:                    Transformer transformer = transformerFactory
129:                            .newTransformer();
130:
131:                    if (response != null) {
132:                        SOAPPart replySOAPPart = response.getSOAPPart();
133:                        Source sourceContent = replySOAPPart.getContent();
134:                        StreamResult result = new StreamResult(fos);
135:                        transformer.transform(sourceContent, result);
136:                    }
137:                } catch (IOException ex) {
138:                    ex.printStackTrace();
139:                } catch (TransformerConfigurationException ex) {
140:                    ex.printStackTrace();
141:                } catch (SOAPException ex) {
142:                    ex.printStackTrace();
143:                } catch (TransformerException ex) {
144:                    ex.printStackTrace();
145:                }
146:            }
147:
148:            /**
149:             * read in a soap message from the given input file
150:             */
151:            private static SOAPMessage loadMessage(String testMsgFileName)
152:                    throws SOAPException, IOException {
153:                //Create and populate the message from a file
154:                SOAPMessage message = messageFactory.createMessage();
155:                SOAPPart soapPart = message.getSOAPPart();
156:                StreamSource preppedMsgSrc = new StreamSource(
157:                        new FileInputStream(testMsgFileName));
158:                soapPart.setContent(preppedMsgSrc);
159:                message.saveChanges();
160:                return message;
161:            }
162:
163:            /**
164:             * Send a soap message 
165:             * @param destination URL to send to 
166:             * @param message message to send
167:             * @param expectedHttpStatus expected http status code or null if success is expected
168:             * @return reply soap message
169:             */
170:            private static SOAPMessage sendMessage(String destination,
171:                    SOAPMessage message, String soapAction)
172:                    throws SOAPException {
173:
174:                // Add soapAction if not null
175:                if (soapAction != null) {
176:                    MimeHeaders hd = message.getMimeHeaders();
177:                    hd.setHeader("SOAPAction", soapAction);
178:                }
179:
180:                // Send the message and get a reply
181:                SOAPMessage reply = null;
182:                long start = 0;
183:
184:                boolean httpSuccess = true;
185:                try {
186:                    reply = connection.call(message, destination);
187:                } catch (SOAPException ex) {
188:                    ex.printStackTrace();
189:                }
190:                long end = 0;
191:
192:                return reply;
193:            }
194:
195:            public final static void main(String[] args) {
196:                if (args.length != 1) {
197:                    System.out.println("java SoapClient test.properties");
198:                    return;
199:                }
200:
201:                String propFilePath = args[0];
202:                System.out.println("file path: " + propFilePath);
203:                try {
204:                    SoapClient.testInboundSOAPRequest(propFilePath);
205:                } catch (Exception ex) {
206:                    ex.printStackTrace();
207:                }
208:            }
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.