Source Code Cross Referenced for Axis2WebServiceContainerTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » axis2 » 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 » EJB Server geronimo » plugins » org.apache.geronimo.axis2 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *       http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        package org.apache.geronimo.axis2;
018:
019:        import java.io.ByteArrayInputStream;
020:        import java.io.ByteArrayOutputStream;
021:        import java.io.File;
022:        import java.io.IOException;
023:        import java.io.InputStream;
024:        import java.net.URI;
025:        import java.util.HashMap;
026:
027:        import javax.xml.parsers.DocumentBuilder;
028:
029:        import org.apache.geronimo.axis2.pojo.POJOWebServiceContainer;
030:        import org.apache.geronimo.jaxws.PortInfo;
031:        import org.apache.geronimo.jaxws.annotations.AnnotationHolder;
032:        import org.apache.geronimo.kernel.util.XmlUtil;
033:        import org.apache.geronimo.webservices.WebServiceContainer.Request;
034:        import org.w3c.dom.Document;
035:        import org.w3c.dom.Element;
036:        import org.w3c.dom.NamedNodeMap;
037:        import org.w3c.dom.NodeList;
038:
039:        public class Axis2WebServiceContainerTest extends Axis2AbstractTestCase {
040:            private final String RESOURCE_PATH = testDir + "/resources/";
041:
042:            public Axis2WebServiceContainerTest(String testName) {
043:                super (testName);
044:            }
045:
046:            /*
047:            public void testDocInvokeWithWSDL() throws Exception {
048:                invokeWithWSDL("BareDocLitService", "org.apache.geronimo.axis2.testdata.doclitbare.BareDocLitService",
049:                               "test_service_doclitbare.wsdl", "test_service_doclitbare_request.xml");
050:            }
051:             */
052:
053:            public void testRPCInvokeWithWSDL() throws Exception {
054:                invokeWithWSDL(
055:                        "RPCLitService",
056:                        "org.apache.geronimo.axis2.testdata.rpclit.RPCLitService",
057:                        "test_service_rpclit.wsdl",
058:                        "test_service_rpclit_request.xml");
059:            }
060:
061:            public void testGetWSDL() throws Exception {
062:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
063:
064:                PortInfo portInfo = new PortInfo();
065:                portInfo.setLocation("/axis2/HelloWorld");
066:                portInfo
067:                        .setServiceEndpointInterfaceName("org.apache.geronimo.axis2.testdata.simple.HelloWorld");
068:
069:                Axis2Request req = new Axis2Request(504,
070:                        "text/xml; charset=utf-8", null, Request.GET,
071:                        new HashMap(), new URI("/axis2/HelloWorld?wsdl"),
072:                        new HashMap(), "127.0.0.1");
073:                ByteArrayOutputStream out = new ByteArrayOutputStream();
074:                Axis2Response res = new Axis2Response(
075:                        "text/xml; charset=utf-8", "127.0.0.1", null, null,
076:                        8080, out);
077:
078:                String endpointClassName = "org.apache.geronimo.axis2.testdata.simple.HelloWorld";
079:                POJOWebServiceContainer container = new POJOWebServiceContainer(
080:                        portInfo, endpointClassName, cl, null, null,
081:                        AnnotationHolder.EMPTY, "/axis2");
082:                container.init();
083:                container.invoke(req, res);
084:                out.flush();
085:
086:            }
087:
088:            private void invokeWithWSDL(String serviceName,
089:                    String endPointClassName, String wsdl, String requestFile)
090:                    throws Exception {
091:                ClassLoader cl = Thread.currentThread().getContextClassLoader();
092:                InputStream in = cl.getResourceAsStream(requestFile);
093:
094:                //This will reduce number of requests files
095:                DocumentBuilder documentBuilder = XmlUtil
096:                        .newDocumentBuilderFactory().newDocumentBuilder();
097:                Document doc = documentBuilder.parse(in);
098:
099:                Element root = doc.getDocumentElement();
100:                NodeList nodeList = root.getElementsByTagName("soap:Envelope");
101:
102:                InputStream request;
103:
104:                for (int i = 0; i < nodeList.getLength(); i++) {
105:                    StringBuffer envelope = new StringBuffer("<soap:Envelope");
106:                    Element element = (Element) nodeList.item(i);
107:                    NamedNodeMap attributes = element.getAttributes();
108:                    if (attributes != null) {
109:                        for (int k = 0; k < attributes.getLength(); k++) {
110:                            envelope.append(" "
111:                                    + attributes.item(k).getNodeName().trim());
112:                            envelope.append("=\""
113:                                    + attributes.item(k).getNodeValue().trim()
114:                                    + "\"");
115:                        }
116:                        String content = element.getTextContent();
117:
118:                        if (content != null && !content.equals("")) {
119:                            envelope.append(">");
120:
121:                            NodeList children = element.getChildNodes();
122:                            if (children != null) {
123:                                for (int j = 0; j < children.getLength(); j++) {
124:                                    if (children.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
125:                                        Element child = (Element) children
126:                                                .item(j);
127:                                        envelope
128:                                                .append(getElementContent(child)
129:                                                        .trim());
130:                                    } else if (children.item(j).getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
131:                                        envelope.append(children.item(j)
132:                                                .getNodeValue().trim());
133:                                    }
134:                                }
135:                            }
136:                            envelope.append("</soap:Envelope>");
137:                        } else {
138:                            envelope.append("/>");
139:                        }
140:                    }
141:
142:                    System.out.println(envelope.toString());
143:
144:                    request = new ByteArrayInputStream(envelope.toString()
145:                            .getBytes("UTF-8"));
146:
147:                    PortInfo portInfo = new PortInfo();
148:                    portInfo.setLocation("/axis2/" + serviceName);
149:
150:                    File wsdlFile = new File(RESOURCE_PATH + wsdl);
151:                    portInfo.setWsdlFile(wsdlFile.toURL().toString());
152:
153:                    try {
154:                        Axis2Request req = new Axis2Request(504,
155:                                "text/xml; charset=utf-8", request,
156:                                Request.POST, new HashMap(), new URI("/axis2/"
157:                                        + serviceName), new HashMap(),
158:                                "127.0.0.1");
159:
160:                        ByteArrayOutputStream out = new ByteArrayOutputStream();
161:                        Axis2Response res = new Axis2Response(
162:                                "text/xml; charset=utf-8", "127.0.0.1", null,
163:                                null, 8080, out);
164:
165:                        POJOWebServiceContainer container = new POJOWebServiceContainer(
166:                                portInfo, endPointClassName, cl, null, null,
167:                                AnnotationHolder.EMPTY, "/axis2");
168:                        container.init();
169:                        container.invoke(req, res);
170:                        System.out.println("Response " + out);
171:                        out.flush();
172:
173:                    } catch (Throwable ex) {
174:                        ex.printStackTrace();
175:                        throw new Exception(ex.toString());
176:                    } finally {
177:                        if (request != null) {
178:                            try {
179:                                request.close();
180:                            } catch (IOException ignore) {
181:                                // ignore
182:                            }
183:                        }
184:                    }
185:                }
186:            }
187:
188:            private String getElementContent(Element e) {
189:                StringBuffer content = new StringBuffer("<" + e.getNodeName());
190:                NamedNodeMap attributes = e.getAttributes();
191:
192:                if (attributes != null) {
193:                    for (int k = 0; k < attributes.getLength(); k++) {
194:                        content.append(" " + attributes.item(k).getNodeName());
195:                        content.append("=\""
196:                                + attributes.item(k).getNodeValue() + "\"");
197:                    }
198:                }
199:
200:                String value = e.getTextContent();
201:
202:                if (value != null && !value.equals("")) {
203:                    content.append(">");
204:
205:                    NodeList children = e.getChildNodes();
206:                    if (children != null) {
207:                        for (int j = 0; j < children.getLength(); j++) {
208:                            if (children.item(j).getNodeType() == org.w3c.dom.Node.ELEMENT_NODE) {
209:                                Element child = (Element) children.item(j);
210:                                content.append(getElementContent(child).trim());
211:                            } else if (children.item(j).getNodeType() == org.w3c.dom.Node.TEXT_NODE) {
212:                                content.append(children.item(j).getNodeValue()
213:                                        .trim());
214:                            }
215:                        }
216:                    }
217:                    content.append("</" + e.getNodeName() + ">");
218:                } else {
219:                    content.append("/>");
220:                }
221:
222:                return content.toString();
223:            }
224:
225:            protected void setUp() throws Exception {
226:            }
227:
228:            protected void tearDown() throws Exception {
229:            }
230:
231:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.