Source Code Cross Referenced for ProviderImpl.java in  » 6.0-JDK-Modules » jax-ws-runtime » com » sun » xml » ws » spi » 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 » 6.0 JDK Modules » jax ws runtime » com.sun.xml.ws.spi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         * 
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         * 
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common Development
008:         * and Distribution License("CDDL") (collectively, the "License").  You
009:         * may not use this file except in compliance with the License. You can obtain
010:         * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011:         * or glassfish/bootstrap/legal/LICENSE.txt.  See the License for the specific
012:         * language governing permissions and limitations under the License.
013:         * 
014:         * When distributing the software, include this License Header Notice in each
015:         * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016:         * Sun designates this particular file as subject to the "Classpath" exception
017:         * as provided by Sun in the GPL Version 2 section of the License file that
018:         * accompanied this code.  If applicable, add the following below the License
019:         * Header, with the fields enclosed by brackets [] replaced by your own
020:         * identifying information: "Portions Copyrighted [year]
021:         * [name of copyright owner]"
022:         * 
023:         * Contributor(s):
024:         * 
025:         * If you wish your version of this file to be governed by only the CDDL or
026:         * only the GPL Version 2, indicate your decision by adding "[Contributor]
027:         * elects to include this software in this distribution under the [CDDL or GPL
028:         * Version 2] license."  If you don't indicate a single choice of license, a
029:         * recipient has the option to distribute your version of this file under
030:         * either the CDDL, the GPL Version 2 or to extend the choice of license to
031:         * its licensees as provided above.  However, if you add GPL Version 2 code
032:         * and therefore, elected the GPL Version 2 license, then the option applies
033:         * only if the new code is made subject to such option by the copyright
034:         * holder.
035:         */
036:        package com.sun.xml.ws.spi;
037:
038:        import com.sun.xml.ws.api.BindingID;
039:        import com.sun.xml.ws.api.WSService;
040:        import com.sun.xml.ws.api.addressing.AddressingVersion;
041:        import com.sun.xml.ws.api.addressing.WSEndpointReference;
042:        import com.sun.xml.ws.api.model.wsdl.WSDLPort;
043:        import com.sun.xml.ws.api.model.wsdl.WSDLService;
044:        import com.sun.xml.ws.api.server.BoundEndpoint;
045:        import com.sun.xml.ws.api.server.Container;
046:        import com.sun.xml.ws.api.server.ContainerResolver;
047:        import com.sun.xml.ws.api.server.Module;
048:        import com.sun.xml.ws.api.server.WSEndpoint;
049:        import com.sun.xml.ws.api.wsdl.parser.WSDLParserExtension;
050:        import com.sun.xml.ws.client.WSServiceDelegate;
051:        import com.sun.xml.ws.developer.MemberSubmissionEndpointReference;
052:        import com.sun.xml.ws.model.wsdl.WSDLModelImpl;
053:        import com.sun.xml.ws.resources.ProviderApiMessages;
054:        import com.sun.xml.ws.transport.http.server.EndpointImpl;
055:        import com.sun.xml.ws.util.ServiceFinder;
056:        import com.sun.xml.ws.util.xml.XmlUtil;
057:        import com.sun.xml.ws.wsdl.parser.RuntimeWSDLParser;
058:        import org.w3c.dom.Element;
059:        import org.xml.sax.EntityResolver;
060:
061:        import javax.xml.bind.JAXBContext;
062:        import javax.xml.bind.JAXBException;
063:        import javax.xml.bind.Unmarshaller;
064:        import javax.xml.namespace.QName;
065:        import javax.xml.transform.Source;
066:        import javax.xml.transform.stream.StreamSource;
067:        import javax.xml.ws.Endpoint;
068:        import javax.xml.ws.EndpointReference;
069:        import javax.xml.ws.Service;
070:        import javax.xml.ws.WebServiceException;
071:        import javax.xml.ws.WebServiceFeature;
072:        import javax.xml.ws.spi.Provider;
073:        import javax.xml.ws.spi.ServiceDelegate;
074:        import javax.xml.ws.wsaddressing.W3CEndpointReference;
075:        import java.net.URL;
076:        import java.security.AccessController;
077:        import java.security.PrivilegedAction;
078:        import java.util.List;
079:
080:        /**
081:         * The entry point to the JAX-WS RI from the JAX-WS API.
082:         *
083:         * @author WS Development Team
084:         */
085:        public class ProviderImpl extends Provider {
086:
087:            private final static JAXBContext eprjc = getEPRJaxbContext();
088:
089:            /**
090:             * Convenient singleton instance.
091:             */
092:            public static final ProviderImpl INSTANCE = new ProviderImpl();
093:
094:            @Override
095:            public Endpoint createEndpoint(String bindingId, Object implementor) {
096:                return new EndpointImpl((bindingId != null) ? BindingID
097:                        .parse(bindingId) : BindingID.parse(implementor
098:                        .getClass()), implementor);
099:            }
100:
101:            @Override
102:            public ServiceDelegate createServiceDelegate(
103:                    URL wsdlDocumentLocation, QName serviceName,
104:                    Class serviceClass) {
105:                return new WSServiceDelegate(wsdlDocumentLocation, serviceName,
106:                        serviceClass);
107:            }
108:
109:            @Override
110:            public Endpoint createAndPublishEndpoint(String address,
111:                    Object implementor) {
112:                Endpoint endpoint = new EndpointImpl(BindingID
113:                        .parse(implementor.getClass()), implementor);
114:                endpoint.publish(address);
115:                return endpoint;
116:            }
117:
118:            public EndpointReference readEndpointReference(
119:                    final Source eprInfoset) {
120:                // EPR constructors are private, so we need privilege escalation.
121:                // this unmarshalling can only access instances of a fixed, known set of classes,
122:                // so doing that shouldn't introduce security vulnerability.
123:                return AccessController
124:                        .doPrivileged(new PrivilegedAction<EndpointReference>() {
125:                            public EndpointReference run() {
126:                                try {
127:                                    Unmarshaller unmarshaller = eprjc
128:                                            .createUnmarshaller();
129:                                    return (EndpointReference) unmarshaller
130:                                            .unmarshal(eprInfoset);
131:                                } catch (JAXBException e) {
132:                                    throw new WebServiceException(
133:                                            "Error creating Marshaller or marshalling.",
134:                                            e);
135:                                }
136:                            }
137:                        });
138:            }
139:
140:            public <T> T getPort(EndpointReference endpointReference,
141:                    Class<T> clazz, WebServiceFeature... webServiceFeatures) {
142:                /*
143:                final @NotNull MemberSubmissionEndpointReference msepr =
144:                        EndpointReferenceUtil.transform(MemberSubmissionEndpointReference.class, endpointReference);
145:                        WSService service = new WSServiceDelegate(msepr.toWSDLSource(), msepr.serviceName.name, Service.class);
146:                 */
147:                if (endpointReference == null)
148:                    throw new WebServiceException(ProviderApiMessages
149:                            .NULL_EPR());
150:                WSEndpointReference wsepr = new WSEndpointReference(
151:                        endpointReference);
152:                WSEndpointReference.Metadata metadata = wsepr.getMetaData();
153:                WSService service;
154:                if (metadata.getWsdlSource() != null)
155:                    service = new WSServiceDelegate(metadata.getWsdlSource(),
156:                            metadata.getServiceName(), Service.class);
157:                else
158:                    throw new WebServiceException(
159:                            "WSDL metadata is missing in EPR");
160:                return service.getPort(wsepr, clazz, webServiceFeatures);
161:            }
162:
163:            public W3CEndpointReference createW3CEndpointReference(
164:                    String address, QName serviceName, QName portName,
165:                    List<Element> metadata, String wsdlDocumentLocation,
166:                    List<Element> referenceParameters) {
167:                if (address == null) {
168:                    if (serviceName == null || portName == null) {
169:                        throw new IllegalStateException(ProviderApiMessages
170:                                .NULL_ADDRESS_SERVICE_ENDPOINT());
171:                    } else {
172:                        //check if it is run in a Java EE Container and if so, get address using serviceName and portName
173:                        Container container = ContainerResolver.getInstance()
174:                                .getContainer();
175:                        Module module = container.getSPI(Module.class);
176:                        if (module != null) {
177:                            List<BoundEndpoint> beList = module
178:                                    .getBoundEndpoints();
179:                            for (BoundEndpoint be : beList) {
180:                                WSEndpoint wse = be.getEndpoint();
181:                                if (wse.getServiceName().equals(serviceName)
182:                                        && wse.getPortName().equals(portName)) {
183:                                    try {
184:                                        address = be.getAddress().toString();
185:                                    } catch (WebServiceException e) {
186:                                        // May be the container does n't support this
187:                                        //just ignore the exception
188:                                    }
189:                                    break;
190:                                }
191:                            }
192:                        }
193:                        //address is still null? may be its not run in a JavaEE Container
194:                        if (address == null)
195:                            throw new IllegalStateException(ProviderApiMessages
196:                                    .NULL_ADDRESS());
197:                    }
198:                }
199:                if ((serviceName == null) && (portName != null)) {
200:                    throw new IllegalStateException(ProviderApiMessages
201:                            .NULL_SERVICE());
202:                }
203:                //Validate Service and Port in WSDL
204:                if (wsdlDocumentLocation != null) {
205:                    try {
206:                        EntityResolver er = XmlUtil
207:                                .createDefaultCatalogResolver();
208:
209:                        URL wsdlLoc = new URL(wsdlDocumentLocation);
210:                        WSDLModelImpl wsdlDoc = RuntimeWSDLParser.parse(
211:                                wsdlLoc, new StreamSource(wsdlLoc
212:                                        .toExternalForm()), er, false,
213:                                ServiceFinder.find(WSDLParserExtension.class)
214:                                        .toArray());
215:                        if (serviceName != null) {
216:                            WSDLService wsdlService = wsdlDoc
217:                                    .getService(serviceName);
218:                            if (wsdlService == null)
219:                                throw new IllegalStateException(
220:                                        ProviderApiMessages
221:                                                .NOTFOUND_SERVICE_IN_WSDL(
222:                                                        serviceName,
223:                                                        wsdlDocumentLocation));
224:                            if (portName != null) {
225:                                WSDLPort wsdlPort = wsdlService.get(portName);
226:                                if (wsdlPort == null)
227:                                    throw new IllegalStateException(
228:                                            ProviderApiMessages
229:                                                    .NOTFOUND_PORT_IN_WSDL(
230:                                                            portName,
231:                                                            serviceName,
232:                                                            wsdlDocumentLocation));
233:                            }
234:                        }
235:                    } catch (Exception e) {
236:                        throw new IllegalStateException(ProviderApiMessages
237:                                .ERROR_WSDL(wsdlDocumentLocation), e);
238:                    }
239:                }
240:                // Supress writing ServiceName and EndpointName in W3C EPR,
241:                // Until the ns for those metadata elements is resolved.
242:                return new WSEndpointReference(AddressingVersion
243:                        .fromSpecClass(W3CEndpointReference.class), address,
244:                        null /*serviceName*/, null /*portName*/, null,
245:                        metadata, null /*wsdlDocumentLocation*/,
246:                        referenceParameters).toSpec(W3CEndpointReference.class);
247:            }
248:
249:            private static JAXBContext getEPRJaxbContext() {
250:                // EPRs have package and private fields, so we need privilege escalation.
251:                // this access only fixed, known set of classes, so doing that
252:                // shouldn't introduce security vulnerability.
253:                return AccessController
254:                        .doPrivileged(new PrivilegedAction<JAXBContext>() {
255:                            public JAXBContext run() {
256:                                try {
257:                                    return JAXBContext
258:                                            .newInstance(
259:                                                    MemberSubmissionEndpointReference.class,
260:                                                    W3CEndpointReference.class);
261:                                } catch (JAXBException e) {
262:                                    throw new WebServiceException(
263:                                            "Error creating JAXBContext for W3CEndpointReference. ",
264:                                            e);
265:                                }
266:                            }
267:                        });
268:            }
269:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.