Source Code Cross Referenced for PipelineAssemblerFactoryImpl.java in  » 6.0-JDK-Modules-com.sun » wsit » com » sun » xml » ws » assembler » 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 » wsit » com.sun.xml.ws.assembler 
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:
037:        package com.sun.xml.ws.assembler;
038:
039:        import com.sun.xml.ws.api.server.Container;
040:        import com.sun.xml.ws.tx.common.Util;
041:        import com.sun.xml.wss.impl.misc.SecurityUtil;
042:        import java.io.InputStream;
043:        import java.net.URL;
044:        import java.util.logging.Logger;
045:
046:        import javax.servlet.ServletContext;
047:        import javax.xml.namespace.QName;
048:        import javax.xml.ws.WebServiceException;
049:
050:        import com.sun.istack.NotNull;
051:        import com.sun.xml.ws.encoding.LazyStreamCodec;
052:        import com.sun.xml.ws.policy.AssertionSet;
053:        import com.sun.xml.ws.policy.PolicyAssertion;
054:        import com.sun.xml.ws.transport.tcp.wsit.TCPConstants;
055:        import com.sun.xml.ws.api.pipe.Codec;
056:        import com.sun.xml.ws.api.pipe.Codecs;
057:        import com.sun.xml.ws.api.BindingID;
058:        import com.sun.xml.ws.api.WSBinding;
059:        import com.sun.xml.ws.api.WSService;
060:        import com.sun.xml.ws.api.addressing.AddressingVersion;
061:        import com.sun.xml.ws.api.client.WSPortInfo;
062:        import com.sun.xml.ws.api.model.wsdl.WSDLBoundOperation;
063:        import com.sun.xml.ws.api.model.wsdl.WSDLModel;
064:        import com.sun.xml.ws.api.model.wsdl.WSDLPort;
065:        import com.sun.xml.ws.api.model.wsdl.WSDLService;
066:        import com.sun.xml.ws.api.pipe.ClientPipeAssemblerContext;
067:        import com.sun.xml.ws.api.pipe.Pipe;
068:        import com.sun.xml.ws.api.pipe.Tube;
069:        import com.sun.xml.ws.api.pipe.PipelineAssembler;
070:        import com.sun.xml.ws.api.pipe.PipelineAssemblerFactory;
071:        import com.sun.xml.ws.api.pipe.ServerPipeAssemblerContext;
072:        import com.sun.xml.ws.api.pipe.StreamSOAPCodec;
073:        import com.sun.xml.ws.api.pipe.helper.PipeAdapter;
074:        import com.sun.xml.ws.api.server.WSEndpoint;
075:        import com.sun.xml.ws.api.server.ServiceDefinition;
076:        import com.sun.xml.ws.policy.Policy;
077:        import com.sun.xml.ws.policy.PolicyException;
078:        import com.sun.xml.ws.policy.PolicyMap;
079:        import com.sun.xml.ws.policy.PolicyMapKey;
080:        import com.sun.xml.ws.policy.jaxws.WSDLPolicyMapWrapper;
081:        import com.sun.xml.ws.policy.jaxws.client.PolicyFeature;
082:        import com.sun.xml.ws.policy.jaxws.xmlstreamwriter.documentfilter.WsdlDocumentFilter;
083:        import com.sun.xml.ws.policy.util.PolicyMapUtil;
084:        import com.sun.xml.ws.rm.Constants;
085:        import com.sun.xml.ws.rm.jaxws.runtime.client.RMClientTube;
086:        import com.sun.xml.ws.rm.jaxws.runtime.server.RMServerTube;
087:        import com.sun.xml.ws.security.secconv.SecureConversationInitiator;
088:        import com.sun.xml.ws.transport.tcp.wsit.TCPTransportPipeFactory;
089:        import com.sun.xml.ws.util.ServiceFinder;
090:        import com.sun.xml.ws.tx.client.TxClientPipe;
091:        import com.sun.xml.ws.tx.service.TxServerPipe;
092:        import com.sun.xml.wss.jaxws.impl.SecurityClientPipe;
093:        import com.sun.xml.wss.jaxws.impl.SecurityServerPipe;
094:
095:        /**
096:         * WSIT PipelineAssembler.
097:         *
098:         * @author Arun Gupta
099:         */
100:        @SuppressWarnings("deprecation")
101:        public final class PipelineAssemblerFactoryImpl extends
102:                PipelineAssemblerFactory {
103:
104:            private static final String PREFIX = "com.sun.xml.ws.assembler";
105:            private static final String CLIENT_PREFIX = PREFIX + ".client";
106:            private static final String SERVER_PREFIX = PREFIX + ".server";
107:            private static final String BEFORE_SUFFIX = ".before";
108:            private static final String AFTER_SUFFIX = ".after";
109:            private static final String TRANSPORT_SUFFIX = ".transport";
110:            private static final String ACTION_SUFFIX = ".action";
111:            private static final String WSS_SUFFIX = ".wss";
112:            private static final String WSA_SUFFIX = ".wsa";
113:            private static final String WSMEX_SUFFIX = ".wsmex";
114:            private static final String WSRM_SUFFIX = ".wsrm";
115:            private static final String WSTX_SUFFIX = ".wstx";
116:
117:            private static final String SECURITY_POLICY_NAMESPACE_URI = "http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";
118:            private static final String WSAT_SOAP_NSURI = "http://schemas.xmlsoap.org/ws/2004/10/wsat";
119:            private static final QName AT_ALWAYS_CAPABILITY = new QName(
120:                    WSAT_SOAP_NSURI, "ATAlwaysCapability");
121:            private static final QName AT_ASSERTION = new QName(
122:                    WSAT_SOAP_NSURI, "ATAssertion");
123:            private static final String AUTO_OPTIMIZED_TRANSPORT_POLICY_NAMESPACE_URI = "http://java.sun.com/xml/ns/wsit/2006/09/policy/transport/client";
124:            private static final QName AUTO_OPTIMIZED_TRANSPORT_POLICY_ASSERTION = new QName(
125:                    AUTO_OPTIMIZED_TRANSPORT_POLICY_NAMESPACE_URI,
126:                    "AutomaticallySelectOptimalTransport");
127:
128:            //default security pipe classes for XWSS 2.0 Style Security Configuration Support
129:            private static final String xwss20ClientPipe = "com.sun.xml.xwss.XWSSClientPipe";
130:            private static final String xwss20ServerPipe = "com.sun.xml.xwss.XWSSServerPipe";
131:            private static final String SERVLET_CONTEXT_CLASSNAME = "javax.servlet.ServletContext";
132:
133:            private static final Logger logger = Logger
134:                    .getLogger(PipelineAssemblerFactoryImpl.class.getName());
135:
136:            private static class WsitPipelineAssembler implements 
137:                    PipelineAssembler {
138:                private BindingID bindingId;
139:
140:                WsitPipelineAssembler(final BindingID bindingId) {
141:                    this .bindingId = bindingId;
142:                }
143:
144:                @NotNull
145:                @SuppressWarnings("unchecked")
146:                public Pipe createClient(@NotNull
147:                ClientPipeAssemblerContext context) {
148:                    // For dispatch client, this variable may be null
149:                    WSDLPort wsdlPort = context.getWsdlModel();
150:                    // This variable may be null if there was no client configuration file
151:                    PolicyFeature feature = initPolicyMap(context);
152:                    // For dispatch client, this variable may be null
153:                    WSDLModel wsdlModel = null;
154:                    // For dispatch client, this variable may be null
155:                    PolicyMap policyMap = null;
156:                    // This variable is only set if WSDL port is null and there is a
157:                    // client configuration file
158:                    WSPortInfo portInfo = null;
159:
160:                    if (feature != null) {
161:                        wsdlModel = feature.getWsdlModel();
162:                        policyMap = feature.getPolicyMap();
163:                        portInfo = feature.getPortInfo();
164:                    }
165:
166:                    // No WSDL port -> we must have a dispatch client. Extract WSDLPort
167:                    // from client config instead (if we have one).
168:                    if (wsdlPort == null && portInfo != null
169:                            && wsdlModel != null) {
170:                        QName serviceName = portInfo.getServiceName();
171:                        QName portName = portInfo.getPortName();
172:                        WSDLService service = wsdlModel.getService(serviceName);
173:                        if (service != null) {
174:                            wsdlPort = service.get(portName);
175:                        }
176:                    }
177:
178:                    boolean isSecurityEnabled = isSecurityEnabled(policyMap,
179:                            wsdlPort);
180:                    if (isSecurityEnabled) {
181:                        setSecurityCodec(context);
182:                    }
183:                    // Transport pipe ALWAYS exist
184:                    Pipe p;
185:                    if (isOptimizedTransportEnabled(policyMap, wsdlPort,
186:                            portInfo)) {
187:                        p = TCPTransportPipeFactory.doCreate(context, false);
188:                    } else {
189:                        p = context.createTransportPipe();
190:                    }
191:                    p = dump(context, CLIENT_PREFIX, p);
192:                    p = dumpAction(CLIENT_PREFIX + ACTION_SUFFIX, context
193:                            .getBinding(), p);
194:                    p = dump(context, CLIENT_PREFIX + TRANSPORT_SUFFIX, p);
195:
196:                    p = dump(context,
197:                            CLIENT_PREFIX + WSS_SUFFIX + AFTER_SUFFIX, p);
198:
199:                    // check for Security
200:                    SecureConversationInitiator scInit = null;
201:
202:                    //Look for pipe-creation hook exposed in contaner.
203:                    ClientPipelineHook hook = context.getContainer().getSPI(
204:                            ClientPipelineHook.class);
205:
206:                    //If not found, look for pipe-creation hook using services
207:                    if (hook == null) {
208:                        ClientPipelineHook[] hooks = loadSPs(ClientPipelineHook.class);
209:                        if (hooks != null && hooks.length > 0) {
210:                            hook = hooks[0];
211:                        }
212:                    }
213:
214:                    //If either mechanism for finding a ClientPipelineHook has found one, use it.
215:                    if (hook != null) {
216:                        p = hook.createSecurityPipe(policyMap, context, p);
217:
218:                        if (isSecurityEnabled) {
219:                            scInit = (SecureConversationInitiator) p;
220:                            /*
221:                            AuthConfigFactory factory = AuthConfigFactory.getFactory();
222:                            if (factory != null) {
223:                                AuthConfigProvider provider = factory.getConfigProvider("SOAP", null,null);
224:                                try {
225:                                    WSITClientAuthConfig authConfig =
226:                                            (WSITClientAuthConfig)provider.getClientAuthConfig("SOAP", null, null);
227:                                    scInit = (SecureConversationInitiator)authConfig;
228:                                }catch (AuthException e) {
229:                                    throw new RuntimeException(e);
230:                                }
231:                            }*/
232:                        }
233:
234:                    } else {
235:                        if (isSecurityEnabled) {
236:
237:                            ClientPipeConfiguration config = new ClientPipeConfiguration(
238:                                    policyMap, wsdlPort, context.getService(),
239:                                    context.getBinding());
240:
241:                            //Use the default WSIT Client Security Pipe
242:                            p = new SecurityClientPipe(config, p);
243:                            scInit = (SecureConversationInitiator) p;
244:
245:                            /*
246:                            HashMap propBag = new HashMap();
247:                            propBag.put("POLICY", policyMap);
248:                            propBag.put("WSDL_MODEL", wsdlPort);
249:                            propBag.put("SERVICE",context.getService());
250:                            propBag.put("BINDING", context.getBinding());
251:                            System.out.println("<<<<<<<<<Creating WSITClientSecurityPipe>>>>>>>>>");
252:                            p = new WSITClientSecurityPipe(propBag, p);
253:                            scInit = (SecureConversationInitiator)propBag.get("SC_INITIATOR");*/
254:
255:                        } else {
256:                            //look for XWSS 2.0 Style Security
257:                            // policyMap may be null in case of client dispatch without a client config file
258:                            if ((policyMap == null || policyMap.isEmpty())
259:                                    && isSecurityConfigPresent(context)) {
260:                                p = initializeXWSSClientPipe(wsdlPort, context
261:                                        .getService(), context.getBinding(), p);
262:                            }
263:                        }
264:                    }
265:                    p = dump(context, CLIENT_PREFIX + WSS_SUFFIX
266:                            + BEFORE_SUFFIX, p);
267:
268:                    // MEX pipe here
269:
270:                    p = dump(context, CLIENT_PREFIX + WSRM_SUFFIX
271:                            + AFTER_SUFFIX, p);
272:                    // check for WS-Reliable Messaging
273:                    if (isReliableMessagingEnabled(policyMap, wsdlPort)) {
274:                        Tube nextTube = PipeAdapter.adapt(p);
275:                        Tube rmClientTube = new RMClientTube(wsdlPort, context
276:                                .getService(), context.getBinding(), scInit,
277:                                nextTube);
278:
279:                        p = PipeAdapter.adapt(rmClientTube);
280:                    }
281:                    p = dump(context, CLIENT_PREFIX + WSRM_SUFFIX
282:                            + BEFORE_SUFFIX, p);
283:
284:                    p = dump(context, CLIENT_PREFIX + WSTX_SUFFIX
285:                            + AFTER_SUFFIX, p);
286:                    // check for WS-Atomic Transactions
287:                    if (isTransactionsEnabled(policyMap, wsdlPort, false)) {
288:                        p = new TxClientPipe(new ClientPipeConfiguration(
289:                                policyMap, wsdlPort, context.getService(),
290:                                context.getBinding()), p);
291:                    }
292:                    p = dump(context, CLIENT_PREFIX + WSTX_SUFFIX
293:                            + BEFORE_SUFFIX, p);
294:
295:                    p = dump(context,
296:                            CLIENT_PREFIX + WSA_SUFFIX + AFTER_SUFFIX, p);
297:                    // check for WS-Addressing
298:                    if (isAddressingEnabled(policyMap, wsdlPort, context
299:                            .getBinding())) {
300:                        p = context.createWsaPipe(p);
301:                    }
302:                    p = dump(context, CLIENT_PREFIX + WSA_SUFFIX
303:                            + BEFORE_SUFFIX, p);
304:                    p = context.createClientMUPipe(p);
305:                    p = context.createHandlerPipe(p);
306:
307:                    return p;
308:                }
309:
310:                @NotNull
311:                @SuppressWarnings("unchecked")
312:                public Pipe createServer(ServerPipeAssemblerContext context) {
313:                    ServiceDefinition sd = context.getEndpoint()
314:                            .getServiceDefinition();
315:                    if (sd != null) {
316:                        sd.addFilter(new WsdlDocumentFilter());
317:                    }
318:                    PolicyMap policyMap = initPolicyMap(context);
319:
320:                    Pipe p = context.getTerminalPipe();
321:                    p = context.createHandlerPipe(p);
322:                    p = context.createServerMUPipe(p);
323:                    p = context.createMonitoringPipe(p);
324:
325:                    p = dump(context, SERVER_PREFIX + WSTX_SUFFIX
326:                            + AFTER_SUFFIX, p);
327:                    // check for WS-Atomic Transactions
328:                    if (isTransactionsEnabled(policyMap,
329:                            context.getWsdlModel(), true)) {
330:                        p = new TxServerPipe(context.getWsdlModel(), context
331:                                .getEndpoint().getBinding(), policyMap, p);
332:                    }
333:                    p = dump(context, SERVER_PREFIX + WSTX_SUFFIX
334:                            + BEFORE_SUFFIX, p);
335:
336:                    p = dump(context, SERVER_PREFIX + WSRM_SUFFIX
337:                            + AFTER_SUFFIX, p);
338:                    // check for WS-Reliable Messaging
339:                    if (isReliableMessagingEnabled(policyMap, context
340:                            .getWsdlModel())) {
341:                        Tube nextTube = PipeAdapter.adapt(p);
342:                        Tube tube = new RMServerTube(context.getWsdlModel(),
343:                                context.getEndpoint(), nextTube);
344:                        p = PipeAdapter.adapt(tube);
345:
346:                    }
347:                    p = dump(context, SERVER_PREFIX + WSRM_SUFFIX
348:                            + BEFORE_SUFFIX, p);
349:
350:                    p = dump(context,
351:                            SERVER_PREFIX + WSA_SUFFIX + AFTER_SUFFIX, p);
352:                    // check for WS-Addressing
353:                    if (isAddressingEnabled(policyMap, context.getWsdlModel(),
354:                            context.getEndpoint().getBinding())) {
355:                        p = context.createWsaPipe(p);
356:                    }
357:                    p = dump(context, SERVER_PREFIX + WSA_SUFFIX
358:                            + BEFORE_SUFFIX, p);
359:
360:                    p = dump(context,
361:                            SERVER_PREFIX + WSS_SUFFIX + AFTER_SUFFIX, p);
362:
363:                    // check for Security
364:                    boolean securityIsEnabled = isSecurityEnabled(policyMap,
365:                            context.getWsdlModel());
366:                    ServerPipelineHook hook = context.getEndpoint()
367:                            .getContainer().getSPI(ServerPipelineHook.class);
368:                    if (hook != null) {
369:                        if (securityIsEnabled) {
370:                            setSecurityCodec(context);
371:                        }
372:                        p = hook.createSecurityPipe(policyMap, context
373:                                .getSEIModel(), context.getWsdlModel(), context
374:                                .getEndpoint(), p);
375:                    } else {
376:                        if (securityIsEnabled) {
377:                            setSecurityCodec(context);
378:                            ServerPipeConfiguration config = new ServerPipeConfiguration(
379:                                    policyMap, context.getWsdlModel(), context
380:                                            .getEndpoint());
381:                            p = new SecurityServerPipe(config, p);
382:                            /*
383:                            HashMap propBag = new HashMap();
384:                            propBag.put("POLICY", policyMap);
385:                            propBag.put("WSDL_MODEL", context.getWsdlModel());
386:                            propBag.put("SEI_MODEL", context.getSEIModel());
387:                            propBag.put("ENDPOINT", context.getEndpoint());
388:                            System.out.println("<<<<<<<<<Creating WSITServerSecurityPipe>>>>>>>>>");
389:                            p = new WSITServerSecurityPipe(propBag, p);*/
390:
391:                        } else {
392:                            try {
393:                                //look for XWSS 2.0 Style Security
394:                                if (((null == policyMap) || policyMap.isEmpty())
395:                                        && isSecurityConfigPresent(context)) {
396:                                    p = initializeXWSSServerPipe(context
397:                                            .getEndpoint(), context
398:                                            .getWsdlModel(), p);
399:                                }
400:                            } catch (NoClassDefFoundError err) {
401:                                // do nothing
402:                            }
403:                        }
404:                    }
405:                    p = dump(context, SERVER_PREFIX + WSS_SUFFIX
406:                            + BEFORE_SUFFIX, p);
407:
408:                    p = dump(context, SERVER_PREFIX + TRANSPORT_SUFFIX, p);
409:                    p = dumpAction(SERVER_PREFIX + ACTION_SUFFIX, context
410:                            .getEndpoint().getBinding(), p);
411:                    p = dump(context, SERVER_PREFIX, p);
412:
413:                    return p;
414:                }
415:
416:                private Pipe dump(ClientPipeAssemblerContext context,
417:                        String name, Pipe p) {
418:                    if (Boolean.getBoolean(name)) {
419:                        p = context.createDumpPipe(name, System.out, p);
420:                    }
421:
422:                    return p;
423:                }
424:
425:                private Pipe dump(ServerPipeAssemblerContext context,
426:                        String name, Pipe p) {
427:                    if (Boolean.getBoolean(name)) {
428:                        p = context.createDumpPipe(name, System.out, p);
429:                    }
430:
431:                    return p;
432:                }
433:
434:                /**
435:                 * Checks to see whether OptimizedTransport is enabled or not.
436:                 *
437:                 * @param policyMap policy map for {@link this} assembler
438:                 * @param port the WSDLPort object
439:                 * @param portInfo the WSPortInfo object
440:                 * @return true if OptimizedTransport is enabled, false otherwise
441:                 */
442:                private boolean isOptimizedTransportEnabled(
443:                        PolicyMap policyMap, WSDLPort port, WSPortInfo portInfo) {
444:                    if (policyMap == null || port == null)
445:                        return false;
446:
447:                    String schema = null;
448:
449:                    if (port != null) {
450:                        schema = port.getAddress().getURI().getScheme();
451:                    } else if (portInfo != null) {
452:                        schema = portInfo.getEndpointAddress().getURI()
453:                                .getScheme();
454:                    }
455:
456:                    if (schema == null) {
457:                        return false;
458:                    }
459:
460:                    // if target endpoint URI starts with TCP schema - dont check policies, just return true
461:                    if (com.sun.xml.ws.transport.tcp.util.TCPConstants.PROTOCOL_SCHEMA
462:                            .equals(schema))
463:                        return true;
464:
465:                    if (policyMap == null)
466:                        return false;
467:
468:                    try {
469:                        PolicyMapKey endpointKey = policyMap
470:                                .createWsdlEndpointScopeKey(port.getOwner()
471:                                        .getName(), port.getName());
472:                        Policy policy = policyMap
473:                                .getEndpointEffectivePolicy(endpointKey);
474:
475:                        if (policy != null
476:                                && policy
477:                                        .contains(TCPConstants.TCPTRANSPORT_POLICY_ASSERTION)
478:                                && policy
479:                                        .contains(AUTO_OPTIMIZED_TRANSPORT_POLICY_ASSERTION)) {
480:                            /* if client set to choose optimal transport and server has TCP transport policy
481:                               then need to check server side policy "enabled" attribute*/
482:                            for (AssertionSet assertionSet : policy) {
483:                                for (PolicyAssertion assertion : assertionSet) {
484:                                    if (assertion
485:                                            .getName()
486:                                            .equals(
487:                                                    TCPConstants.TCPTRANSPORT_POLICY_ASSERTION)) {
488:                                        String value = assertion
489:                                                .getAttributeValue(new QName(
490:                                                        "enabled"));
491:                                        if (value == null)
492:                                            return false;
493:                                        value = value.trim();
494:
495:                                        return (Boolean.valueOf(value) || value
496:                                                .equalsIgnoreCase("yes"));
497:                                    }
498:                                }
499:                            }
500:                        }
501:
502:                        return false;
503:                    } catch (PolicyException e) {
504:                        throw new WebServiceException(e);
505:                    }
506:                }
507:
508:                /**
509:                 * Checks to see whether WS-Atomic Transactions are enabled or not.
510:                 *
511:                 * @param policyMap policy map for {@link this} assembler
512:                 * @param wsdlPort the WSDLPort object
513:                 * @param isServerSide true iff this method is being called from {@link PipelineAssembler#createServer(ServerPipeAssemblerContext)}
514:                 * @return true if Transactions is enabled, false otherwise
515:                 */
516:                private boolean isTransactionsEnabled(PolicyMap policyMap,
517:                        WSDLPort wsdlPort, boolean isServerSide) {
518:                    if (policyMap == null || wsdlPort == null
519:                            || !Util.isJTAAvailable()) { // false for standalone WSIT client or WSIT Service in Tomcat
520:                        return false;
521:                    }
522:                    try {
523:                        PolicyMapKey endpointKey = PolicyMap
524:                                .createWsdlEndpointScopeKey(wsdlPort.getOwner()
525:                                        .getName(), wsdlPort.getName());
526:                        Policy policy = policyMap
527:                                .getEndpointEffectivePolicy(endpointKey);
528:
529:                        for (WSDLBoundOperation wbo : wsdlPort.getBinding()
530:                                .getBindingOperations()) {
531:                            PolicyMapKey operationKey = PolicyMap
532:                                    .createWsdlOperationScopeKey(wsdlPort
533:                                            .getOwner().getName(), wsdlPort
534:                                            .getName(), wbo.getName());
535:                            policy = policyMap
536:                                    .getOperationEffectivePolicy(operationKey);
537:
538:                            if (policy != null) {
539:                                // look for ATAlwaysCapable on the server side
540:                                if ((isServerSide)
541:                                        && (policy
542:                                                .contains(AT_ALWAYS_CAPABILITY))) {
543:                                    return true;
544:                                }
545:
546:                                // look for ATAssertion in both client and server
547:                                if (policy.contains(AT_ASSERTION)) {
548:                                    return true;
549:                                }
550:                            }
551:                        }
552:                    } catch (PolicyException e) {
553:                        throw new WebServiceException(e);
554:                    }
555:
556:                    return false;
557:                }
558:
559:                /**
560:                 * Checks to see whether WS-ReliableMessaging is enabled or not.
561:                 *
562:                 * @param policyMap policy map for {@link this} assembler
563:                 * @param port wsdl:port
564:                 * @return true if ReliableMessaging is enabled, false otherwise
565:                 */
566:                private boolean isReliableMessagingEnabled(PolicyMap policyMap,
567:                        WSDLPort port) {
568:                    if (policyMap == null || port == null)
569:                        return false;
570:
571:                    try {
572:                        PolicyMapKey endpointKey = policyMap
573:                                .createWsdlEndpointScopeKey(port.getOwner()
574:                                        .getName(), port.getName());
575:                        Policy policy = policyMap
576:                                .getEndpointEffectivePolicy(endpointKey);
577:
578:                        return (policy != null)
579:                                && (policy.contains(Constants.version10) || policy
580:                                        .contains(Constants.version11));
581:                    } catch (PolicyException e) {
582:                        throw new WebServiceException(e);
583:                    }
584:                }
585:
586:                /**
587:                 * Checks to see whether WS-Addressing is enabled or not.
588:                 *
589:                 * @param policyMap policy map for {@link this} assembler
590:                 * @param port wsdl:port
591:                 * @param binding Binding
592:                 * @return true if Addressing is enabled, false otherwise
593:                 */
594:                private boolean isAddressingEnabled(PolicyMap policyMap,
595:                        WSDLPort port, WSBinding binding) {
596:                    if (AddressingVersion.isEnabled(binding))
597:                        return true;
598:
599:                    if (policyMap == null || port == null)
600:                        return false;
601:
602:                    try {
603:                        PolicyMapKey endpointKey = policyMap
604:                                .createWsdlEndpointScopeKey(port.getOwner()
605:                                        .getName(), port.getName());
606:                        Policy policy = policyMap
607:                                .getEndpointEffectivePolicy(endpointKey);
608:
609:                        return (policy != null)
610:                                && (policy
611:                                        .contains(AddressingVersion.W3C.policyNsUri) || policy
612:                                        .contains(AddressingVersion.MEMBER.policyNsUri));
613:                    } catch (PolicyException e) {
614:                        throw new WebServiceException(e);
615:                    }
616:                }
617:
618:                /**
619:                 * Checks to see whether WS-Security is enabled or not.
620:                 *
621:                 * @param policyMap policy map for {@link this} assembler
622:                 * @param wsdlPort wsdl:port
623:                 * @return true if Security is enabled, false otherwise
624:                 */
625:                private boolean isSecurityEnabled(PolicyMap policyMap,
626:                        WSDLPort wsdlPort) {
627:                    if (policyMap == null || wsdlPort == null)
628:                        return false;
629:
630:                    try {
631:                        PolicyMapKey endpointKey = policyMap
632:                                .createWsdlEndpointScopeKey(wsdlPort.getOwner()
633:                                        .getName(), wsdlPort.getName());
634:                        Policy policy = policyMap
635:                                .getEndpointEffectivePolicy(endpointKey);
636:
637:                        if ((policy != null)
638:                                && policy
639:                                        .contains(SECURITY_POLICY_NAMESPACE_URI)) {
640:                            return true;
641:                        }
642:
643:                        for (WSDLBoundOperation wbo : wsdlPort.getBinding()
644:                                .getBindingOperations()) {
645:                            PolicyMapKey operationKey = policyMap
646:                                    .createWsdlOperationScopeKey(wsdlPort
647:                                            .getOwner().getName(), wsdlPort
648:                                            .getName(), wbo.getName());
649:                            policy = policyMap
650:                                    .getOperationEffectivePolicy(operationKey);
651:                            if ((policy != null)
652:                                    && policy
653:                                            .contains(SECURITY_POLICY_NAMESPACE_URI))
654:                                return true;
655:
656:                            policy = policyMap
657:                                    .getInputMessageEffectivePolicy(operationKey);
658:                            if ((policy != null)
659:                                    && policy
660:                                            .contains(SECURITY_POLICY_NAMESPACE_URI))
661:                                return true;
662:
663:                            policy = policyMap
664:                                    .getOutputMessageEffectivePolicy(operationKey);
665:                            if ((policy != null)
666:                                    && policy
667:                                            .contains(SECURITY_POLICY_NAMESPACE_URI))
668:                                return true;
669:
670:                            policy = policyMap
671:                                    .getFaultMessageEffectivePolicy(operationKey);
672:                            if ((policy != null)
673:                                    && policy
674:                                            .contains(SECURITY_POLICY_NAMESPACE_URI))
675:                                return true;
676:                        }
677:                    } catch (PolicyException e) {
678:                        throw new WebServiceException(e);
679:                    }
680:
681:                    return false;
682:                }
683:
684:                private static <P> P[] loadSPs(final Class<P> svcClass) {
685:                    return ServiceFinder.find(svcClass).toArray();
686:                }
687:
688:                private Pipe dumpAction(String name, WSBinding binding, Pipe p) {
689:                    if (Boolean.getBoolean(name)) {
690:                        ActionDumpPipe[] pipes = loadSPs(ActionDumpPipe.class);
691:                        if (pipes.length > 0) {
692:                            return pipes[0];
693:                        }
694:                        return new ActionDumpPipe(name, binding, p);
695:                    }
696:                    return p;
697:                }
698:
699:                /**
700:                 * Initializes the {@link PolicyMap} on the client side.
701:                 *
702:                 * If the server WSDL is known, this method returns:
703:                 * <ul>
704:                 * <li>PolicyMap that contains the policies for the client and server
705:                 * <li>WSDLModel of the server
706:                 * <li>PortInfo is null
707:                 * </ul>
708:                 *
709:                 * If this is a dispatch client that does not know the server WSDL, this
710:                 * method returns:
711:                 * <ul>
712:                 * <li>PolicyMap with the policies for the client
713:                 * <li>WSDLModel of the client configuration
714:                 * <li>PortInfo for the client
715:                 * </ul>
716:                 *
717:                 * If there is no server WSDL and no client configuration, this method
718:                 * returns null.
719:                 *
720:                 * @param context client assembler context
721:                 * @return policy feature
722:                 */
723:                private PolicyFeature initPolicyMap(
724:                        ClientPipeAssemblerContext context) {
725:                    logger.entering(this .getClass().getName(), "initPolicyMap",
726:                            new Object[] { context });
727:                    PolicyFeature feature = null;
728:                    PolicyMap map = null;
729:                    WSDLModel model = null;
730:
731:                    WSDLPort wsdlPort = context.getWsdlModel();
732:                    if (wsdlPort != null) {
733:                        // Usually, the WSDL model holds the server and client policy maps
734:                        // merged into one
735:                        model = wsdlPort.getBinding().getOwner();
736:                        WSDLPolicyMapWrapper mapWrapper = model
737:                                .getExtension(WSDLPolicyMapWrapper.class);
738:                        if (mapWrapper != null) {
739:                            map = mapWrapper.getPolicyMap();
740:                        }
741:                        feature = new PolicyFeature(map, model, null);
742:
743:                    }
744:                    // In dispatch mode, wsdlPort is null
745:                    else {
746:                        WSBinding binding = context.getBinding();
747:                        // In this mode, we don't have a server policy map, so we read the
748:                        // client policy map only
749:                        feature = binding.getFeature(PolicyFeature.class);
750:                    }
751:
752:                    logger.exiting(this .getClass().getName(), "initPolicyMap",
753:                            feature);
754:                    return feature;
755:                }
756:
757:                /**
758:                 * Initializes the {@link PolicyMap} on the server side.
759:                 *
760:                 * @param context server assembler context
761:                 * @return initialized policy map
762:                 */
763:                private PolicyMap initPolicyMap(
764:                        ServerPipeAssemblerContext context)
765:                        throws WebServiceException {
766:                    PolicyMap map = null;
767:
768:                    WSDLPort wsdlPort = context.getWsdlModel();
769:                    if (wsdlPort != null) {
770:                        WSDLModel model = wsdlPort.getBinding().getOwner();
771:                        WSDLPolicyMapWrapper mapWrapper = model
772:                                .getExtension(WSDLPolicyMapWrapper.class);
773:                        if (mapWrapper != null) {
774:                            map = mapWrapper.getPolicyMap();
775:                        }
776:
777:                        if (map != null) {
778:                            try {
779:                                PolicyMapUtil.rejectAlternatives(map);
780:                            } catch (PolicyException e) {
781:                                throw new WebServiceException(e);
782:                            }
783:                        }
784:                    }
785:
786:                    return map;
787:                }
788:
789:                private void setSecurityCodec(ServerPipeAssemblerContext context) {
790:                    StreamSOAPCodec primaryCodec = Codecs
791:                            .createSOAPEnvelopeXmlCodec(context.getEndpoint()
792:                                    .getBinding().getSOAPVersion());
793:                    LazyStreamCodec lsc = new LazyStreamCodec(primaryCodec);
794:                    Codec fullCodec = Codecs.createSOAPBindingCodec(context
795:                            .getEndpoint().getBinding(), lsc);
796:                    context.setCodec(fullCodec);
797:                }
798:
799:                private void setSecurityCodec(ClientPipeAssemblerContext context) {
800:                    StreamSOAPCodec primaryCodec = Codecs
801:                            .createSOAPEnvelopeXmlCodec(context.getBinding()
802:                                    .getSOAPVersion());
803:                    LazyStreamCodec lsc = new LazyStreamCodec(primaryCodec);
804:                    Codec fullCodec = Codecs.createSOAPBindingCodec(context
805:                            .getBinding(), lsc);
806:                    context.setCodec(fullCodec);
807:                }
808:
809:                /**
810:                 * Helper class to return both PolicyMap and WSDLModel
811:                 */
812:                private static class MapModelRecord {
813:                    private final PolicyMap policyMap;
814:                    private final WSDLModel wsdlModel;
815:
816:                    MapModelRecord(PolicyMap map, WSDLModel model) {
817:                        this .policyMap = map;
818:                        this .wsdlModel = model;
819:                    }
820:
821:                    public PolicyMap getPolicyMap() {
822:                        return this .policyMap;
823:                    }
824:
825:                    public WSDLModel getWsdlModel() {
826:                        return this .wsdlModel;
827:                    }
828:                }
829:            }
830:
831:            public PipelineAssembler doCreate(final BindingID bindingId) {
832:                return new WsitPipelineAssembler(bindingId);
833:            }
834:
835:            private static boolean isSecurityConfigPresent(
836:                    ClientPipeAssemblerContext context) {
837:                //returning true by default for now, because the Client Side Security Config is
838:                //only accessible as a Runtime Property on BindingProvider.RequestContext
839:                return true;
840:            }
841:
842:            private static boolean isSecurityConfigPresent(
843:                    ServerPipeAssemblerContext context) {
844:
845:                QName serviceQName = context.getEndpoint().getServiceName();
846:                //TODO: not sure which of the two above will give the service name as specified in DD
847:                String serviceLocalName = serviceQName.getLocalPart();
848:                Container container = context.getEndpoint().getContainer();
849:
850:                Object ctxt = null;
851:                if (container != null) {
852:                    try {
853:                        final Class<?> contextClass = Class
854:                                .forName(SERVLET_CONTEXT_CLASSNAME);
855:                        ctxt = container.getSPI(contextClass);
856:                    } catch (ClassNotFoundException e) {
857:                        //log here that the ServletContext was not found
858:                    }
859:                }
860:                String serverName = "server";
861:                if (ctxt != null) {
862:
863:                    String serverConfig = "/WEB-INF/" + serverName + "_"
864:                            + "security_config.xml";
865:                    URL url = SecurityUtil.loadFromContext(serverConfig, ctxt);
866:
867:                    if (url == null) {
868:                        serverConfig = "/WEB-INF/" + serviceLocalName + "_"
869:                                + "security_config.xml";
870:                        url = SecurityUtil.loadFromContext(serverConfig, ctxt);
871:                    }
872:
873:                    if (url != null) {
874:                        return true;
875:                    }
876:                } else {
877:                    //this could be an EJB or JDK6 endpoint
878:                    //so let us try to locate the config from META-INF classpath
879:                    String serverConfig = "META-INF/" + serverName + "_"
880:                            + "security_config.xml";
881:                    URL url = SecurityUtil.loadFromClasspath(serverConfig);
882:                    if (url == null) {
883:                        serverConfig = "META-INF/" + serviceLocalName + "_"
884:                                + "security_config.xml";
885:                        url = SecurityUtil.loadFromClasspath(serverConfig);
886:                    }
887:
888:                    if (url != null) {
889:                        return true;
890:                    }
891:                }
892:                return false;
893:            }
894:
895:            private static Pipe initializeXWSSClientPipe(WSDLPort prt,
896:                    WSService svc, WSBinding bnd, Pipe nextP) {
897:                return new com.sun.xml.xwss.XWSSClientPipe(prt, svc, bnd, nextP);
898:            }
899:
900:            private static Pipe initializeXWSSServerPipe(WSEndpoint epoint,
901:                    WSDLPort prt, Pipe nextP) {
902:                return new com.sun.xml.xwss.XWSSServerPipe(epoint, prt, nextP);
903:            }
904:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.