Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.policy.jaxws; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.txw2.TypedXmlWriter; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.addressing.policy.AddressingPolicyMapConfigurator; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.WSBinding; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.api.policy.PolicyResolver; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.api.model.CheckedException; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.api.model.JavaMethod; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.api.model.SEIModel; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundFault; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLInput; |
aoqi@0 | 41 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage; |
aoqi@0 | 42 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation; |
aoqi@0 | 43 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput; |
aoqi@0 | 44 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort; |
aoqi@0 | 45 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType; |
aoqi@0 | 46 | import com.sun.xml.internal.ws.api.model.wsdl.WSDLService; |
aoqi@0 | 47 | import com.sun.xml.internal.ws.api.policy.ModelGenerator; |
aoqi@0 | 48 | import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension; |
aoqi@0 | 49 | import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGenExtnContext; |
aoqi@0 | 50 | import com.sun.xml.internal.ws.encoding.policy.MtomPolicyMapConfigurator; |
aoqi@0 | 51 | import com.sun.xml.internal.ws.policy.Policy; |
aoqi@0 | 52 | import com.sun.xml.internal.ws.policy.PolicyConstants; |
aoqi@0 | 53 | import com.sun.xml.internal.ws.policy.PolicyException; |
aoqi@0 | 54 | import com.sun.xml.internal.ws.policy.PolicyMap; |
aoqi@0 | 55 | import com.sun.xml.internal.ws.policy.PolicyMapExtender; |
aoqi@0 | 56 | import com.sun.xml.internal.ws.policy.PolicyMapUtil; |
aoqi@0 | 57 | import com.sun.xml.internal.ws.policy.PolicyMerger; |
aoqi@0 | 58 | import com.sun.xml.internal.ws.policy.PolicySubject; |
aoqi@0 | 59 | import com.sun.xml.internal.ws.policy.jaxws.spi.PolicyMapConfigurator; |
aoqi@0 | 60 | import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
aoqi@0 | 61 | import com.sun.xml.internal.ws.policy.sourcemodel.PolicyModelGenerator; |
aoqi@0 | 62 | import com.sun.xml.internal.ws.policy.sourcemodel.PolicyModelMarshaller; |
aoqi@0 | 63 | import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel; |
aoqi@0 | 64 | import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken; |
aoqi@0 | 65 | import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion; |
aoqi@0 | 66 | import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject; |
aoqi@0 | 67 | import com.sun.xml.internal.ws.resources.PolicyMessages; |
aoqi@0 | 68 | |
aoqi@0 | 69 | import java.lang.reflect.InvocationTargetException; |
aoqi@0 | 70 | import java.lang.reflect.Method; |
aoqi@0 | 71 | import java.util.Arrays; |
aoqi@0 | 72 | import java.util.Collection; |
aoqi@0 | 73 | import java.util.HashSet; |
aoqi@0 | 74 | import java.util.LinkedList; |
aoqi@0 | 75 | import java.util.Set; |
aoqi@0 | 76 | import javax.xml.namespace.QName; |
aoqi@0 | 77 | import javax.xml.ws.WebServiceException; |
aoqi@0 | 78 | |
aoqi@0 | 79 | /** |
aoqi@0 | 80 | * Marshals the contents of a policy map to WSDL. |
aoqi@0 | 81 | * |
aoqi@0 | 82 | * @author Jakub Podlesak (jakub.podlesak at sun.com) |
aoqi@0 | 83 | * @author Fabian Ritzmann |
aoqi@0 | 84 | */ |
aoqi@0 | 85 | public class PolicyWSDLGeneratorExtension extends WSDLGeneratorExtension { |
aoqi@0 | 86 | |
aoqi@0 | 87 | static enum ScopeType { |
aoqi@0 | 88 | |
aoqi@0 | 89 | SERVICE, |
aoqi@0 | 90 | ENDPOINT, |
aoqi@0 | 91 | OPERATION, |
aoqi@0 | 92 | INPUT_MESSAGE, |
aoqi@0 | 93 | OUTPUT_MESSAGE, |
aoqi@0 | 94 | FAULT_MESSAGE |
aoqi@0 | 95 | } |
aoqi@0 | 96 | private final static PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyWSDLGeneratorExtension.class); |
aoqi@0 | 97 | private PolicyMap policyMap; |
aoqi@0 | 98 | private SEIModel seiModel; |
aoqi@0 | 99 | private final Collection<PolicySubject> subjects = new LinkedList<PolicySubject>(); |
aoqi@0 | 100 | private final PolicyModelMarshaller marshaller = PolicyModelMarshaller.getXmlMarshaller(true); |
aoqi@0 | 101 | private final PolicyMerger merger = PolicyMerger.getMerger(); |
aoqi@0 | 102 | |
aoqi@0 | 103 | @Override |
aoqi@0 | 104 | public void start(final WSDLGenExtnContext context) { |
aoqi@0 | 105 | LOGGER.entering(); |
aoqi@0 | 106 | try { |
aoqi@0 | 107 | this.seiModel = context.getModel(); |
aoqi@0 | 108 | |
aoqi@0 | 109 | final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators(); |
aoqi@0 | 110 | final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length]; |
aoqi@0 | 111 | for (int i = 0; i < policyMapConfigurators.length; i++) { |
aoqi@0 | 112 | extenders[i] = PolicyMapExtender.createPolicyMapExtender(); |
aoqi@0 | 113 | } |
aoqi@0 | 114 | // Read policy config file |
aoqi@0 | 115 | policyMap = PolicyResolverFactory.create().resolve( |
aoqi@0 | 116 | new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders)); |
aoqi@0 | 117 | |
aoqi@0 | 118 | if (policyMap == null) { |
aoqi@0 | 119 | LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP()); |
aoqi@0 | 120 | policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders)); |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | final WSBinding binding = context.getBinding(); |
aoqi@0 | 124 | try { |
aoqi@0 | 125 | final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>(); |
aoqi@0 | 126 | for (int i = 0; i < policyMapConfigurators.length; i++) { |
aoqi@0 | 127 | policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding)); |
aoqi@0 | 128 | extenders[i].disconnect(); |
aoqi@0 | 129 | } |
aoqi@0 | 130 | PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName()); |
aoqi@0 | 131 | } catch (PolicyException e) { |
aoqi@0 | 132 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e)); |
aoqi@0 | 133 | } |
aoqi@0 | 134 | final TypedXmlWriter root = context.getRoot(); |
aoqi@0 | 135 | root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix()); |
aoqi@0 | 136 | root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix()); |
aoqi@0 | 137 | root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX); |
aoqi@0 | 138 | |
aoqi@0 | 139 | } finally { |
aoqi@0 | 140 | LOGGER.exiting(); |
aoqi@0 | 141 | } |
aoqi@0 | 142 | } |
aoqi@0 | 143 | |
aoqi@0 | 144 | @Override |
aoqi@0 | 145 | public void addDefinitionsExtension(final TypedXmlWriter definitions) { |
aoqi@0 | 146 | try { |
aoqi@0 | 147 | LOGGER.entering(); |
aoqi@0 | 148 | if (policyMap == null) { |
aoqi@0 | 149 | LOGGER.fine(PolicyMessages.WSP_1009_NOT_MARSHALLING_ANY_POLICIES_POLICY_MAP_IS_NULL()); |
aoqi@0 | 150 | } else { |
aoqi@0 | 151 | subjects.addAll(policyMap.getPolicySubjects()); |
aoqi@0 | 152 | final PolicyModelGenerator generator = ModelGenerator.getGenerator(); |
aoqi@0 | 153 | Set<String> policyIDsOrNamesWritten = new HashSet<String>(); |
aoqi@0 | 154 | for (PolicySubject subject : subjects) { |
aoqi@0 | 155 | if (subject.getSubject() == null) { |
aoqi@0 | 156 | LOGGER.fine(PolicyMessages.WSP_1008_NOT_MARSHALLING_WSDL_SUBJ_NULL(subject)); |
aoqi@0 | 157 | } else { |
aoqi@0 | 158 | final Policy policy; |
aoqi@0 | 159 | try { |
aoqi@0 | 160 | policy = subject.getEffectivePolicy(merger); |
aoqi@0 | 161 | } catch (PolicyException e) { |
aoqi@0 | 162 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e)); |
aoqi@0 | 163 | } |
aoqi@0 | 164 | if ((null == policy.getIdOrName()) || (policyIDsOrNamesWritten.contains(policy.getIdOrName()))) { |
aoqi@0 | 165 | LOGGER.fine(PolicyMessages.WSP_1016_POLICY_ID_NULL_OR_DUPLICATE(policy)); |
aoqi@0 | 166 | } else { |
aoqi@0 | 167 | try { |
aoqi@0 | 168 | final PolicySourceModel policyInfoset = generator.translate(policy); |
aoqi@0 | 169 | marshaller.marshal(policyInfoset, definitions); |
aoqi@0 | 170 | } catch (PolicyException e) { |
aoqi@0 | 171 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1018_FAILED_TO_MARSHALL_POLICY(policy.getIdOrName()), e)); |
aoqi@0 | 172 | } |
aoqi@0 | 173 | policyIDsOrNamesWritten.add(policy.getIdOrName()); |
aoqi@0 | 174 | } |
aoqi@0 | 175 | } |
aoqi@0 | 176 | } |
aoqi@0 | 177 | } |
aoqi@0 | 178 | } finally { |
aoqi@0 | 179 | LOGGER.exiting(); |
aoqi@0 | 180 | } |
aoqi@0 | 181 | } |
aoqi@0 | 182 | |
aoqi@0 | 183 | @Override |
aoqi@0 | 184 | public void addServiceExtension(final TypedXmlWriter service) { |
aoqi@0 | 185 | LOGGER.entering(); |
aoqi@0 | 186 | final String serviceName = (null == seiModel) ? null : seiModel.getServiceQName().getLocalPart(); |
aoqi@0 | 187 | selectAndProcessSubject(service, WSDLService.class, ScopeType.SERVICE, serviceName); |
aoqi@0 | 188 | LOGGER.exiting(); |
aoqi@0 | 189 | } |
aoqi@0 | 190 | |
aoqi@0 | 191 | @Override |
aoqi@0 | 192 | public void addPortExtension(final TypedXmlWriter port) { |
aoqi@0 | 193 | LOGGER.entering(); |
aoqi@0 | 194 | final String portName = (null == seiModel) ? null : seiModel.getPortName().getLocalPart(); |
aoqi@0 | 195 | selectAndProcessSubject(port, WSDLPort.class, ScopeType.ENDPOINT, portName); |
aoqi@0 | 196 | LOGGER.exiting(); |
aoqi@0 | 197 | } |
aoqi@0 | 198 | |
aoqi@0 | 199 | @Override |
aoqi@0 | 200 | public void addPortTypeExtension(final TypedXmlWriter portType) { |
aoqi@0 | 201 | LOGGER.entering(); |
aoqi@0 | 202 | final String portTypeName = (null == seiModel) ? null : seiModel.getPortTypeName().getLocalPart(); |
aoqi@0 | 203 | selectAndProcessSubject(portType, WSDLPortType.class, ScopeType.ENDPOINT, portTypeName); |
aoqi@0 | 204 | LOGGER.exiting(); |
aoqi@0 | 205 | } |
aoqi@0 | 206 | |
aoqi@0 | 207 | @Override |
aoqi@0 | 208 | public void addBindingExtension(final TypedXmlWriter binding) { |
aoqi@0 | 209 | LOGGER.entering(); |
aoqi@0 | 210 | final QName bindingName = (null == seiModel) ? null : seiModel.getBoundPortTypeName(); |
aoqi@0 | 211 | selectAndProcessBindingSubject(binding, WSDLBoundPortType.class, ScopeType.ENDPOINT, bindingName); |
aoqi@0 | 212 | LOGGER.exiting(); |
aoqi@0 | 213 | } |
aoqi@0 | 214 | |
aoqi@0 | 215 | @Override |
aoqi@0 | 216 | public void addOperationExtension(final TypedXmlWriter operation, final JavaMethod method) { |
aoqi@0 | 217 | LOGGER.entering(); |
aoqi@0 | 218 | selectAndProcessSubject(operation, WSDLOperation.class, ScopeType.OPERATION, (String)null); |
aoqi@0 | 219 | LOGGER.exiting(); |
aoqi@0 | 220 | } |
aoqi@0 | 221 | |
aoqi@0 | 222 | @Override |
aoqi@0 | 223 | public void addBindingOperationExtension(final TypedXmlWriter operation, final JavaMethod method) { |
aoqi@0 | 224 | LOGGER.entering(); |
aoqi@0 | 225 | final QName operationName = (method == null) ? null : new QName(method.getOwner().getTargetNamespace(), method.getOperationName()); |
aoqi@0 | 226 | selectAndProcessBindingSubject(operation, WSDLBoundOperation.class, ScopeType.OPERATION, operationName); |
aoqi@0 | 227 | LOGGER.exiting(); |
aoqi@0 | 228 | } |
aoqi@0 | 229 | |
aoqi@0 | 230 | @Override |
aoqi@0 | 231 | public void addInputMessageExtension(final TypedXmlWriter message, final JavaMethod method) { |
aoqi@0 | 232 | LOGGER.entering(); |
aoqi@0 | 233 | final String messageName = (null == method) ? null : method.getRequestMessageName(); |
aoqi@0 | 234 | selectAndProcessSubject(message, WSDLMessage.class, ScopeType.INPUT_MESSAGE, messageName); |
aoqi@0 | 235 | LOGGER.exiting(); |
aoqi@0 | 236 | } |
aoqi@0 | 237 | |
aoqi@0 | 238 | @Override |
aoqi@0 | 239 | public void addOutputMessageExtension(final TypedXmlWriter message, final JavaMethod method) { |
aoqi@0 | 240 | LOGGER.entering(); |
aoqi@0 | 241 | final String messageName = (null == method) ? null : method.getResponseMessageName(); |
aoqi@0 | 242 | selectAndProcessSubject(message, WSDLMessage.class, ScopeType.OUTPUT_MESSAGE, messageName); |
aoqi@0 | 243 | LOGGER.exiting(); |
aoqi@0 | 244 | } |
aoqi@0 | 245 | |
aoqi@0 | 246 | @Override |
aoqi@0 | 247 | public void addFaultMessageExtension(final TypedXmlWriter message, final JavaMethod method, final CheckedException exception) { |
aoqi@0 | 248 | LOGGER.entering(); |
aoqi@0 | 249 | final String messageName = (null == exception) ? null : exception.getMessageName(); |
aoqi@0 | 250 | selectAndProcessSubject(message, WSDLMessage.class, ScopeType.FAULT_MESSAGE, messageName); |
aoqi@0 | 251 | LOGGER.exiting(); |
aoqi@0 | 252 | } |
aoqi@0 | 253 | |
aoqi@0 | 254 | @Override |
aoqi@0 | 255 | public void addOperationInputExtension(final TypedXmlWriter input, final JavaMethod method) { |
aoqi@0 | 256 | LOGGER.entering(); |
aoqi@0 | 257 | final String messageName = (null == method) ? null : method.getRequestMessageName(); |
aoqi@0 | 258 | selectAndProcessSubject(input, WSDLInput.class, ScopeType.INPUT_MESSAGE, messageName); |
aoqi@0 | 259 | LOGGER.exiting(); |
aoqi@0 | 260 | } |
aoqi@0 | 261 | |
aoqi@0 | 262 | @Override |
aoqi@0 | 263 | public void addOperationOutputExtension(final TypedXmlWriter output, final JavaMethod method) { |
aoqi@0 | 264 | LOGGER.entering(); |
aoqi@0 | 265 | final String messageName = (null == method) ? null : method.getResponseMessageName(); |
aoqi@0 | 266 | selectAndProcessSubject(output, WSDLOutput.class, ScopeType.OUTPUT_MESSAGE, messageName); |
aoqi@0 | 267 | LOGGER.exiting(); |
aoqi@0 | 268 | } |
aoqi@0 | 269 | |
aoqi@0 | 270 | @Override |
aoqi@0 | 271 | public void addOperationFaultExtension(final TypedXmlWriter fault, final JavaMethod method, final CheckedException exception) { |
aoqi@0 | 272 | LOGGER.entering(); |
aoqi@0 | 273 | final String messageName = (null == exception) ? null : exception.getMessageName(); |
aoqi@0 | 274 | selectAndProcessSubject(fault, WSDLFault.class, ScopeType.FAULT_MESSAGE, messageName); |
aoqi@0 | 275 | LOGGER.exiting(); |
aoqi@0 | 276 | } |
aoqi@0 | 277 | |
aoqi@0 | 278 | @Override |
aoqi@0 | 279 | public void addBindingOperationInputExtension(final TypedXmlWriter input, final JavaMethod method) { |
aoqi@0 | 280 | LOGGER.entering(); |
aoqi@0 | 281 | final QName operationName = new QName(method.getOwner().getTargetNamespace(), method.getOperationName()); |
aoqi@0 | 282 | selectAndProcessBindingSubject(input, WSDLBoundOperation.class, ScopeType.INPUT_MESSAGE, operationName); |
aoqi@0 | 283 | LOGGER.exiting(); |
aoqi@0 | 284 | } |
aoqi@0 | 285 | |
aoqi@0 | 286 | @Override |
aoqi@0 | 287 | public void addBindingOperationOutputExtension(final TypedXmlWriter output, final JavaMethod method) { |
aoqi@0 | 288 | LOGGER.entering(); |
aoqi@0 | 289 | final QName operationName = new QName(method.getOwner().getTargetNamespace(), method.getOperationName()); |
aoqi@0 | 290 | selectAndProcessBindingSubject(output, WSDLBoundOperation.class, ScopeType.OUTPUT_MESSAGE, operationName); |
aoqi@0 | 291 | LOGGER.exiting(); |
aoqi@0 | 292 | } |
aoqi@0 | 293 | |
aoqi@0 | 294 | @Override |
aoqi@0 | 295 | public void addBindingOperationFaultExtension(final TypedXmlWriter writer, final JavaMethod method, final CheckedException exception) { |
aoqi@0 | 296 | LOGGER.entering(writer, method, exception); |
aoqi@0 | 297 | if (subjects != null) { |
aoqi@0 | 298 | for (PolicySubject subject : subjects) { // iterate over all subjects in policy map |
aoqi@0 | 299 | if (this.policyMap.isFaultMessageSubject(subject)) { |
aoqi@0 | 300 | final Object concreteSubject = subject.getSubject(); |
aoqi@0 | 301 | if (concreteSubject != null) { |
aoqi@0 | 302 | final String exceptionName = exception == null ? null : exception.getMessageName(); |
aoqi@0 | 303 | if (exceptionName == null) { // no name provided to check |
aoqi@0 | 304 | writePolicyOrReferenceIt(subject, writer); |
aoqi@0 | 305 | } |
aoqi@0 | 306 | if (WSDLBoundFaultContainer.class.isInstance(concreteSubject)) { // is it our class? |
aoqi@0 | 307 | WSDLBoundFaultContainer faultContainer = (WSDLBoundFaultContainer) concreteSubject; |
aoqi@0 | 308 | WSDLBoundFault fault = faultContainer.getBoundFault(); |
aoqi@0 | 309 | WSDLBoundOperation operation = faultContainer.getBoundOperation(); |
aoqi@0 | 310 | if (exceptionName.equals(fault.getName()) && |
aoqi@0 | 311 | operation.getName().getLocalPart().equals(method.getOperationName())) { |
aoqi@0 | 312 | writePolicyOrReferenceIt(subject, writer); |
aoqi@0 | 313 | } |
aoqi@0 | 314 | } |
aoqi@0 | 315 | else if (WsdlBindingSubject.class.isInstance(concreteSubject)) { |
aoqi@0 | 316 | WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) concreteSubject; |
aoqi@0 | 317 | if ((wsdlSubject.getMessageType() == WsdlBindingSubject.WsdlMessageType.FAULT) && |
aoqi@0 | 318 | exception.getOwner().getTargetNamespace().equals(wsdlSubject.getName().getNamespaceURI()) && |
aoqi@0 | 319 | exceptionName.equals(wsdlSubject.getName().getLocalPart())) { |
aoqi@0 | 320 | writePolicyOrReferenceIt(subject, writer); |
aoqi@0 | 321 | } |
aoqi@0 | 322 | } |
aoqi@0 | 323 | } |
aoqi@0 | 324 | } |
aoqi@0 | 325 | } |
aoqi@0 | 326 | } |
aoqi@0 | 327 | LOGGER.exiting(); |
aoqi@0 | 328 | } |
aoqi@0 | 329 | |
aoqi@0 | 330 | /** |
aoqi@0 | 331 | * This method should only be invoked by interface methods that deal with WSDL binding because they |
aoqi@0 | 332 | * may use the QName of the WSDL binding element as PolicySubject instead of a WSDL object. |
aoqi@0 | 333 | * |
aoqi@0 | 334 | * @param xmlWriter A TypedXmlWriter. |
aoqi@0 | 335 | * @param clazz The policy subject. |
aoqi@0 | 336 | * @param scopeType The WSDL scope. |
aoqi@0 | 337 | * @param bindingName The WSDL binding name. |
aoqi@0 | 338 | */ |
aoqi@0 | 339 | private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) { |
aoqi@0 | 340 | LOGGER.entering(xmlWriter, clazz, scopeType, bindingName); |
aoqi@0 | 341 | if (bindingName == null) { |
aoqi@0 | 342 | selectAndProcessSubject(xmlWriter, clazz, scopeType, (String) null); |
aoqi@0 | 343 | } else { |
aoqi@0 | 344 | if (subjects != null) { |
aoqi@0 | 345 | for (PolicySubject subject : subjects) { |
aoqi@0 | 346 | if (bindingName.equals(subject.getSubject())) { |
aoqi@0 | 347 | writePolicyOrReferenceIt(subject, xmlWriter); |
aoqi@0 | 348 | } |
aoqi@0 | 349 | } |
aoqi@0 | 350 | } |
aoqi@0 | 351 | selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName.getLocalPart()); |
aoqi@0 | 352 | } |
aoqi@0 | 353 | LOGGER.exiting(); |
aoqi@0 | 354 | } |
aoqi@0 | 355 | |
aoqi@0 | 356 | private void selectAndProcessBindingSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) { |
aoqi@0 | 357 | LOGGER.entering(xmlWriter, clazz, scopeType, bindingName); |
aoqi@0 | 358 | if ((subjects != null) && (bindingName != null)) { |
aoqi@0 | 359 | for (PolicySubject subject : subjects) { |
aoqi@0 | 360 | if (subject.getSubject() instanceof WsdlBindingSubject) { |
aoqi@0 | 361 | final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) subject.getSubject(); |
aoqi@0 | 362 | if (bindingName.equals(wsdlSubject.getName())) { |
aoqi@0 | 363 | writePolicyOrReferenceIt(subject, xmlWriter); |
aoqi@0 | 364 | } |
aoqi@0 | 365 | } |
aoqi@0 | 366 | } |
aoqi@0 | 367 | } |
aoqi@0 | 368 | selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName); |
aoqi@0 | 369 | LOGGER.exiting(); |
aoqi@0 | 370 | } |
aoqi@0 | 371 | |
aoqi@0 | 372 | private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final String wsdlName) { |
aoqi@0 | 373 | LOGGER.entering(xmlWriter, clazz, scopeType, wsdlName); |
aoqi@0 | 374 | if (subjects != null) { |
aoqi@0 | 375 | for (PolicySubject subject : subjects) { // iterate over all subjects in policy map |
aoqi@0 | 376 | if (isCorrectType(policyMap, subject, scopeType)) { |
aoqi@0 | 377 | final Object concreteSubject = subject.getSubject(); |
aoqi@0 | 378 | if (concreteSubject != null && clazz.isInstance(concreteSubject)) { // is it our class? |
aoqi@0 | 379 | if (null == wsdlName) { // no name provided to check |
aoqi@0 | 380 | writePolicyOrReferenceIt(subject, xmlWriter); |
aoqi@0 | 381 | } else { |
aoqi@0 | 382 | try { |
aoqi@0 | 383 | final Method getNameMethod = clazz.getDeclaredMethod("getName"); |
aoqi@0 | 384 | if (stringEqualsToStringOrQName(wsdlName, getNameMethod.invoke(concreteSubject))) { |
aoqi@0 | 385 | writePolicyOrReferenceIt(subject, xmlWriter); |
aoqi@0 | 386 | } |
aoqi@0 | 387 | } catch (NoSuchMethodException e) { |
aoqi@0 | 388 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e)); |
aoqi@0 | 389 | } catch (IllegalAccessException e) { |
aoqi@0 | 390 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e)); |
aoqi@0 | 391 | } catch (InvocationTargetException e) { |
aoqi@0 | 392 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e)); |
aoqi@0 | 393 | } |
aoqi@0 | 394 | } |
aoqi@0 | 395 | } |
aoqi@0 | 396 | } |
aoqi@0 | 397 | } |
aoqi@0 | 398 | } |
aoqi@0 | 399 | LOGGER.exiting(); |
aoqi@0 | 400 | } |
aoqi@0 | 401 | |
aoqi@0 | 402 | private static boolean isCorrectType(final PolicyMap map, final PolicySubject subject, final ScopeType type) { |
aoqi@0 | 403 | switch (type) { |
aoqi@0 | 404 | case OPERATION: |
aoqi@0 | 405 | return !(map.isInputMessageSubject(subject) || map.isOutputMessageSubject(subject) || map.isFaultMessageSubject(subject)); |
aoqi@0 | 406 | case INPUT_MESSAGE: |
aoqi@0 | 407 | return map.isInputMessageSubject(subject); |
aoqi@0 | 408 | case OUTPUT_MESSAGE: |
aoqi@0 | 409 | return map.isOutputMessageSubject(subject); |
aoqi@0 | 410 | case FAULT_MESSAGE: |
aoqi@0 | 411 | return map.isFaultMessageSubject(subject); |
aoqi@0 | 412 | default: |
aoqi@0 | 413 | return true; |
aoqi@0 | 414 | } |
aoqi@0 | 415 | } |
aoqi@0 | 416 | |
aoqi@0 | 417 | private boolean stringEqualsToStringOrQName(final String first, final Object second) { |
aoqi@0 | 418 | return (second instanceof QName) ? first.equals(((QName) second).getLocalPart()) : first.equals(second); |
aoqi@0 | 419 | } |
aoqi@0 | 420 | |
aoqi@0 | 421 | /** |
aoqi@0 | 422 | * Adds a PolicyReference element that points to the policy of the element, |
aoqi@0 | 423 | * if the policy does not have any id or name. Writes policy inside the element otherwise. |
aoqi@0 | 424 | * |
aoqi@0 | 425 | * @param subject |
aoqi@0 | 426 | * PolicySubject to be referenced or marshalled |
aoqi@0 | 427 | * @param writer |
aoqi@0 | 428 | * A TXW on to which we shall add the PolicyReference |
aoqi@0 | 429 | */ |
aoqi@0 | 430 | private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) { |
aoqi@0 | 431 | final Policy policy; |
aoqi@0 | 432 | try { |
aoqi@0 | 433 | policy = subject.getEffectivePolicy(merger); |
aoqi@0 | 434 | } catch (PolicyException e) { |
aoqi@0 | 435 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e)); |
aoqi@0 | 436 | } |
aoqi@0 | 437 | if (policy != null) { |
aoqi@0 | 438 | if (null == policy.getIdOrName()) { |
aoqi@0 | 439 | final PolicyModelGenerator generator = ModelGenerator.getGenerator(); |
aoqi@0 | 440 | try { |
aoqi@0 | 441 | final PolicySourceModel policyInfoset = generator.translate(policy); |
aoqi@0 | 442 | marshaller.marshal(policyInfoset, writer); |
aoqi@0 | 443 | } catch (PolicyException pe) { |
aoqi@0 | 444 | throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe)); |
aoqi@0 | 445 | } |
aoqi@0 | 446 | } else { |
aoqi@0 | 447 | final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class); |
aoqi@0 | 448 | policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName()); |
aoqi@0 | 449 | } |
aoqi@0 | 450 | } |
aoqi@0 | 451 | } |
aoqi@0 | 452 | |
aoqi@0 | 453 | private PolicyMapConfigurator[] loadConfigurators() { |
aoqi@0 | 454 | final Collection<PolicyMapConfigurator> configurators = new LinkedList<PolicyMapConfigurator>(); |
aoqi@0 | 455 | |
aoqi@0 | 456 | // Add map configurators that are already built into JAX-WS |
aoqi@0 | 457 | configurators.add(new AddressingPolicyMapConfigurator()); |
aoqi@0 | 458 | configurators.add(new MtomPolicyMapConfigurator()); |
aoqi@0 | 459 | |
aoqi@0 | 460 | // Dynamically discover remaining map configurators |
aoqi@0 | 461 | PolicyUtil.addServiceProviders(configurators, PolicyMapConfigurator.class); |
aoqi@0 | 462 | |
aoqi@0 | 463 | return configurators.toArray(new PolicyMapConfigurator[configurators.size()]); |
aoqi@0 | 464 | } |
aoqi@0 | 465 | |
aoqi@0 | 466 | } |