Source Code Cross Referenced for WSRPWSDLToEndpointTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » wsrp » 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 JBoss 4.2.1 » testsuite » org.jboss.test.wsrp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.wsrp;
023:
024:        import java.io.IOException;
025:        import java.io.InputStream;
026:        import java.net.MalformedURLException;
027:        import java.net.URL;
028:        import java.util.Iterator;
029:
030:        import javax.wsdl.Definition;
031:        import javax.wsdl.Port;
032:        import javax.wsdl.Service;
033:        import javax.wsdl.extensions.ExtensibilityElement;
034:        import javax.wsdl.extensions.soap.SOAPAddress;
035:        import javax.wsdl.factory.WSDLFactory;
036:        import javax.wsdl.xml.WSDLLocator;
037:        import javax.xml.namespace.QName;
038:
039:        import junit.framework.Test;
040:
041:        import org.jboss.logging.Logger;
042:        import org.jboss.test.webservice.WebserviceTestBase;
043:        import org.xml.sax.InputSource;
044:
045:        //$Id: WSRPWSDLToEndpointTestCase.java 62137 2007-04-05 16:07:01Z fnasser@redhat.com $
046:
047:        /**
048:         *  Given a WSRP wsdl, derive the endpoint urls for the various
049:         *  wsrp services
050:         *  @author <a href="mailto:Anil.Saldhana@jboss.org">Anil Saldhana</a>
051:         *  @since  May 5, 2006
052:         *  @version $Revision: 62137 $
053:         */
054:        public class WSRPWSDLToEndpointTestCase extends WebserviceTestBase {
055:            private static Logger log = Logger
056:                    .getLogger(WSRPWSDLToEndpointTestCase.class);
057:
058:            /**
059:             * deploy the test archives
060:             */
061:            public static Test suite() throws Exception {
062:                return getDeploySetup(WSRPWSDLToEndpointTestCase.class,
063:                        "wsrp.war");
064:            }
065:
066:            public WSRPWSDLToEndpointTestCase(String name) {
067:                super (name);
068:            }
069:
070:            public void testEndpointGrab() throws Exception {
071:                String wsdl_url = "http://" + this .getServerHost()
072:                        + ":8080/wsrp/MarkupService?wsdl";
073:                Definition def = getWSDLDefinition(new URL(wsdl_url));
074:                Service serve = def.getService(new QName(
075:                        "urn:oasis:names:tc:wsrp:v1:wsdl", "WSRPService"));
076:                assertMarkupService(serve);
077:                assertPortletManagementService(serve);
078:                assertServiceDescriptionService(serve);
079:                assertRegistrationService(serve);
080:            }
081:
082:            //Requires wsdl4j
083:            private Definition getWSDLDefinition(URL url) throws Exception {
084:                WSDLFactory wsdlFactory = WSDLFactory.newInstance();
085:                javax.wsdl.xml.WSDLReader wsdlReader = wsdlFactory
086:                        .newWSDLReader();
087:                return wsdlReader.readWSDL(new WSDLLocatorImpl(url));
088:            }
089:
090:            private void assertMarkupService(Service serve) {
091:                Port markupPort = serve.getPort("WSRPMarkupService");
092:                if (markupPort == null)
093:                    markupPort = serve.getPort("WSRPBaseService");
094:                assertNotNull("MarkupService Port is not null", markupPort);
095:                String markupEndpoint = getLocation(markupPort);
096:                assertTrue("MarkupService endpoint is not null",
097:                        markupEndpoint != null
098:                                && markupEndpoint.indexOf("MarkupService") > 0);
099:            }
100:
101:            private void assertPortletManagementService(Service serve) {
102:                Port pmPort = serve.getPort("WSRPPortletManagementService");
103:                assertNotNull("WSRPPortletManagementService Port is not null",
104:                        pmPort);
105:                String pmEndpoint = getLocation(pmPort);
106:                assertTrue(
107:                        "WSRPPortletManagementService endpoint is not null",
108:                        pmEndpoint != null
109:                                && pmEndpoint
110:                                        .indexOf("PortletManagementService") > 0);
111:            }
112:
113:            private void assertServiceDescriptionService(Service serve) {
114:                Port sdPort = serve.getPort("WSRPServiceDescriptionService");
115:                assertNotNull("WSRPServiceDescriptionService Port is not null",
116:                        sdPort);
117:                String sdEndpoint = getLocation(sdPort);
118:                assertTrue(
119:                        "WSRPServiceDescriptionService endpoint is not null",
120:                        sdEndpoint != null
121:                                && sdEndpoint
122:                                        .indexOf("ServiceDescriptionService") > 0);
123:            }
124:
125:            private void assertRegistrationService(Service serve) {
126:                Port rsPort = serve.getPort("WSRPRegistrationService");
127:                assertNotNull("WSRPRegistrationService Port is not null",
128:                        rsPort);
129:                String rsEndpoint = getLocation(rsPort);
130:                assertTrue(
131:                        "WSRPRegistrationService endpoint is not null",
132:                        rsEndpoint != null
133:                                && rsEndpoint.indexOf("RegistrationService") > 0);
134:            }
135:
136:            /* A WSDLLocator that can handle wsdl imports
137:             */
138:            public static class WSDLLocatorImpl implements  WSDLLocator {
139:                private URL wsdlURL;
140:                private String latestImportURI;
141:
142:                public WSDLLocatorImpl(URL wsdlFile) {
143:                    if (wsdlFile == null)
144:                        throw new IllegalArgumentException(
145:                                "WSDL file argument cannot be null");
146:
147:                    this .wsdlURL = wsdlFile;
148:                }
149:
150:                public InputSource getBaseInputSource() {
151:                    log.trace("getBaseInputSource [wsdlUrl=" + wsdlURL + "]");
152:                    try {
153:                        InputStream is = wsdlURL.openStream();
154:                        if (is == null)
155:                            throw new IllegalArgumentException(
156:                                    "Cannot obtain wsdl from [" + wsdlURL + "]");
157:
158:                        return new InputSource(is);
159:                    } catch (IOException e) {
160:                        throw new RuntimeException("Cannot access wsdl from ["
161:                                + wsdlURL + "], " + e.getMessage());
162:                    }
163:                }
164:
165:                public String getBaseURI() {
166:                    return wsdlURL.toExternalForm();
167:                }
168:
169:                public InputSource getImportInputSource(String parent,
170:                        String resource) {
171:                    log.trace("getImportInputSource [parent=" + parent
172:                            + ",resource=" + resource + "]");
173:
174:                    URL parentURL = null;
175:                    try {
176:                        parentURL = new URL(parent);
177:                    } catch (MalformedURLException e) {
178:                        log.error("Not a valid URL: " + parent);
179:                        return null;
180:                    }
181:
182:                    String wsdlImport = null;
183:                    String external = parentURL.toExternalForm();
184:
185:                    // An external URL
186:                    if (resource.startsWith("http://")
187:                            || resource.startsWith("https://")) {
188:                        wsdlImport = resource;
189:                    }
190:
191:                    // Absolute path
192:                    else if (resource.startsWith("/")) {
193:                        String beforePath = external.substring(0, external
194:                                .indexOf(parentURL.getPath()));
195:                        wsdlImport = beforePath + resource;
196:                    }
197:
198:                    // A relative path
199:                    else {
200:                        String parentDir = external.substring(0, external
201:                                .lastIndexOf("/"));
202:
203:                        // remove references to current dir
204:                        while (resource.startsWith("./"))
205:                            resource = resource.substring(2);
206:
207:                        // remove references to parentdir
208:                        while (resource.startsWith("../")) {
209:                            parentDir = parentDir.substring(0, parentDir
210:                                    .lastIndexOf("/"));
211:                            resource = resource.substring(3);
212:                        }
213:
214:                        wsdlImport = parentDir + "/" + resource;
215:                    }
216:
217:                    try {
218:                        log.trace("Resolved to: " + wsdlImport);
219:                        InputStream is = new URL(wsdlImport).openStream();
220:                        if (is == null)
221:                            throw new IllegalArgumentException(
222:                                    "Cannot import wsdl from [" + wsdlImport
223:                                            + "]");
224:
225:                        latestImportURI = wsdlImport;
226:                        return new InputSource(is);
227:                    } catch (IOException e) {
228:                        throw new RuntimeException(
229:                                "Cannot access imported wsdl [" + wsdlImport
230:                                        + "], " + e.getMessage());
231:                    }
232:                }
233:
234:                public String getLatestImportURI() {
235:                    return latestImportURI;
236:                }
237:
238:                public void close() {
239:                }
240:            }
241:
242:            private String getLocation(Port port) {
243:                String loc = "";
244:                Iterator iter = port.getExtensibilityElements().iterator();
245:                while (iter.hasNext()) {
246:                    ExtensibilityElement ext = (ExtensibilityElement) iter
247:                            .next();
248:                    if (ext instanceof  SOAPAddress) {
249:                        SOAPAddress add = (SOAPAddress) ext;
250:                        loc = add.getLocationURI();
251:                    }
252:                }
253:                return loc;
254:            }
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.