Source Code Cross Referenced for JAXWSUtil.java in  » EJB-Server-resin-3.1.5 » extra » com » caucho » soap » jaxws » 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 resin 3.1.5 » extra » com.caucho.soap.jaxws 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *
023:         *   Free Software Foundation, Inc.
024:         *   59 Temple Place, Suite 330
025:         *   Boston, MA 02111-1307  USA
026:         *
027:         * @author Emil Ong
028:         */
029:
030:        package com.caucho.soap.jaxws;
031:
032:        import java.io.*;
033:
034:        import java.util.ArrayList;
035:        import java.util.List;
036:        import java.util.StringTokenizer;
037:        import java.util.logging.Level;
038:        import java.util.logging.Logger;
039:
040:        import javax.jws.HandlerChain;
041:        import javax.jws.WebService;
042:
043:        import javax.xml.bind.JAXBContext;
044:        import javax.xml.bind.Unmarshaller;
045:        import javax.xml.stream.XMLStreamException;
046:        import javax.xml.ws.WebServiceException;
047:        import javax.xml.ws.handler.Handler;
048:        import javax.xml.ws.handler.HandlerResolver;
049:        import javax.xml.ws.handler.LogicalHandler;
050:
051:        import com.caucho.util.L10N;
052:
053:        import com.caucho.soap.jaxws.handlerchain.HandlerChains;
054:
055:        import com.caucho.xml.stream.StaxUtil;
056:        import com.caucho.xml.stream.XMLStreamReaderImpl;
057:        import com.caucho.xml.stream.XMLStreamWriterImpl;
058:
059:        public class JAXWSUtil {
060:            private static final Logger log = Logger.getLogger(JAXWSUtil.class
061:                    .getName());
062:            private final static L10N L = new L10N(JAXWSUtil.class);
063:            private static Unmarshaller _handlerChainUnmarshaller = null;
064:
065:            public static void writeStartSOAPEnvelope(Writer out,
066:                    String namespace) throws IOException {
067:                out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
068:                out.write("<soapenv:Envelope xmlns:soapenv=\"" + namespace
069:                        + "\">");
070:                out.write("<soapenv:Body>");
071:
072:                out.flush();
073:            }
074:
075:            public static void writeEndSOAPEnvelope(Writer out)
076:                    throws IOException {
077:                out.write("</soapenv:Body>");
078:                out.write("</soapenv:Envelope>");
079:
080:                out.flush();
081:            }
082:
083:            public static void extractSOAPBody(InputStream in, OutputStream out)
084:                    throws WebServiceException {
085:                boolean foundBody = false;
086:
087:                try {
088:                    XMLStreamReaderImpl reader = new XMLStreamReaderImpl(in);
089:
090:                    // skip the Envelope
091:                    reader.nextTag();
092:
093:                    if (reader.getEventType() != reader.START_ELEMENT
094:                            || !"Envelope".equals(reader.getLocalName())) {
095:                        throw new WebServiceException(
096:                                L
097:                                        .l("Invalid response from server: No Envelope found"));
098:                    }
099:
100:                    // find the body
101:                    while (reader.hasNext()) {
102:                        reader.next();
103:
104:                        if (reader.getEventType() == reader.START_ELEMENT
105:                                && "Body".equals(reader.getLocalName())) {
106:
107:                            // Copy the body contents to a StreamDataHandler
108:                            reader.nextTag();
109:
110:                            XMLStreamWriterImpl xmlWriter = new XMLStreamWriterImpl(
111:                                    out, false);
112:
113:                            StaxUtil.copyReaderToWriter(reader, xmlWriter);
114:
115:                            xmlWriter.flush();
116:
117:                            foundBody = true;
118:
119:                            break;
120:                        }
121:                    }
122:                } catch (XMLStreamException e) {
123:                    throw new WebServiceException(e);
124:                }
125:
126:                if (!foundBody)
127:                    throw new WebServiceException(L
128:                            .l("Invalid response from server"));
129:            }
130:
131:            public static HandlerResolver createHandlerResolver(Class cl,
132:                    HandlerChain handlerChain) throws WebServiceException {
133:                try {
134:                    if (_handlerChainUnmarshaller == null) {
135:                        JAXBContext context = JAXBContext
136:                                .newInstance("com.caucho.soap.jaxws.handlerchain");
137:                        _handlerChainUnmarshaller = context
138:                                .createUnmarshaller();
139:                    }
140:
141:                    if (log.isLoggable(Level.FINER)) {
142:                        log.finer("Creating handler chain for " + cl
143:                                + " from file " + handlerChain.file());
144:                    }
145:
146:                    InputStream is = cl
147:                            .getResourceAsStream(handlerChain.file());
148:
149:                    HandlerChains handlerChains = (HandlerChains) _handlerChainUnmarshaller
150:                            .unmarshal(is);
151:
152:                    return handlerChains;
153:                } catch (Exception e) {
154:                    throw new WebServiceException(e);
155:                }
156:            }
157:
158:            public static List<Handler> sortHandlerChain(
159:                    List<Handler> handlerChain) {
160:                // According to the JAX-WS documentation, handler chains must be sorted
161:                // so that all LogicalHandlers appear before protocol Handlers 
162:                // (protocol Handlers are just Handlers that are not LogicalHandlers)
163:                //
164:                // XXX do this by bubbling up instead of creating a new list
165:                List list = new ArrayList<Handler>();
166:
167:                for (int i = 0; i < handlerChain.size(); i++) {
168:                    Handler handler = handlerChain.get(i);
169:
170:                    if (handler instanceof  LogicalHandler)
171:                        list.add(handler);
172:                }
173:
174:                for (int i = 0; i < handlerChain.size(); i++) {
175:                    Handler handler = handlerChain.get(i);
176:
177:                    if (!(handler instanceof  LogicalHandler))
178:                        list.add(handler);
179:                }
180:
181:                return list;
182:            }
183:
184:            public static Class getEndpointInterface(Class type) {
185:                WebService webService = (WebService) type
186:                        .getAnnotation(WebService.class);
187:
188:                if (webService != null
189:                        && !"".equals(webService.endpointInterface())) {
190:                    try {
191:                        ClassLoader loader = type.getClassLoader();
192:                        return loader.loadClass(webService.endpointInterface());
193:                    } catch (ClassNotFoundException e) {
194:                        throw new WebServiceException(e);
195:                    }
196:                }
197:
198:                return type;
199:            }
200:
201:            public static String getTargetNamespace(Class type, Class api) {
202:                WebService webService = (WebService) type
203:                        .getAnnotation(WebService.class);
204:
205:                // try to get the namespace from the annotation first...
206:                if (webService != null) {
207:                    if (!"".equals(webService.targetNamespace()))
208:                        return webService.targetNamespace();
209:
210:                    else if (!api.equals(type)) {
211:                        webService = (WebService) api
212:                                .getAnnotation(WebService.class);
213:
214:                        if (!"".equals(webService.targetNamespace()))
215:                            return webService.targetNamespace();
216:                    }
217:                }
218:
219:                // get the namespace from the package name
220:                String namespace = null;
221:                String packageName = type.getPackage().getName();
222:                StringTokenizer st = new StringTokenizer(packageName, ".");
223:
224:                while (st.hasMoreTokens()) {
225:                    if (namespace == null)
226:                        namespace = st.nextToken();
227:                    else
228:                        namespace = st.nextToken() + "." + namespace;
229:                }
230:
231:                return "http://" + namespace + "/";
232:            }
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.