Source Code Cross Referenced for ContextUtils.java in  » Web-Services-AXIS2 » jax-ws » org » apache » axis2 » jaxws » context » utils » 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 » Web Services AXIS2 » jax ws » org.apache.axis2.jaxws.context.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.jaxws.context.utils;
020:
021:        import org.apache.axis2.context.ServiceContext;
022:        import org.apache.axis2.jaxws.core.MessageContext;
023:        import org.apache.axis2.jaxws.description.EndpointDescription;
024:        import org.apache.axis2.jaxws.description.EndpointInterfaceDescription;
025:        import org.apache.axis2.jaxws.description.OperationDescription;
026:        import org.apache.axis2.jaxws.description.ServiceDescription;
027:        import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
028:        import org.apache.axis2.transport.http.HTTPConstants;
029:        import org.apache.commons.logging.Log;
030:        import org.apache.commons.logging.LogFactory;
031:
032:        import javax.servlet.http.HttpServletRequest;
033:        import javax.servlet.http.HttpServletResponse;
034:        import javax.xml.namespace.QName;
035:        import javax.xml.ws.WebServiceContext;
036:        import javax.xml.ws.handler.MessageContext.Scope;
037:        import javax.xml.ws.handler.soap.SOAPMessageContext;
038:        import java.net.URI;
039:        import java.net.URISyntaxException;
040:        import java.net.URL;
041:        import java.util.Map;
042:
043:        public class ContextUtils {
044:            private static final Log log = LogFactory
045:                    .getLog(ContextUtils.class);
046:            private static final String WEBSERVICE_MESSAGE_CONTEXT = "javax.xml.ws.WebServiceContext";
047:
048:            /**
049:             * Adds the appropriate properties to the MessageContext that the user will see
050:             *
051:             * @param soapMessageContext
052:             * @param jaxwsMessageContext
053:             */
054:            public static void addProperties(
055:                    SOAPMessageContext soapMessageContext,
056:                    MessageContext jaxwsMessageContext) {
057:
058:                // Copy Axis2 MessageContext properties.  It's possible that some set of Axis2 handlers
059:                // have run and placed some properties in the context that need to be visible.
060:                soapMessageContext.putAll(jaxwsMessageContext.getProperties());
061:
062:                EndpointDescription description = jaxwsMessageContext
063:                        .getEndpointDescription();
064:                if (description != null) {
065:                    // Set the WSDL properties
066:                    ServiceDescription sd = description.getServiceDescription();
067:                    if (sd != null) {
068:                        URL wsdlLocation = ((ServiceDescriptionWSDL) sd)
069:                                .getWSDLLocation();
070:                        if (wsdlLocation != null && !"".equals(wsdlLocation)) {
071:                            URI wsdlLocationURI = null;
072:                            try {
073:                                wsdlLocationURI = wsdlLocation.toURI();
074:                            } catch (URISyntaxException ex) {
075:                                // TODO: NLS/RAS
076:                                log.warn(
077:                                        "Unable to convert WSDL location URL to URI.  URL: "
078:                                                + wsdlLocation.toString()
079:                                                + "; Service: "
080:                                                + sd.getServiceQName(), ex);
081:                            }
082:                            soapMessageContext
083:                                    .put(
084:                                            javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION,
085:                                            wsdlLocationURI);
086:                            soapMessageContext
087:                                    .setScope(
088:                                            javax.xml.ws.handler.MessageContext.WSDL_DESCRIPTION,
089:                                            Scope.APPLICATION);
090:                        }
091:
092:                        soapMessageContext
093:                                .put(
094:                                        javax.xml.ws.handler.MessageContext.WSDL_SERVICE,
095:                                        sd.getServiceQName());
096:                        soapMessageContext
097:                                .setScope(
098:                                        javax.xml.ws.handler.MessageContext.WSDL_SERVICE,
099:                                        Scope.APPLICATION);
100:                        if (log.isDebugEnabled()) {
101:                            log.debug("WSDL_SERVICE :" + sd.getServiceQName());
102:                        }
103:                    }
104:                }
105:
106:                // If we are running within a servlet container, then JAX-WS requires that the
107:                // servlet related properties be set on the MessageContext
108:                soapMessageContext
109:                        .put(
110:                                javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT,
111:                                jaxwsMessageContext
112:                                        .getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT));
113:                soapMessageContext.setScope(
114:                        javax.xml.ws.handler.MessageContext.SERVLET_CONTEXT,
115:                        Scope.APPLICATION);
116:
117:                if (log.isDebugEnabled()) {
118:                    if (jaxwsMessageContext
119:                            .getProperty(HTTPConstants.MC_HTTP_SERVLETCONTEXT) != null) {
120:                        log.debug("Servlet Context Set");
121:                    } else {
122:                        log.debug("Servlet Context not found");
123:                    }
124:                }
125:
126:                HttpServletRequest req = (HttpServletRequest) jaxwsMessageContext
127:                        .getProperty(HTTPConstants.MC_HTTP_SERVLETREQUEST);
128:                if (req == null) {
129:                    if (log.isDebugEnabled()) {
130:                        log.debug("HTTPServletRequest not found");
131:                    }
132:                }
133:                if (req != null) {
134:                    soapMessageContext
135:                            .put(
136:                                    javax.xml.ws.handler.MessageContext.SERVLET_REQUEST,
137:                                    req);
138:                    soapMessageContext
139:                            .setScope(
140:                                    javax.xml.ws.handler.MessageContext.SERVLET_REQUEST,
141:                                    Scope.APPLICATION);
142:                    if (log.isDebugEnabled()) {
143:                        log.debug("SERVLET_REQUEST Set");
144:                    }
145:
146:                    String pathInfo = req.getPathInfo();
147:                    soapMessageContext.put(
148:                            javax.xml.ws.handler.MessageContext.PATH_INFO,
149:                            pathInfo);
150:                    soapMessageContext.setScope(
151:                            javax.xml.ws.handler.MessageContext.PATH_INFO,
152:                            Scope.APPLICATION);
153:                    if (log.isDebugEnabled()) {
154:                        if (pathInfo != null) {
155:                            log.debug("HTTP_REQUEST_PATHINFO Set");
156:                        } else {
157:                            log.debug("HTTP_REQUEST_PATHINFO not found");
158:                        }
159:                    }
160:                    String queryString = req.getQueryString();
161:                    soapMessageContext.put(
162:                            javax.xml.ws.handler.MessageContext.QUERY_STRING,
163:                            queryString);
164:                    soapMessageContext.setScope(
165:                            javax.xml.ws.handler.MessageContext.QUERY_STRING,
166:                            Scope.APPLICATION);
167:                    if (log.isDebugEnabled()) {
168:                        if (queryString != null) {
169:                            log.debug("HTTP_REQUEST_QUERYSTRING Set");
170:                        } else {
171:                            log.debug("HTTP_REQUEST_QUERYSTRING not found");
172:                        }
173:                    }
174:                    String method = req.getMethod();
175:                    soapMessageContext
176:                            .put(
177:                                    javax.xml.ws.handler.MessageContext.HTTP_REQUEST_METHOD,
178:                                    method);
179:                    soapMessageContext
180:                            .setScope(
181:                                    javax.xml.ws.handler.MessageContext.HTTP_REQUEST_METHOD,
182:                                    Scope.APPLICATION);
183:                    if (log.isDebugEnabled()) {
184:                        if (method != null) {
185:                            log.debug("HTTP_REQUEST_METHOD Set");
186:                        } else {
187:                            log.debug("HTTP_REQUEST_METHOD not found");
188:                        }
189:                    }
190:
191:                }
192:                HttpServletResponse res = (HttpServletResponse) jaxwsMessageContext
193:                        .getProperty(HTTPConstants.MC_HTTP_SERVLETRESPONSE);
194:                if (res == null) {
195:                    if (log.isDebugEnabled()) {
196:                        log.debug("Servlet Response not found");
197:                    }
198:                }
199:                if (res != null) {
200:                    soapMessageContext
201:                            .put(
202:                                    javax.xml.ws.handler.MessageContext.SERVLET_RESPONSE,
203:                                    res);
204:                    soapMessageContext
205:                            .setScope(
206:                                    javax.xml.ws.handler.MessageContext.SERVLET_RESPONSE,
207:                                    Scope.APPLICATION);
208:                    if (log.isDebugEnabled()) {
209:                        log.debug("SERVLET_RESPONSE Set");
210:                    }
211:                }
212:
213:            }
214:
215:            public static void addWSDLProperties(
216:                    MessageContext jaxwsMessageContext) {
217:                org.apache.axis2.context.MessageContext msgContext = jaxwsMessageContext
218:                        .getAxisMessageContext();
219:                ServiceContext serviceContext = msgContext.getServiceContext();
220:                SOAPMessageContext soapMessageContext = null;
221:                if (serviceContext != null) {
222:                    WebServiceContext wsc = (WebServiceContext) serviceContext
223:                            .getProperty(WEBSERVICE_MESSAGE_CONTEXT);
224:                    if (wsc != null) {
225:                        soapMessageContext = (SOAPMessageContext) wsc
226:                                .getMessageContext();
227:                    }
228:                }
229:                OperationDescription op = jaxwsMessageContext
230:                        .getOperationDescription();
231:
232:                if (op != null && soapMessageContext != null) {
233:                    soapMessageContext.put(
234:                            javax.xml.ws.handler.MessageContext.WSDL_OPERATION,
235:                            op.getName());
236:                    soapMessageContext.setScope(
237:                            javax.xml.ws.handler.MessageContext.WSDL_OPERATION,
238:                            Scope.APPLICATION);
239:                    if (log.isDebugEnabled()) {
240:                        log.debug("WSDL_OPERATION :" + op.getName());
241:                    }
242:
243:                    EndpointInterfaceDescription eid = op
244:                            .getEndpointInterfaceDescription();
245:                    if (eid != null) {
246:                        EndpointDescription ed = eid.getEndpointDescription();
247:                        QName portType = eid.getPortType();
248:                        if (portType == null || portType.getLocalPart() == "") {
249:                            if (log.isDebugEnabled()) {
250:                                log
251:                                        .debug("Did not get port type from EndpointInterfaceDescription, attempting to get PortType from EndpointDescription");
252:                            }
253:                        }
254:                        if (ed != null) {
255:                            soapMessageContext
256:                                    .put(
257:                                            javax.xml.ws.handler.MessageContext.WSDL_PORT,
258:                                            ed.getPortQName());
259:                            soapMessageContext
260:                                    .setScope(
261:                                            javax.xml.ws.handler.MessageContext.WSDL_PORT,
262:                                            Scope.APPLICATION);
263:                            if (log.isDebugEnabled()) {
264:                                log.debug("WSDL_PORT :" + ed.getPortQName());
265:                            }
266:                        }
267:                        soapMessageContext
268:                                .put(
269:                                        javax.xml.ws.handler.MessageContext.WSDL_INTERFACE,
270:                                        portType);
271:                        soapMessageContext
272:                                .setScope(
273:                                        javax.xml.ws.handler.MessageContext.WSDL_INTERFACE,
274:                                        Scope.APPLICATION);
275:                        if (log.isDebugEnabled()) {
276:                            log.debug("WSDL_INTERFACE :" + portType);
277:                        }
278:                    }
279:                } else {
280:                    if (log.isDebugEnabled()) {
281:                        log
282:                                .debug("Unable to read WSDL operation, port and interface properties");
283:                    }
284:                }
285:            }
286:
287:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.