Source Code Cross Referenced for SecuredMessage.java in  » 6.0-JDK-Modules-com.sun » xws-security » com » sun » xml » ws » security » opt » impl » message » 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 com.sun » xws security » com.sun.xml.ws.security.opt.impl.message 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the terms
003:         * of the Common Development and Distribution License
004:         * (the License).  You may not use this file except in
005:         * compliance with the License.
006:         *
007:         * You can obtain a copy of the license at
008:         * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009:         * See the License for the specific language governing
010:         * permissions and limitations under the License.
011:         *
012:         * When distributing Covered Code, include this CDDL
013:         * Header Notice in each file and include the License file
014:         * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015:         * If applicable, add the following below the CDDL Header,
016:         * with the fields enclosed by brackets [] replaced by
017:         * you own identifying information:
018:         * "Portions Copyrighted [year] [name of copyright owner]"
019:         *
020:         * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021:         */
022:
023:        package com.sun.xml.ws.security.opt.impl.message;
024:
025:        import com.sun.xml.ws.api.message.HeaderList;
026:        import com.sun.xml.ws.api.message.Message;
027:        import com.sun.xml.ws.security.opt.api.SecurityElement;
028:        import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
029:        import com.sun.xml.ws.security.opt.impl.outgoing.SecurityHeader;
030:        import java.util.ArrayList;
031:        import java.util.Iterator;
032:        import java.util.NoSuchElementException;
033:
034:        import javax.xml.stream.XMLStreamException;
035:        import javax.xml.stream.XMLStreamReader;
036:        import javax.xml.stream.XMLStreamWriter;
037:        import org.jvnet.staxex.NamespaceContextEx;
038:        import com.sun.xml.wss.impl.MessageConstants;
039:        import com.sun.xml.wss.XWSSecurityException;
040:        import com.sun.xml.ws.api.message.AttachmentSet;
041:        import com.sun.xml.ws.api.SOAPVersion;
042:        import com.sun.xml.ws.api.message.Header;
043:
044:        /**
045:         *
046:         * @author K.Venugopal@sun.com
047:         */
048:
049:        public class SecuredMessage {
050:
051:            ArrayList headers;
052:            Message msg;
053:            SOAPBody body = null;
054:
055:            boolean isOneWay = false;
056:            SecurityElement securedBody = null;
057:            AttachmentSet attachments = null;
058:            private NamespaceContextEx context = null;
059:            SOAPVersion soapVersion = SOAPVersion.SOAP_11;
060:            private SecurityHeader sh = null;
061:
062:            /** Creates a new instance of SecuredMessage */
063:            public SecuredMessage(Message msg, SecurityHeader sh,
064:                    SOAPVersion soapVersion) {
065:                this (msg, sh);
066:                this .body = new SOAPBody(msg, soapVersion);
067:                this .soapVersion = soapVersion;
068:                boolean isSOAP12 = (soapVersion == SOAPVersion.SOAP_12) ? true
069:                        : false;
070:            }
071:
072:            public SecuredMessage(Message msg, SecurityHeader sh) {
073:                HeaderList hl = msg.getHeaders();
074:                headers = new ArrayList(hl);
075:                this .msg = msg;
076:                this .body = new SOAPBody(msg);
077:                attachments = msg.getAttachments();
078:                this .sh = sh;
079:            }
080:
081:            public ArrayList getHeaders() {
082:                return headers;
083:            }
084:
085:            public void setRootElements(NamespaceContextEx ne) {
086:                this .context = ne;
087:            }
088:
089:            public boolean isOneWay() {
090:                return this .isOneWay;
091:            }
092:
093:            public Iterator getHeaders(final String localName, final String uri) {
094:                return new Iterator() {
095:                    int idx = 0;
096:                    Object next;
097:
098:                    public boolean hasNext() {
099:                        if (next == null)
100:                            fetch();
101:                        return next != null;
102:                    }
103:
104:                    public Object next() {
105:                        if (next == null) {
106:                            fetch();
107:                            if (next == null) {
108:                                throw new NoSuchElementException();
109:                            }
110:                        }
111:
112:                        Object r = next;
113:                        next = null;
114:                        return r;
115:                    }
116:
117:                    private void fetch() {
118:                        while (idx < headers.size()) {
119:                            Object obj = headers.get(idx++);
120:                            if (obj instanceof  Header) {
121:                                Header hd = (Header) obj;
122:                                if ((uri == null && localName.equals(hd
123:                                        .getLocalPart()))
124:                                        || (localName.equals(hd.getLocalPart()) && uri
125:                                                .equals(hd.getNamespaceURI()))) {
126:                                    next = hd;
127:                                    break;
128:                                }
129:                            } else if (obj instanceof  SecurityElement) {
130:                                SecurityElement she = (SecurityElement) obj;
131:                                if ((uri == null && localName.equals(she
132:                                        .getLocalPart()))
133:                                        || (localName
134:                                                .equals(she.getLocalPart()) && uri
135:                                                .equals(she.getNamespaceURI()))) {
136:                                    next = she;
137:                                    break;
138:                                }
139:                            }
140:                        }
141:                    }
142:
143:                    public void remove() {
144:                        throw new UnsupportedOperationException();
145:                    }
146:                };
147:
148:            }
149:
150:            public Iterator getHeaders(final String uri) {
151:                return new Iterator() {
152:                    int idx = 0;
153:                    Object next;
154:
155:                    public boolean hasNext() {
156:                        if (next == null)
157:                            fetch();
158:                        return next != null;
159:                    }
160:
161:                    public Object next() {
162:                        if (next == null) {
163:                            fetch();
164:                            if (next == null) {
165:                                throw new NoSuchElementException();
166:                            }
167:                        }
168:
169:                        Object r = next;
170:                        next = null;
171:                        return r;
172:                    }
173:
174:                    private void fetch() {
175:                        while (idx < headers.size()) {
176:                            Object obj = headers.get(idx++);
177:                            if (obj instanceof  Header) {
178:                                Header hd = (Header) obj;
179:                                if (uri.equals(hd.getNamespaceURI())) {
180:                                    next = hd;
181:                                    break;
182:                                }
183:                            } else if (obj instanceof  SecurityElement) {
184:                                SecurityElement she = (SecurityElement) obj;
185:                                if (uri.equals(she.getNamespaceURI())) {
186:                                    next = she;
187:                                    break;
188:                                }
189:                            }
190:                        }
191:                    }
192:
193:                    public void remove() {
194:                        throw new UnsupportedOperationException();
195:                    }
196:                };
197:            }
198:
199:            public boolean replaceHeader(Object header1, Object header2) {
200:                boolean replaced = false;
201:                for (int i = 0; i < headers.size(); i++) {
202:                    Object obj = headers.get(i);
203:                    if (obj == header1 && obj.equals(header1)) {
204:                        headers.set(i, header2);
205:                        replaced = true;
206:                        break;
207:                    }
208:                }
209:                return replaced;
210:            }
211:
212:            public Object getHeader(String id) {
213:                Object hdr = null;
214:                for (int i = 0; i < headers.size(); i++) {
215:                    Object obj = headers.get(i);
216:                    if (obj instanceof  Header) {
217:                        Header hd = (Header) obj;
218:                        String wsuId = hd.getAttribute(
219:                                MessageConstants.WSSE_NS, "Id");
220:                        if (id.equals(wsuId)) {
221:                            hdr = hd;
222:                            break;
223:                        }
224:                    } else if (obj instanceof  SecurityElement) {
225:                        SecurityElement she = (SecurityElement) obj;
226:                        if (id.equals(she.getId())) {
227:                            hdr = she;
228:                            break;
229:                        }
230:                    }
231:                }
232:                return hdr;
233:            }
234:
235:            public String getPayloadNamespaceURI() {
236:                if (body != null) {
237:                    return body.getPayloadNamespaceURI();
238:                }
239:                if (securedBody != null) {
240:                    return securedBody.getNamespaceURI();
241:                }
242:                return null;
243:            }
244:
245:            public String getPayloadLocalPart() {
246:                if (body != null) {
247:                    return body.getPayloadLocalPart();
248:                }
249:                if (securedBody != null) {
250:                    return securedBody.getLocalPart();
251:                }
252:                return null;
253:            }
254:
255:            public XMLStreamReader readPayload() throws XMLStreamException {
256:                if (body != null) {
257:                    return body.read();
258:                }
259:
260:                if (securedBody != null) {
261:                    return securedBody.readHeader();
262:                }
263:                throw new XMLStreamException("No Payload found");
264:            }
265:
266:            public void writePayloadTo(XMLStreamWriter sw)
267:                    throws XMLStreamException {
268:                if (body != null) {
269:                    body.writeTo(sw);
270:                } else if (securedBody != null) {
271:                    ((SecurityElementWriter) securedBody).writeTo(sw);
272:                } else {
273:                    throw new XMLStreamException("No Payload found");
274:                }
275:                return;
276:            }
277:
278:            public Object getBody() throws XWSSecurityException {
279:                if (body != null) {
280:                    return body;
281:                } else if (securedBody != null) {
282:                    return securedBody;
283:                } else {
284:                    throw new XWSSecurityException("No body present in message");
285:                }
286:            }
287:
288:            public void replaceBody(SecurityElement she) {
289:                msg = null;
290:                securedBody = she;
291:                body = null;
292:            }
293:
294:            public void replaceBody(SOAPBody sb) {
295:                msg = null;
296:                body = sb;
297:                securedBody = null;
298:            }
299:
300:            public AttachmentSet getAttachments() {
301:                return attachments;
302:            }
303:
304:            public void writeTo(XMLStreamWriter sw) throws XMLStreamException {
305:                sw.writeStartDocument();
306:                sw.writeStartElement("S", "Envelope", soapVersion.nsUri);
307:                Iterator<org.jvnet.staxex.NamespaceContextEx.Binding> itr = context
308:                        .iterator();
309:
310:                while (itr.hasNext()) {
311:                    com.sun.xml.ws.security.opt.impl.util.NamespaceContextEx.Binding binding = itr
312:                            .next();
313:                    sw.writeNamespace(binding.getPrefix(), binding
314:                            .getNamespaceURI());
315:                }
316:
317:                sw.writeStartElement("S", "Header", soapVersion.nsUri);
318:                for (int i = 0; i < headers.size(); i++) {
319:                    Object hdr = headers.get(i);
320:                    if (hdr instanceof  Header) {
321:                        ((Header) hdr).writeTo(sw);
322:                    } else {
323:                        ((SecurityElementWriter) hdr).writeTo(sw);
324:                    }
325:                }
326:
327:                sh.writeTo(sw);
328:                sw.writeEndElement();
329:                if (securedBody != null) {
330:                    ((SecurityElementWriter) securedBody).writeTo(sw);
331:                } else if (body != null) {
332:                    body.writeTo(sw);
333:                }
334:
335:                sw.writeEndDocument();
336:            }
337:        }
w__w__w._j_a_v_a2s__._c__o_m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.