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.policy.jaxws.client;
038:
039: import com.sun.xml.ws.api.WSFeatureList;
040: import com.sun.xml.ws.api.client.ServiceInterceptor;
041: import com.sun.xml.ws.api.client.WSPortInfo;
042: import com.sun.xml.ws.api.model.wsdl.WSDLModel;
043: import com.sun.xml.ws.api.model.wsdl.WSDLPort;
044: import com.sun.xml.ws.api.model.wsdl.WSDLService;
045: import com.sun.xml.ws.policy.PolicyConstants;
046: import com.sun.xml.ws.policy.PolicyException;
047: import com.sun.xml.ws.policy.PolicyMap;
048: import com.sun.xml.ws.policy.jaxws.PolicyConfigParser;
049: import com.sun.xml.ws.policy.jaxws.WSDLPolicyMapWrapper;
050: import com.sun.xml.ws.policy.jaxws.privateutil.LocalizationMessages;
051: import com.sun.xml.ws.policy.jaxws.spi.ModelConfiguratorProvider;
052: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
053: import com.sun.xml.ws.policy.privateutil.PolicyUtils;
054: import java.util.LinkedList;
055: import java.util.List;
056: import javax.xml.namespace.QName;
057: import javax.xml.ws.WebServiceException;
058: import javax.xml.ws.WebServiceFeature;
059:
060: public class PolicyServiceInterceptor extends ServiceInterceptor {
061: private static final PolicyLogger LOGGER = PolicyLogger
062: .getLogger(PolicyServiceInterceptor.class);
063:
064: public List<WebServiceFeature> preCreateBinding(
065: final WSPortInfo port,
066: final java.lang.Class<?> serviceEndpointInterface,
067: final WSFeatureList defaultFeatures) {
068: LOGGER
069: .entering(port, serviceEndpointInterface,
070: defaultFeatures);
071: final LinkedList<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
072: try {
073: final WSDLPort wsdlPort = port.getPort();
074: // We only need to read the client config if the server WSDL was not parsed
075: if (wsdlPort == null) {
076: final WSDLModel clientModel;
077: try {
078: clientModel = PolicyConfigParser
079: .parseModel(
080: PolicyConstants.CLIENT_CONFIGURATION_IDENTIFIER,
081: null);
082: } catch (PolicyException pe) {
083: throw LOGGER
084: .logSevereException(new WebServiceException(
085: LocalizationMessages
086: .WSP_1017_ERROR_WHILE_PROCESSING_CLIENT_CONFIG(),
087: pe));
088: }
089:
090: if (clientModel != null) {
091: final WSDLPolicyMapWrapper policyMapWrapper = clientModel
092: .getExtension(WSDLPolicyMapWrapper.class);
093: if (policyMapWrapper == null) {
094: LOGGER.config(LocalizationMessages
095: .WSP_1022_POLICY_MAP_NOT_IN_MODEL());
096: } else {
097: LOGGER
098: .config(LocalizationMessages
099: .WSP_1024_INVOKING_CLIENT_POLICY_ALTERNATIVE_SELECTION());
100: try {
101: policyMapWrapper.doAlternativeSelection();
102: } catch (PolicyException e) {
103: throw LOGGER
104: .logSevereException(new WebServiceException(
105: LocalizationMessages
106: .WSP_1003_VALID_POLICY_ALTERNATIVE_NOT_FOUND(),
107: e));
108: }
109:
110: final PolicyMap map = policyMapWrapper
111: .getPolicyMap();
112:
113: try {
114: for (ModelConfiguratorProvider configurator : PolicyUtils.ServiceProvider
115: .load(ModelConfiguratorProvider.class)) {
116: configurator
117: .configure(clientModel, map);
118: }
119: } catch (PolicyException e) {
120: throw LOGGER
121: .logSevereException(new WebServiceException(
122: LocalizationMessages
123: .WSP_1023_ERROR_WHILE_CONFIGURING_MODEL(),
124: e));
125: }
126: // We can not read the features directly from port.getPort() because in the
127: // case of dispatch that object may be null.
128: addFeatures(features, clientModel, port
129: .getPortName());
130: features.add(new PolicyFeature(map,
131: clientModel, port));
132: }
133: }
134: }
135:
136: return features;
137: } finally {
138: LOGGER.exiting(features);
139: }
140: }
141:
142: /**
143: * Add the features in the WSDL model for the given port to the list
144: */
145: private void addFeatures(final List<WebServiceFeature> features,
146: final WSDLModel model, final QName portName) {
147: LOGGER.entering(features, model, portName);
148: try {
149: for (WSDLService service : model.getServices().values()) {
150: final WSDLPort port = service.get(portName);
151: if (port != null) {
152: addFeatureListToList(features, port.getFeatures());
153: addFeatureListToList(features, port.getBinding()
154: .getFeatures());
155: break;
156: }
157: }
158: } finally {
159: LOGGER.exiting(features);
160: }
161: }
162:
163: private void addFeatureListToList(
164: final List<WebServiceFeature> list,
165: final WSFeatureList featureList) {
166: for (WebServiceFeature feature : featureList) {
167: list.add(feature);
168: }
169: }
170: }
|