feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.api.policy.ModelTranslator;
|
||||
import com.sun.xml.internal.ws.policy.Policy;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.resources.PolicyMessages;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
abstract class BuilderHandler{
|
||||
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(BuilderHandler.class);
|
||||
|
||||
Map<String,PolicySourceModel> policyStore;
|
||||
Collection<String> policyURIs;
|
||||
Object policySubject;
|
||||
|
||||
/**
|
||||
* Creates a new instance of BuilderHandler
|
||||
*/
|
||||
BuilderHandler(Collection<String> policyURIs, Map<String,PolicySourceModel> policyStore, Object policySubject) {
|
||||
this.policyStore = policyStore;
|
||||
this.policyURIs = policyURIs;
|
||||
this.policySubject = policySubject;
|
||||
}
|
||||
|
||||
final void populate(final PolicyMapExtender policyMapExtender) throws PolicyException {
|
||||
if (null == policyMapExtender) {
|
||||
throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1006_POLICY_MAP_EXTENDER_CAN_NOT_BE_NULL()));
|
||||
}
|
||||
|
||||
doPopulate(policyMapExtender);
|
||||
}
|
||||
|
||||
protected abstract void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException;
|
||||
|
||||
final Collection<Policy> getPolicies() throws PolicyException {
|
||||
if (null == policyURIs) {
|
||||
throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1004_POLICY_URIS_CAN_NOT_BE_NULL()));
|
||||
}
|
||||
if (null == policyStore) {
|
||||
throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1010_NO_POLICIES_DEFINED()));
|
||||
}
|
||||
|
||||
final Collection<Policy> result = new ArrayList<Policy>(policyURIs.size());
|
||||
|
||||
for (String policyURI : policyURIs) {
|
||||
final PolicySourceModel sourceModel = policyStore.get(policyURI);
|
||||
if (sourceModel == null) {
|
||||
throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1005_POLICY_REFERENCE_DOES_NOT_EXIST(policyURI)));
|
||||
} else {
|
||||
result.add(ModelTranslator.getTranslator().translate(sourceModel));
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
final Collection<PolicySubject> getPolicySubjects() throws PolicyException {
|
||||
final Collection<Policy> policies = getPolicies();
|
||||
final Collection<PolicySubject> result = new ArrayList<PolicySubject>(policies.size());
|
||||
for (Policy policy : policies) {
|
||||
result.add(new PolicySubject(policySubject, policy));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
final class BuilderHandlerEndpointScope extends BuilderHandler{
|
||||
private final QName service;
|
||||
private final QName port;
|
||||
|
||||
/** Creates a new instance of WSDLServiceScopeBuilderHandler */
|
||||
BuilderHandlerEndpointScope(Collection<String> policyURIs, Map<String,PolicySourceModel> policyStore, Object policySubject, QName service, QName port) {
|
||||
|
||||
super(policyURIs, policyStore, policySubject);
|
||||
this.service = service;
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
protected void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException {
|
||||
final PolicyMapKey mapKey = PolicyMap.createWsdlEndpointScopeKey(service, port);
|
||||
for (PolicySubject subject : getPolicySubjects()) {
|
||||
policyMapExtender.putEndpointSubject(mapKey, subject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return (new StringBuffer(service.toString())).append(":").append(port.toString()).toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
final class BuilderHandlerMessageScope extends BuilderHandler{
|
||||
private final QName service;
|
||||
private final QName port;
|
||||
private final QName operation;
|
||||
private final QName message;
|
||||
private final Scope scope;
|
||||
|
||||
enum Scope{
|
||||
InputMessageScope,
|
||||
OutputMessageScope,
|
||||
FaultMessageScope,
|
||||
};
|
||||
|
||||
|
||||
/** Creates a new instance of WSDLServiceScopeBuilderHandler */
|
||||
BuilderHandlerMessageScope(
|
||||
Collection<String> policyURIs
|
||||
, Map<String,PolicySourceModel> policyStore
|
||||
, Object policySubject
|
||||
, Scope scope
|
||||
, QName service, QName port, QName operation, QName message) {
|
||||
|
||||
super(policyURIs, policyStore, policySubject);
|
||||
this.service = service;
|
||||
this.port = port;
|
||||
this.operation = operation;
|
||||
this.scope = scope;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiple bound operations may refer to the same fault messages. This would result
|
||||
* in multiple builder handlers referring to the same policies. This method allows
|
||||
* to sort out these duplicate handlers.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof BuilderHandlerMessageScope)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final BuilderHandlerMessageScope that = (BuilderHandlerMessageScope) obj;
|
||||
boolean result = true;
|
||||
|
||||
result = result && ((this.policySubject == null) ? ((that.policySubject == null) ? true : false) :this.policySubject.equals(that.policySubject));
|
||||
result = result && ((this.scope == null) ? ((that.scope == null) ? true : false) :this.scope.equals(that.scope));
|
||||
result = result && ((this.message == null) ? ((that.message == null) ? true : false) :this.message.equals(that.message));
|
||||
if (this.scope != Scope.FaultMessageScope) {
|
||||
result = result && ((this.service == null) ? ((that.service == null) ? true : false) :this.service.equals(that.service));
|
||||
result = result && ((this.port == null) ? ((that.port == null) ? true : false) :this.port.equals(that.port));
|
||||
result = result && ((this.operation == null) ? ((that.operation == null) ? true : false) :this.operation.equals(that.operation));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hashCode = 19;
|
||||
hashCode = 31 * hashCode + (policySubject == null ? 0 : policySubject.hashCode());
|
||||
hashCode = 31 * hashCode + (message == null ? 0 : message.hashCode());
|
||||
hashCode = 31 * hashCode + (scope == null ? 0 : scope.hashCode());
|
||||
if (scope != Scope.FaultMessageScope) {
|
||||
hashCode = 31 * hashCode + (service == null ? 0 : service.hashCode());
|
||||
hashCode = 31 * hashCode + (port == null ? 0 : port.hashCode());
|
||||
hashCode = 31 * hashCode + (operation == null ? 0 : operation.hashCode());
|
||||
}
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
protected void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException{
|
||||
PolicyMapKey mapKey;
|
||||
|
||||
if (Scope.FaultMessageScope == scope) {
|
||||
mapKey = PolicyMap.createWsdlFaultMessageScopeKey(service, port, operation, message);
|
||||
} else { // in|out msg scope
|
||||
mapKey = PolicyMap.createWsdlMessageScopeKey(service, port, operation);
|
||||
}
|
||||
|
||||
if (Scope.InputMessageScope == scope) {
|
||||
for (PolicySubject subject:getPolicySubjects()) {
|
||||
policyMapExtender.putInputMessageSubject(mapKey, subject);
|
||||
}
|
||||
} else if (Scope.OutputMessageScope == scope) {
|
||||
for (PolicySubject subject:getPolicySubjects()) {
|
||||
policyMapExtender.putOutputMessageSubject(mapKey, subject);
|
||||
}
|
||||
} else if (Scope.FaultMessageScope == scope) {
|
||||
for (PolicySubject subject : getPolicySubjects()) {
|
||||
policyMapExtender.putFaultMessageSubject(mapKey, subject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
final class BuilderHandlerOperationScope extends BuilderHandler{
|
||||
private final QName service;
|
||||
private final QName port;
|
||||
private final QName operation;
|
||||
|
||||
/** Creates a new instance of WSDLServiceScopeBuilderHandler */
|
||||
BuilderHandlerOperationScope(
|
||||
Collection<String> policyURIs
|
||||
, Map<String,PolicySourceModel> policyStore
|
||||
, Object policySubject
|
||||
, QName service, QName port, QName operation) {
|
||||
|
||||
super(policyURIs, policyStore, policySubject);
|
||||
this.service = service;
|
||||
this.port = port;
|
||||
this.operation = operation;
|
||||
}
|
||||
|
||||
protected void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException{
|
||||
final PolicyMapKey mapKey = PolicyMap.createWsdlOperationScopeKey(service, port, operation);
|
||||
for (PolicySubject subject : getPolicySubjects()) {
|
||||
policyMapExtender.putOperationSubject(mapKey, subject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
final class BuilderHandlerServiceScope extends BuilderHandler{
|
||||
private final QName service;
|
||||
|
||||
/**
|
||||
* Creates a new instance of BuilderHandlerServiceScope
|
||||
*/
|
||||
BuilderHandlerServiceScope(
|
||||
Collection<String> policyURIs, Map<String,PolicySourceModel> policyStore, Object policySubject, QName service) {
|
||||
|
||||
super(policyURIs, policyStore, policySubject);
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
protected void doPopulate(final PolicyMapExtender policyMapExtender) throws PolicyException{
|
||||
final PolicyMapKey mapKey = PolicyMap.createWsdlServiceScopeKey(service);
|
||||
for (PolicySubject subject : getPolicySubjects()) {
|
||||
policyMapExtender.putServiceSubject(mapKey, subject);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return service.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.api.policy.AlternativeSelector;
|
||||
import com.sun.xml.internal.ws.api.policy.PolicyResolver;
|
||||
import com.sun.xml.internal.ws.api.policy.ValidationProcessor;
|
||||
import com.sun.xml.internal.ws.policy.AssertionSet;
|
||||
import com.sun.xml.internal.ws.policy.EffectivePolicyModifier;
|
||||
import com.sun.xml.internal.ws.policy.Policy;
|
||||
import com.sun.xml.internal.ws.policy.PolicyAssertion;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.spi.PolicyAssertionValidator.Fitness;
|
||||
import com.sun.xml.internal.ws.resources.PolicyMessages;
|
||||
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* This default implementation runs the policy validators on the server side and
|
||||
* selects a policy alternative on the client side.
|
||||
*
|
||||
* @author Rama Pulavarthi
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
public class DefaultPolicyResolver implements PolicyResolver {
|
||||
|
||||
public PolicyMap resolve(ServerContext context) {
|
||||
PolicyMap map = context.getPolicyMap();
|
||||
if(map != null)
|
||||
validateServerPolicyMap(map);
|
||||
return map;
|
||||
}
|
||||
|
||||
public PolicyMap resolve(ClientContext context) {
|
||||
PolicyMap map = context.getPolicyMap();
|
||||
if(map != null)
|
||||
map = doAlternativeSelection(map);
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the PolicyMap has only single alternative in the scope.
|
||||
*
|
||||
* @param policyMap
|
||||
* PolicyMap that needs to be validated.
|
||||
*/
|
||||
private void validateServerPolicyMap(PolicyMap policyMap) {
|
||||
try {
|
||||
final ValidationProcessor validationProcessor = ValidationProcessor.getInstance();
|
||||
|
||||
for (Policy policy : policyMap) {
|
||||
|
||||
// TODO: here is a good place to check if the actual policy has only one alternative...
|
||||
|
||||
for (AssertionSet assertionSet : policy) {
|
||||
for (PolicyAssertion assertion : assertionSet) {
|
||||
Fitness validationResult = validationProcessor.validateServerSide(assertion);
|
||||
if (validationResult != Fitness.SUPPORTED) {
|
||||
throw new PolicyException(PolicyMessages.WSP_1015_SERVER_SIDE_ASSERTION_VALIDATION_FAILED(
|
||||
assertion.getName(),
|
||||
validationResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (PolicyException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a best alternative if there are multiple policy alternatives.
|
||||
*
|
||||
* @param policyMap
|
||||
* @return
|
||||
*/
|
||||
private PolicyMap doAlternativeSelection(PolicyMap policyMap) {
|
||||
final EffectivePolicyModifier modifier = EffectivePolicyModifier.createEffectivePolicyModifier();
|
||||
modifier.connect(policyMap);
|
||||
try {
|
||||
AlternativeSelector.doSelection(modifier);
|
||||
} catch (PolicyException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
return policyMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapMutator;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used for populating changes into PolicyMap. Once a PolicyMap is created
|
||||
* PolicyMapBuilder notifies all the registered WSPolicyBuilderHandler to populate
|
||||
* changes to the PolicyMap.
|
||||
*
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
*/
|
||||
class PolicyMapBuilder {
|
||||
/**
|
||||
* policyBuilders should contain list of registered PolicyBuilders
|
||||
*/
|
||||
private List<BuilderHandler> policyBuilders = new LinkedList<BuilderHandler>();
|
||||
|
||||
/**
|
||||
* Creates a new instance of PolicyMapBuilder
|
||||
*/
|
||||
PolicyMapBuilder() {
|
||||
// nothing to initialize
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers another builder, which has to be notified after a new
|
||||
* PolicyMap is created in order to populate it's changes.
|
||||
*
|
||||
*/
|
||||
void registerHandler(final BuilderHandler builder){
|
||||
if (null != builder) {
|
||||
policyBuilders.add(builder);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates all the registered PolicyBuilders and lets them populate
|
||||
* their changes into PolicyMap. Registers mutators given as a parameter
|
||||
* with the newly created map.
|
||||
*/
|
||||
PolicyMap getPolicyMap(final PolicyMapMutator... externalMutators) throws PolicyException{
|
||||
return getNewPolicyMap(externalMutators);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Iterates all the registered PolicyBuilders and lets them populate
|
||||
* their changes into PolicyMap. Registers mutators from collection given as a parameter
|
||||
* with the newly created map.
|
||||
*/
|
||||
private PolicyMap getNewPolicyMap(final PolicyMapMutator... externalMutators) throws PolicyException{
|
||||
final HashSet<PolicyMapMutator> mutators = new HashSet<PolicyMapMutator>();
|
||||
final PolicyMapExtender myExtender = PolicyMapExtender.createPolicyMapExtender();
|
||||
mutators.add(myExtender);
|
||||
if (null != externalMutators) {
|
||||
mutators.addAll(Arrays.asList(externalMutators));
|
||||
}
|
||||
final PolicyMap policyMap = PolicyMap.createPolicyMap(mutators);
|
||||
for(BuilderHandler builder : policyBuilders){
|
||||
builder.populate(myExtender);
|
||||
}
|
||||
return policyMap;
|
||||
}
|
||||
|
||||
void unregisterAll() {
|
||||
this.policyBuilders = null;
|
||||
}
|
||||
}
|
||||
136
jdkSrc/jdk8/com/sun/xml/internal/ws/policy/jaxws/PolicyUtil.java
Normal file
136
jdkSrc/jdk8/com/sun/xml/internal/ws/policy/jaxws/PolicyUtil.java
Normal file
@@ -0,0 +1,136 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.addressing.policy.AddressingFeatureConfigurator;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLModel;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
|
||||
import com.sun.xml.internal.ws.encoding.policy.FastInfosetFeatureConfigurator;
|
||||
import com.sun.xml.internal.ws.encoding.policy.MtomFeatureConfigurator;
|
||||
import com.sun.xml.internal.ws.encoding.policy.SelectOptimalEncodingFeatureConfigurator;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import com.sun.xml.internal.ws.policy.jaxws.spi.PolicyFeatureConfigurator;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
|
||||
import com.sun.xml.internal.ws.util.ServiceFinder;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.WebServiceFeature;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
/**
|
||||
* @author Rama Pulavarthi
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
public class PolicyUtil {
|
||||
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyUtil.class);
|
||||
private static final Collection<PolicyFeatureConfigurator> CONFIGURATORS =
|
||||
new LinkedList<PolicyFeatureConfigurator>();
|
||||
|
||||
static {
|
||||
// Add feature configurators that are already built into JAX-WS
|
||||
CONFIGURATORS.add(new AddressingFeatureConfigurator());
|
||||
CONFIGURATORS.add(new MtomFeatureConfigurator());
|
||||
CONFIGURATORS.add(new FastInfosetFeatureConfigurator());
|
||||
CONFIGURATORS.add(new SelectOptimalEncodingFeatureConfigurator());
|
||||
|
||||
// Dynamically discover remaining feature configurators
|
||||
addServiceProviders(CONFIGURATORS, PolicyFeatureConfigurator.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the dynamically discovered implementations for the given service class
|
||||
* to the given collection.
|
||||
*
|
||||
* @param <T> The type of the service class.
|
||||
* @param providers The discovered implementations are added to this collection.
|
||||
* @param service The service interface.
|
||||
*/
|
||||
public static <T> void addServiceProviders(Collection<T> providers, Class<T> service) {
|
||||
final Iterator<T> foundProviders = ServiceFinder.find(service).iterator();
|
||||
while (foundProviders.hasNext()) {
|
||||
providers.add(foundProviders.next());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through the ports in the WSDL model, for each policy in the policy
|
||||
* map that is attached at endpoint scope computes a list of corresponding
|
||||
* WebServiceFeatures and sets them on the port.
|
||||
*
|
||||
* @param model The WSDL model
|
||||
* @param policyMap The policy map
|
||||
* @throws PolicyException If the list of WebServiceFeatures could not be computed
|
||||
*/
|
||||
public static void configureModel(final WSDLModel model, PolicyMap policyMap) throws PolicyException {
|
||||
LOGGER.entering(model, policyMap);
|
||||
for (WSDLService service : model.getServices().values()) {
|
||||
for (WSDLPort port : service.getPorts()) {
|
||||
final Collection<WebServiceFeature> features = getPortScopedFeatures(policyMap, service.getName(), port.getName());
|
||||
for (WebServiceFeature feature : features) {
|
||||
port.addFeature(feature);
|
||||
port.getBinding().addFeature(feature);
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of features that correspond to the policies in the policy
|
||||
* map for a give port
|
||||
*
|
||||
* @param policyMap The service policies
|
||||
* @param serviceName The service name
|
||||
* @param portName The service port name
|
||||
* @return List of features for the given port corresponding to the policies in the map
|
||||
*/
|
||||
public static Collection<WebServiceFeature> getPortScopedFeatures(PolicyMap policyMap, QName serviceName, QName portName) {
|
||||
LOGGER.entering(policyMap, serviceName, portName);
|
||||
Collection<WebServiceFeature> features = new ArrayList<WebServiceFeature>();
|
||||
try {
|
||||
final PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(serviceName, portName);
|
||||
for (PolicyFeatureConfigurator configurator : CONFIGURATORS) {
|
||||
Collection<WebServiceFeature> additionalFeatures = configurator.getFeatures(key, policyMap);
|
||||
if (additionalFeatures != null) {
|
||||
features.addAll(additionalFeatures);
|
||||
}
|
||||
}
|
||||
} catch (PolicyException e) {
|
||||
throw new WebServiceException(e);
|
||||
}
|
||||
LOGGER.exiting(features);
|
||||
return features;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,466 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.txw2.TypedXmlWriter;
|
||||
import com.sun.xml.internal.ws.addressing.policy.AddressingPolicyMapConfigurator;
|
||||
import com.sun.xml.internal.ws.api.WSBinding;
|
||||
import com.sun.xml.internal.ws.api.policy.PolicyResolverFactory;
|
||||
import com.sun.xml.internal.ws.api.policy.PolicyResolver;
|
||||
import com.sun.xml.internal.ws.api.model.CheckedException;
|
||||
import com.sun.xml.internal.ws.api.model.JavaMethod;
|
||||
import com.sun.xml.internal.ws.api.model.SEIModel;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundFault;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundPortType;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLInput;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLMessage;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOperation;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLOutput;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPortType;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLService;
|
||||
import com.sun.xml.internal.ws.api.policy.ModelGenerator;
|
||||
import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGeneratorExtension;
|
||||
import com.sun.xml.internal.ws.api.wsdl.writer.WSDLGenExtnContext;
|
||||
import com.sun.xml.internal.ws.encoding.policy.MtomPolicyMapConfigurator;
|
||||
import com.sun.xml.internal.ws.policy.Policy;
|
||||
import com.sun.xml.internal.ws.policy.PolicyConstants;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapExtender;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapUtil;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMerger;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import com.sun.xml.internal.ws.policy.jaxws.spi.PolicyMapConfigurator;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicyModelGenerator;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicyModelMarshaller;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
|
||||
import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject;
|
||||
import com.sun.xml.internal.ws.resources.PolicyMessages;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* Marshals the contents of a policy map to WSDL.
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
public class PolicyWSDLGeneratorExtension extends WSDLGeneratorExtension {
|
||||
|
||||
static enum ScopeType {
|
||||
|
||||
SERVICE,
|
||||
ENDPOINT,
|
||||
OPERATION,
|
||||
INPUT_MESSAGE,
|
||||
OUTPUT_MESSAGE,
|
||||
FAULT_MESSAGE
|
||||
}
|
||||
private final static PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyWSDLGeneratorExtension.class);
|
||||
private PolicyMap policyMap;
|
||||
private SEIModel seiModel;
|
||||
private final Collection<PolicySubject> subjects = new LinkedList<PolicySubject>();
|
||||
private final PolicyModelMarshaller marshaller = PolicyModelMarshaller.getXmlMarshaller(true);
|
||||
private final PolicyMerger merger = PolicyMerger.getMerger();
|
||||
|
||||
@Override
|
||||
public void start(final WSDLGenExtnContext context) {
|
||||
LOGGER.entering();
|
||||
try {
|
||||
this.seiModel = context.getModel();
|
||||
|
||||
final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
|
||||
final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
|
||||
for (int i = 0; i < policyMapConfigurators.length; i++) {
|
||||
extenders[i] = PolicyMapExtender.createPolicyMapExtender();
|
||||
}
|
||||
// Read policy config file
|
||||
policyMap = PolicyResolverFactory.create().resolve(
|
||||
new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));
|
||||
|
||||
if (policyMap == null) {
|
||||
LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
|
||||
policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
|
||||
}
|
||||
|
||||
final WSBinding binding = context.getBinding();
|
||||
try {
|
||||
final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>();
|
||||
for (int i = 0; i < policyMapConfigurators.length; i++) {
|
||||
policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
|
||||
extenders[i].disconnect();
|
||||
}
|
||||
PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
|
||||
} catch (PolicyException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
|
||||
}
|
||||
final TypedXmlWriter root = context.getRoot();
|
||||
root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
|
||||
root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
|
||||
root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);
|
||||
|
||||
} finally {
|
||||
LOGGER.exiting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addDefinitionsExtension(final TypedXmlWriter definitions) {
|
||||
try {
|
||||
LOGGER.entering();
|
||||
if (policyMap == null) {
|
||||
LOGGER.fine(PolicyMessages.WSP_1009_NOT_MARSHALLING_ANY_POLICIES_POLICY_MAP_IS_NULL());
|
||||
} else {
|
||||
subjects.addAll(policyMap.getPolicySubjects());
|
||||
final PolicyModelGenerator generator = ModelGenerator.getGenerator();
|
||||
Set<String> policyIDsOrNamesWritten = new HashSet<String>();
|
||||
for (PolicySubject subject : subjects) {
|
||||
if (subject.getSubject() == null) {
|
||||
LOGGER.fine(PolicyMessages.WSP_1008_NOT_MARSHALLING_WSDL_SUBJ_NULL(subject));
|
||||
} else {
|
||||
final Policy policy;
|
||||
try {
|
||||
policy = subject.getEffectivePolicy(merger);
|
||||
} catch (PolicyException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
|
||||
}
|
||||
if ((null == policy.getIdOrName()) || (policyIDsOrNamesWritten.contains(policy.getIdOrName()))) {
|
||||
LOGGER.fine(PolicyMessages.WSP_1016_POLICY_ID_NULL_OR_DUPLICATE(policy));
|
||||
} else {
|
||||
try {
|
||||
final PolicySourceModel policyInfoset = generator.translate(policy);
|
||||
marshaller.marshal(policyInfoset, definitions);
|
||||
} catch (PolicyException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1018_FAILED_TO_MARSHALL_POLICY(policy.getIdOrName()), e));
|
||||
}
|
||||
policyIDsOrNamesWritten.add(policy.getIdOrName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
LOGGER.exiting();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addServiceExtension(final TypedXmlWriter service) {
|
||||
LOGGER.entering();
|
||||
final String serviceName = (null == seiModel) ? null : seiModel.getServiceQName().getLocalPart();
|
||||
selectAndProcessSubject(service, WSDLService.class, ScopeType.SERVICE, serviceName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPortExtension(final TypedXmlWriter port) {
|
||||
LOGGER.entering();
|
||||
final String portName = (null == seiModel) ? null : seiModel.getPortName().getLocalPart();
|
||||
selectAndProcessSubject(port, WSDLPort.class, ScopeType.ENDPOINT, portName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPortTypeExtension(final TypedXmlWriter portType) {
|
||||
LOGGER.entering();
|
||||
final String portTypeName = (null == seiModel) ? null : seiModel.getPortTypeName().getLocalPart();
|
||||
selectAndProcessSubject(portType, WSDLPortType.class, ScopeType.ENDPOINT, portTypeName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindingExtension(final TypedXmlWriter binding) {
|
||||
LOGGER.entering();
|
||||
final QName bindingName = (null == seiModel) ? null : seiModel.getBoundPortTypeName();
|
||||
selectAndProcessBindingSubject(binding, WSDLBoundPortType.class, ScopeType.ENDPOINT, bindingName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationExtension(final TypedXmlWriter operation, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
selectAndProcessSubject(operation, WSDLOperation.class, ScopeType.OPERATION, (String)null);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindingOperationExtension(final TypedXmlWriter operation, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final QName operationName = (method == null) ? null : new QName(method.getOwner().getTargetNamespace(), method.getOperationName());
|
||||
selectAndProcessBindingSubject(operation, WSDLBoundOperation.class, ScopeType.OPERATION, operationName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInputMessageExtension(final TypedXmlWriter message, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == method) ? null : method.getRequestMessageName();
|
||||
selectAndProcessSubject(message, WSDLMessage.class, ScopeType.INPUT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOutputMessageExtension(final TypedXmlWriter message, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == method) ? null : method.getResponseMessageName();
|
||||
selectAndProcessSubject(message, WSDLMessage.class, ScopeType.OUTPUT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addFaultMessageExtension(final TypedXmlWriter message, final JavaMethod method, final CheckedException exception) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == exception) ? null : exception.getMessageName();
|
||||
selectAndProcessSubject(message, WSDLMessage.class, ScopeType.FAULT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationInputExtension(final TypedXmlWriter input, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == method) ? null : method.getRequestMessageName();
|
||||
selectAndProcessSubject(input, WSDLInput.class, ScopeType.INPUT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationOutputExtension(final TypedXmlWriter output, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == method) ? null : method.getResponseMessageName();
|
||||
selectAndProcessSubject(output, WSDLOutput.class, ScopeType.OUTPUT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationFaultExtension(final TypedXmlWriter fault, final JavaMethod method, final CheckedException exception) {
|
||||
LOGGER.entering();
|
||||
final String messageName = (null == exception) ? null : exception.getMessageName();
|
||||
selectAndProcessSubject(fault, WSDLFault.class, ScopeType.FAULT_MESSAGE, messageName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindingOperationInputExtension(final TypedXmlWriter input, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final QName operationName = new QName(method.getOwner().getTargetNamespace(), method.getOperationName());
|
||||
selectAndProcessBindingSubject(input, WSDLBoundOperation.class, ScopeType.INPUT_MESSAGE, operationName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindingOperationOutputExtension(final TypedXmlWriter output, final JavaMethod method) {
|
||||
LOGGER.entering();
|
||||
final QName operationName = new QName(method.getOwner().getTargetNamespace(), method.getOperationName());
|
||||
selectAndProcessBindingSubject(output, WSDLBoundOperation.class, ScopeType.OUTPUT_MESSAGE, operationName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindingOperationFaultExtension(final TypedXmlWriter writer, final JavaMethod method, final CheckedException exception) {
|
||||
LOGGER.entering(writer, method, exception);
|
||||
if (subjects != null) {
|
||||
for (PolicySubject subject : subjects) { // iterate over all subjects in policy map
|
||||
if (this.policyMap.isFaultMessageSubject(subject)) {
|
||||
final Object concreteSubject = subject.getSubject();
|
||||
if (concreteSubject != null) {
|
||||
final String exceptionName = exception == null ? null : exception.getMessageName();
|
||||
if (exceptionName == null) { // no name provided to check
|
||||
writePolicyOrReferenceIt(subject, writer);
|
||||
}
|
||||
if (WSDLBoundFaultContainer.class.isInstance(concreteSubject)) { // is it our class?
|
||||
WSDLBoundFaultContainer faultContainer = (WSDLBoundFaultContainer) concreteSubject;
|
||||
WSDLBoundFault fault = faultContainer.getBoundFault();
|
||||
WSDLBoundOperation operation = faultContainer.getBoundOperation();
|
||||
if (exceptionName.equals(fault.getName()) &&
|
||||
operation.getName().getLocalPart().equals(method.getOperationName())) {
|
||||
writePolicyOrReferenceIt(subject, writer);
|
||||
}
|
||||
}
|
||||
else if (WsdlBindingSubject.class.isInstance(concreteSubject)) {
|
||||
WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) concreteSubject;
|
||||
if ((wsdlSubject.getMessageType() == WsdlBindingSubject.WsdlMessageType.FAULT) &&
|
||||
exception.getOwner().getTargetNamespace().equals(wsdlSubject.getName().getNamespaceURI()) &&
|
||||
exceptionName.equals(wsdlSubject.getName().getLocalPart())) {
|
||||
writePolicyOrReferenceIt(subject, writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should only be invoked by interface methods that deal with WSDL binding because they
|
||||
* may use the QName of the WSDL binding element as PolicySubject instead of a WSDL object.
|
||||
*
|
||||
* @param xmlWriter A TypedXmlWriter.
|
||||
* @param clazz The policy subject.
|
||||
* @param scopeType The WSDL scope.
|
||||
* @param bindingName The WSDL binding name.
|
||||
*/
|
||||
private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
|
||||
LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
|
||||
if (bindingName == null) {
|
||||
selectAndProcessSubject(xmlWriter, clazz, scopeType, (String) null);
|
||||
} else {
|
||||
if (subjects != null) {
|
||||
for (PolicySubject subject : subjects) {
|
||||
if (bindingName.equals(subject.getSubject())) {
|
||||
writePolicyOrReferenceIt(subject, xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName.getLocalPart());
|
||||
}
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
private void selectAndProcessBindingSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final QName bindingName) {
|
||||
LOGGER.entering(xmlWriter, clazz, scopeType, bindingName);
|
||||
if ((subjects != null) && (bindingName != null)) {
|
||||
for (PolicySubject subject : subjects) {
|
||||
if (subject.getSubject() instanceof WsdlBindingSubject) {
|
||||
final WsdlBindingSubject wsdlSubject = (WsdlBindingSubject) subject.getSubject();
|
||||
if (bindingName.equals(wsdlSubject.getName())) {
|
||||
writePolicyOrReferenceIt(subject, xmlWriter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
selectAndProcessSubject(xmlWriter, clazz, scopeType, bindingName);
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
private void selectAndProcessSubject(final TypedXmlWriter xmlWriter, final Class clazz, final ScopeType scopeType, final String wsdlName) {
|
||||
LOGGER.entering(xmlWriter, clazz, scopeType, wsdlName);
|
||||
if (subjects != null) {
|
||||
for (PolicySubject subject : subjects) { // iterate over all subjects in policy map
|
||||
if (isCorrectType(policyMap, subject, scopeType)) {
|
||||
final Object concreteSubject = subject.getSubject();
|
||||
if (concreteSubject != null && clazz.isInstance(concreteSubject)) { // is it our class?
|
||||
if (null == wsdlName) { // no name provided to check
|
||||
writePolicyOrReferenceIt(subject, xmlWriter);
|
||||
} else {
|
||||
try {
|
||||
final Method getNameMethod = clazz.getDeclaredMethod("getName");
|
||||
if (stringEqualsToStringOrQName(wsdlName, getNameMethod.invoke(concreteSubject))) {
|
||||
writePolicyOrReferenceIt(subject, xmlWriter);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
|
||||
} catch (InvocationTargetException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1003_UNABLE_TO_CHECK_ELEMENT_NAME(clazz.getName(), wsdlName), e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
private static boolean isCorrectType(final PolicyMap map, final PolicySubject subject, final ScopeType type) {
|
||||
switch (type) {
|
||||
case OPERATION:
|
||||
return !(map.isInputMessageSubject(subject) || map.isOutputMessageSubject(subject) || map.isFaultMessageSubject(subject));
|
||||
case INPUT_MESSAGE:
|
||||
return map.isInputMessageSubject(subject);
|
||||
case OUTPUT_MESSAGE:
|
||||
return map.isOutputMessageSubject(subject);
|
||||
case FAULT_MESSAGE:
|
||||
return map.isFaultMessageSubject(subject);
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean stringEqualsToStringOrQName(final String first, final Object second) {
|
||||
return (second instanceof QName) ? first.equals(((QName) second).getLocalPart()) : first.equals(second);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a PolicyReference element that points to the policy of the element,
|
||||
* if the policy does not have any id or name. Writes policy inside the element otherwise.
|
||||
*
|
||||
* @param subject
|
||||
* PolicySubject to be referenced or marshalled
|
||||
* @param writer
|
||||
* A TXW on to which we shall add the PolicyReference
|
||||
*/
|
||||
private void writePolicyOrReferenceIt(final PolicySubject subject, final TypedXmlWriter writer) {
|
||||
final Policy policy;
|
||||
try {
|
||||
policy = subject.getEffectivePolicy(merger);
|
||||
} catch (PolicyException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1011_FAILED_TO_RETRIEVE_EFFECTIVE_POLICY_FOR_SUBJECT(subject.toString()), e));
|
||||
}
|
||||
if (policy != null) {
|
||||
if (null == policy.getIdOrName()) {
|
||||
final PolicyModelGenerator generator = ModelGenerator.getGenerator();
|
||||
try {
|
||||
final PolicySourceModel policyInfoset = generator.translate(policy);
|
||||
marshaller.marshal(policyInfoset, writer);
|
||||
} catch (PolicyException pe) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1002_UNABLE_TO_MARSHALL_POLICY_OR_POLICY_REFERENCE(), pe));
|
||||
}
|
||||
} else {
|
||||
final TypedXmlWriter policyReference = writer._element(policy.getNamespaceVersion().asQName(XmlToken.PolicyReference), TypedXmlWriter.class);
|
||||
policyReference._attribute(XmlToken.Uri.toString(), '#' + policy.getIdOrName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PolicyMapConfigurator[] loadConfigurators() {
|
||||
final Collection<PolicyMapConfigurator> configurators = new LinkedList<PolicyMapConfigurator>();
|
||||
|
||||
// Add map configurators that are already built into JAX-WS
|
||||
configurators.add(new AddressingPolicyMapConfigurator());
|
||||
configurators.add(new MtomPolicyMapConfigurator());
|
||||
|
||||
// Dynamically discover remaining map configurators
|
||||
PolicyUtil.addServiceProviders(configurators, PolicyMapConfigurator.class);
|
||||
|
||||
return configurators.toArray(new PolicyMapConfigurator[configurators.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,990 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.editable.*;
|
||||
import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtension;
|
||||
import com.sun.xml.internal.ws.api.wsdl.parser.WSDLParserExtensionContext;
|
||||
import com.sun.xml.internal.ws.api.policy.PolicyResolver;
|
||||
import com.sun.xml.internal.ws.resources.PolicyMessages;
|
||||
import com.sun.xml.internal.ws.policy.jaxws.SafePolicyReader.PolicyRecord;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModelContext;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.util.xml.XmlUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.HashSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* This class parses the Policy Attachments in the WSDL and creates a PolicyMap thaty captures the policies configured on
|
||||
* different PolicySubjects in the wsdl.
|
||||
*
|
||||
* After, it is finished it sets the PolicyMap on the WSDLModel.
|
||||
*
|
||||
* @author Jakub Podlesak (jakub.podlesak at sun.com)
|
||||
* @author Fabian Ritzmann
|
||||
* @author Rama Pulavarthi
|
||||
*/
|
||||
final public class PolicyWSDLParserExtension extends WSDLParserExtension {
|
||||
|
||||
enum HandlerType {
|
||||
PolicyUri, AnonymousPolicyId
|
||||
}
|
||||
|
||||
final static class PolicyRecordHandler {
|
||||
String handler;
|
||||
HandlerType type;
|
||||
|
||||
PolicyRecordHandler(HandlerType type, String handler) {
|
||||
this.type = type;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
HandlerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
String getHandler() {
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyWSDLParserExtension.class);
|
||||
|
||||
//anonymous policy id prefix
|
||||
private static final StringBuffer AnonymnousPolicyIdPrefix = new StringBuffer("#__anonymousPolicy__ID");
|
||||
|
||||
// anonymous policies count
|
||||
private int anonymousPoliciesCount;
|
||||
|
||||
private final SafePolicyReader policyReader = new SafePolicyReader();
|
||||
|
||||
// policy queue -- needed for evaluating the right order policy of policy models expansion
|
||||
private PolicyRecord expandQueueHead = null;
|
||||
|
||||
// storage for policy models with an id passed by
|
||||
private Map<String,PolicyRecord> policyRecordsPassedBy = null;
|
||||
// storage for anonymous policies defined within given WSDL
|
||||
private Map<String,PolicySourceModel> anonymousPolicyModels = null;
|
||||
|
||||
// container for URIs of policies referenced
|
||||
private List<String> unresolvedUris = null;
|
||||
|
||||
// structures for policies really needed to build a map
|
||||
private final LinkedList<String> urisNeeded = new LinkedList<String>();
|
||||
private final Map<String, PolicySourceModel> modelsNeeded = new HashMap<String, PolicySourceModel>();
|
||||
|
||||
// lookup tables for Policy attachments found
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4ServiceMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4PortMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4PortTypeMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BoundOperationMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4OperationMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4MessageMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4InputMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4OutputMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4FaultMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingInputOpMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingOutputOpMap = null;
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> handlers4BindingFaultOpMap = null;
|
||||
|
||||
private PolicyMapBuilder policyBuilder = new PolicyMapBuilder();
|
||||
|
||||
private boolean isPolicyProcessed(final String policyUri) {
|
||||
return modelsNeeded.containsKey(policyUri);
|
||||
}
|
||||
|
||||
private void addNewPolicyNeeded(final String policyUri, final PolicySourceModel policyModel) {
|
||||
if (!modelsNeeded.containsKey(policyUri)) {
|
||||
modelsNeeded.put(policyUri, policyModel);
|
||||
urisNeeded.addFirst(policyUri);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, PolicySourceModel> getPolicyModels() {
|
||||
return modelsNeeded;
|
||||
}
|
||||
|
||||
private Map<String,PolicyRecord> getPolicyRecordsPassedBy() {
|
||||
if (null==policyRecordsPassedBy) {
|
||||
policyRecordsPassedBy = new HashMap<String,PolicyRecord>();
|
||||
}
|
||||
return policyRecordsPassedBy;
|
||||
}
|
||||
|
||||
private Map<String,PolicySourceModel> getAnonymousPolicyModels() {
|
||||
if (null==anonymousPolicyModels) {
|
||||
anonymousPolicyModels = new HashMap<String,PolicySourceModel>();
|
||||
}
|
||||
return anonymousPolicyModels;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4ServiceMap() {
|
||||
if (null==handlers4ServiceMap) {
|
||||
handlers4ServiceMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4ServiceMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4PortMap() {
|
||||
if (null==handlers4PortMap) {
|
||||
handlers4PortMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4PortMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4PortTypeMap() {
|
||||
if (null==handlers4PortTypeMap) {
|
||||
handlers4PortTypeMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4PortTypeMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingMap() {
|
||||
if (null==handlers4BindingMap) {
|
||||
handlers4BindingMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4BindingMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4OperationMap() {
|
||||
if (null==handlers4OperationMap) {
|
||||
handlers4OperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4OperationMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BoundOperationMap() {
|
||||
if (null==handlers4BoundOperationMap) {
|
||||
handlers4BoundOperationMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4BoundOperationMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4MessageMap() {
|
||||
if (null==handlers4MessageMap) {
|
||||
handlers4MessageMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4MessageMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4InputMap() {
|
||||
if (null==handlers4InputMap) {
|
||||
handlers4InputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4InputMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4OutputMap() {
|
||||
if (null==handlers4OutputMap) {
|
||||
handlers4OutputMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4OutputMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4FaultMap() {
|
||||
if (null==handlers4FaultMap) {
|
||||
handlers4FaultMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4FaultMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingInputOpMap() {
|
||||
if (null==handlers4BindingInputOpMap) {
|
||||
handlers4BindingInputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4BindingInputOpMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingOutputOpMap() {
|
||||
if (null==handlers4BindingOutputOpMap) {
|
||||
handlers4BindingOutputOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4BindingOutputOpMap;
|
||||
}
|
||||
|
||||
private Map<WSDLObject, Collection<PolicyRecordHandler>> getHandlers4BindingFaultOpMap() {
|
||||
if (null==handlers4BindingFaultOpMap) {
|
||||
handlers4BindingFaultOpMap = new HashMap<WSDLObject,Collection<PolicyRecordHandler>>();
|
||||
}
|
||||
return handlers4BindingFaultOpMap;
|
||||
}
|
||||
|
||||
private List<String> getUnresolvedUris(final boolean emptyListNeeded) {
|
||||
if ((null == unresolvedUris) || emptyListNeeded) {
|
||||
unresolvedUris = new LinkedList<String>();
|
||||
}
|
||||
return unresolvedUris;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void policyRecToExpandQueue(final PolicyRecord policyRec) {
|
||||
if (null==expandQueueHead) {
|
||||
expandQueueHead = policyRec;
|
||||
} else {
|
||||
expandQueueHead = expandQueueHead.insert(policyRec);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of PolicyWSDLParserExtension
|
||||
*/
|
||||
public PolicyWSDLParserExtension() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
private PolicyRecordHandler readSinglePolicy(final PolicyRecord policyRec, final boolean inner) {
|
||||
PolicyRecordHandler handler = null;
|
||||
String policyId = policyRec.policyModel.getPolicyId();
|
||||
if (policyId == null) {
|
||||
policyId = policyRec.policyModel.getPolicyName();
|
||||
}
|
||||
if (policyId != null) { // policy id defined, keep the policy
|
||||
handler = new PolicyRecordHandler(HandlerType.PolicyUri, policyRec.getUri());
|
||||
getPolicyRecordsPassedBy().put(policyRec.getUri(), policyRec);
|
||||
policyRecToExpandQueue(policyRec);
|
||||
} else if (inner) { // no id given to the policy --> keep as an annonymous policy model
|
||||
final String anonymousId = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString();
|
||||
handler = new PolicyRecordHandler(HandlerType.AnonymousPolicyId,anonymousId);
|
||||
getAnonymousPolicyModels().put(anonymousId, policyRec.policyModel);
|
||||
if (null != policyRec.unresolvedURIs) {
|
||||
getUnresolvedUris(false).addAll(policyRec.unresolvedURIs);
|
||||
}
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
|
||||
private void addHandlerToMap(
|
||||
final Map<WSDLObject, Collection<PolicyRecordHandler>> map, final WSDLObject key, final PolicyRecordHandler handler) {
|
||||
if (map.containsKey(key)) {
|
||||
map.get(key).add(handler);
|
||||
} else {
|
||||
final Collection<PolicyRecordHandler> newSet = new LinkedList<PolicyRecordHandler>();
|
||||
newSet.add(handler);
|
||||
map.put(key,newSet);
|
||||
}
|
||||
}
|
||||
|
||||
private String getBaseUrl(final String policyUri) {
|
||||
if (null == policyUri) {
|
||||
return null;
|
||||
}
|
||||
// TODO: encoded urls (escaped characters) might be a problem ?
|
||||
final int fragmentIdx = policyUri.indexOf('#');
|
||||
return (fragmentIdx == -1) ? policyUri : policyUri.substring(0, fragmentIdx);
|
||||
}
|
||||
|
||||
// adding current url even to locally referenced policies
|
||||
// in order to distinguish imported policies
|
||||
private void processReferenceUri(
|
||||
final String policyUri,
|
||||
final WSDLObject element,
|
||||
final XMLStreamReader reader,
|
||||
final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
|
||||
|
||||
if (null == policyUri || policyUri.length() == 0) {
|
||||
return;
|
||||
}
|
||||
if ('#' != policyUri.charAt(0)) { // external uri (already)
|
||||
getUnresolvedUris(false).add(policyUri);
|
||||
}
|
||||
|
||||
addHandlerToMap(map, element,
|
||||
new PolicyRecordHandler(
|
||||
HandlerType.PolicyUri,
|
||||
SafePolicyReader.relativeToAbsoluteUrl(policyUri, reader.getLocation().getSystemId())));
|
||||
}
|
||||
|
||||
private boolean processSubelement(
|
||||
final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
|
||||
if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) { // "PolicyReference" element interests us
|
||||
processReferenceUri(policyReader.readPolicyReferenceElement(reader), element, reader, map);
|
||||
return true;
|
||||
} else if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) { // policy could be defined here
|
||||
final PolicyRecordHandler handler =
|
||||
readSinglePolicy(
|
||||
policyReader.readPolicyElement(
|
||||
reader,
|
||||
(null == reader.getLocation().getSystemId()) ? // baseUrl
|
||||
"" : reader.getLocation().getSystemId()),
|
||||
true);
|
||||
if (null != handler) { // only policies with an Id can work for us
|
||||
addHandlerToMap(map, element, handler);
|
||||
} // endif null != handler
|
||||
return true; // element consumed
|
||||
}//end if Policy element found
|
||||
return false;
|
||||
}
|
||||
|
||||
private void processAttributes(final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
|
||||
final String[] uriArray = getPolicyURIsFromAttr(reader);
|
||||
if (null != uriArray) {
|
||||
for (String policyUri : uriArray) {
|
||||
processReferenceUri(policyUri, element, reader, map);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean portElements(final EditableWSDLPort port, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(port, reader, getHandlers4PortMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portAttributes(final EditableWSDLPort port, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(port, reader, getHandlers4PortMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean serviceElements(final EditableWSDLService service, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(service, reader, getHandlers4ServiceMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceAttributes(final EditableWSDLService service, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(service, reader, getHandlers4ServiceMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean definitionsElements(final XMLStreamReader reader){
|
||||
LOGGER.entering();
|
||||
if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) { // Only "Policy" element interests me
|
||||
readSinglePolicy(
|
||||
policyReader.readPolicyElement(
|
||||
reader,
|
||||
(null == reader.getLocation().getSystemId()) ? // baseUrl
|
||||
"" : reader.getLocation().getSystemId()),
|
||||
false);
|
||||
LOGGER.exiting();
|
||||
return true;
|
||||
}
|
||||
LOGGER.exiting();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingElements(final EditableWSDLBoundPortType binding, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(binding, reader, getHandlers4BindingMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingAttributes(final EditableWSDLBoundPortType binding, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(binding, reader, getHandlers4BindingMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean portTypeElements(final EditableWSDLPortType portType, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(portType, reader, getHandlers4PortTypeMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portTypeAttributes(final EditableWSDLPortType portType, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(portType, reader, getHandlers4PortTypeMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean portTypeOperationElements(final EditableWSDLOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(operation, reader, getHandlers4OperationMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portTypeOperationAttributes(final EditableWSDLOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(operation, reader, getHandlers4OperationMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingOperationElements(final EditableWSDLBoundOperation boundOperation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(boundOperation, reader, getHandlers4BoundOperationMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingOperationAttributes(final EditableWSDLBoundOperation boundOperation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(boundOperation, reader, getHandlers4BoundOperationMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean messageElements(final EditableWSDLMessage msg, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(msg, reader, getHandlers4MessageMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageAttributes(final EditableWSDLMessage msg, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(msg, reader, getHandlers4MessageMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean portTypeOperationInputElements(final EditableWSDLInput input, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(input, reader, getHandlers4InputMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portTypeOperationInputAttributes(final EditableWSDLInput input, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(input, reader, getHandlers4InputMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean portTypeOperationOutputElements(final EditableWSDLOutput output, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(output, reader, getHandlers4OutputMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portTypeOperationOutputAttributes(final EditableWSDLOutput output, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(output, reader, getHandlers4OutputMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean portTypeOperationFaultElements(final EditableWSDLFault fault, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(fault, reader, getHandlers4FaultMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void portTypeOperationFaultAttributes(final EditableWSDLFault fault, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(fault, reader, getHandlers4FaultMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingOperationInputElements(final EditableWSDLBoundOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(operation, reader, getHandlers4BindingInputOpMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingOperationInputAttributes(final EditableWSDLBoundOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(operation, reader, getHandlers4BindingInputOpMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean bindingOperationOutputElements(final EditableWSDLBoundOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(operation, reader, getHandlers4BindingOutputOpMap());
|
||||
LOGGER.exiting();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingOperationOutputAttributes(final EditableWSDLBoundOperation operation, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(operation, reader, getHandlers4BindingOutputOpMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean bindingOperationFaultElements(final EditableWSDLBoundFault fault, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
final boolean result = processSubelement(fault, reader, getHandlers4BindingFaultOpMap());
|
||||
LOGGER.exiting(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindingOperationFaultAttributes(final EditableWSDLBoundFault fault, final XMLStreamReader reader) {
|
||||
LOGGER.entering();
|
||||
processAttributes(fault, reader, getHandlers4BindingFaultOpMap());
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
private PolicyMapBuilder getPolicyMapBuilder() {
|
||||
if (null == policyBuilder) {
|
||||
policyBuilder = new PolicyMapBuilder();
|
||||
}
|
||||
return policyBuilder;
|
||||
}
|
||||
|
||||
private Collection<String> getPolicyURIs(
|
||||
final Collection<PolicyRecordHandler> handlers, final PolicySourceModelContext modelContext) throws PolicyException{
|
||||
final Collection<String> result = new ArrayList<String>(handlers.size());
|
||||
String policyUri;
|
||||
for (PolicyRecordHandler handler : handlers) {
|
||||
policyUri = handler.handler;
|
||||
if (HandlerType.AnonymousPolicyId == handler.type) {
|
||||
final PolicySourceModel policyModel = getAnonymousPolicyModels().get(policyUri);
|
||||
policyModel.expand(modelContext);
|
||||
while (getPolicyModels().containsKey(policyUri)) {
|
||||
policyUri = AnonymnousPolicyIdPrefix.append(anonymousPoliciesCount++).toString();
|
||||
}
|
||||
getPolicyModels().put(policyUri,policyModel);
|
||||
}
|
||||
result.add(policyUri);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean readExternalFile(final String fileUrl) {
|
||||
InputStream ios = null;
|
||||
XMLStreamReader reader = null;
|
||||
try {
|
||||
final URL xmlURL = new URL(fileUrl);
|
||||
ios = xmlURL.openStream();
|
||||
reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
|
||||
while (reader.hasNext()) {
|
||||
if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
|
||||
readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
|
||||
}
|
||||
reader.next();
|
||||
}
|
||||
return true;
|
||||
} catch (IOException ioe) {
|
||||
return false;
|
||||
} catch (XMLStreamException xmlse) {
|
||||
return false;
|
||||
} finally {
|
||||
PolicyUtils.IO.closeResource(reader);
|
||||
PolicyUtils.IO.closeResource(ios);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finished(final WSDLParserExtensionContext context) {
|
||||
LOGGER.entering(context);
|
||||
// need to make sure proper beginning order of internal policies within unresolvedUris list
|
||||
if (null != expandQueueHead) { // any policies found
|
||||
final List<String> externalUris = getUnresolvedUris(false); // protect list of possible external policies
|
||||
getUnresolvedUris(true); // cleaning up the list only
|
||||
final LinkedList<String> baseUnresolvedUris = new LinkedList<String>();
|
||||
for (PolicyRecord currentRec = expandQueueHead ; null != currentRec ; currentRec = currentRec.next) {
|
||||
baseUnresolvedUris.addFirst(currentRec.getUri());
|
||||
}
|
||||
getUnresolvedUris(false).addAll(baseUnresolvedUris);
|
||||
expandQueueHead = null; // cut the queue off
|
||||
getUnresolvedUris(false).addAll(externalUris);
|
||||
}
|
||||
|
||||
while (!getUnresolvedUris(false).isEmpty()) {
|
||||
final List<String> urisToBeSolvedList = getUnresolvedUris(false);
|
||||
getUnresolvedUris(true); // just cleaning up the list
|
||||
for (String currentUri : urisToBeSolvedList) {
|
||||
if (!isPolicyProcessed(currentUri)) {
|
||||
final PolicyRecord prefetchedRecord = getPolicyRecordsPassedBy().get(currentUri);
|
||||
if (null == prefetchedRecord) {
|
||||
if (policyReader.getUrlsRead().contains(getBaseUrl(currentUri))) { // --> unresolvable policy
|
||||
LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1014_CAN_NOT_FIND_POLICY(currentUri)));
|
||||
} else {
|
||||
if (readExternalFile(getBaseUrl(currentUri))) {
|
||||
getUnresolvedUris(false).add(currentUri);
|
||||
}
|
||||
}
|
||||
} else { // policy has not been yet passed by
|
||||
if (null != prefetchedRecord.unresolvedURIs) {
|
||||
getUnresolvedUris(false).addAll(prefetchedRecord.unresolvedURIs);
|
||||
} // end-if null != prefetchedRecord.unresolvedURIs
|
||||
addNewPolicyNeeded(currentUri, prefetchedRecord.policyModel);
|
||||
}
|
||||
} // end-if policy already processed
|
||||
} // end-foreach unresolved uris
|
||||
}
|
||||
final PolicySourceModelContext modelContext = PolicySourceModelContext.createContext();
|
||||
for (String policyUri : urisNeeded) {
|
||||
final PolicySourceModel sourceModel = modelsNeeded.get(policyUri);
|
||||
try {
|
||||
sourceModel.expand(modelContext);
|
||||
modelContext.addModel(new URI(policyUri), sourceModel);
|
||||
} catch (URISyntaxException e) {
|
||||
LOGGER.logSevereException(e);
|
||||
} catch (PolicyException e) {
|
||||
LOGGER.logSevereException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Start-preparation of policy map builder
|
||||
// iterating over all services and binding all the policies read before
|
||||
try {
|
||||
// messageSet holds the handlers for all wsdl:message elements. There
|
||||
// may otherwise be multiple entries for policies that are contained
|
||||
// by fault messages.
|
||||
HashSet<BuilderHandlerMessageScope> messageSet = new HashSet<BuilderHandlerMessageScope>();
|
||||
for (EditableWSDLService service : context.getWSDLModel().getServices().values()) {
|
||||
if (getHandlers4ServiceMap().containsKey(service)) {
|
||||
getPolicyMapBuilder().registerHandler(new BuilderHandlerServiceScope(
|
||||
getPolicyURIs(getHandlers4ServiceMap().get(service),modelContext)
|
||||
,getPolicyModels()
|
||||
,service
|
||||
,service.getName()));
|
||||
}
|
||||
// end service scope
|
||||
|
||||
for (EditableWSDLPort port : service.getPorts()) {
|
||||
if (getHandlers4PortMap().containsKey(port)) {
|
||||
getPolicyMapBuilder().registerHandler(
|
||||
new BuilderHandlerEndpointScope(
|
||||
getPolicyURIs(getHandlers4PortMap().get(port),modelContext)
|
||||
,getPolicyModels()
|
||||
,port
|
||||
,port.getOwner().getName()
|
||||
,port.getName()));
|
||||
}
|
||||
if ( // port.getBinding may not be null, but in case ...
|
||||
null != port.getBinding()) {
|
||||
if ( // handler for binding
|
||||
getHandlers4BindingMap().containsKey(port.getBinding())) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerEndpointScope(
|
||||
getPolicyURIs(getHandlers4BindingMap().get(port.getBinding()),modelContext)
|
||||
,getPolicyModels()
|
||||
,port.getBinding()
|
||||
,service.getName()
|
||||
,port.getName()));
|
||||
} // endif handler for binding
|
||||
if ( // handler for port type
|
||||
getHandlers4PortTypeMap().containsKey(port.getBinding().getPortType())) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerEndpointScope(
|
||||
getPolicyURIs(getHandlers4PortTypeMap().get(port.getBinding().getPortType()),modelContext)
|
||||
,getPolicyModels()
|
||||
,port.getBinding().getPortType()
|
||||
,service.getName()
|
||||
,port.getName()));
|
||||
} // endif handler for port type
|
||||
// end endpoint scope
|
||||
|
||||
for (EditableWSDLBoundOperation boundOperation : port.getBinding().getBindingOperations()) {
|
||||
|
||||
final EditableWSDLOperation operation = boundOperation.getOperation();
|
||||
final QName operationName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundOperation.getName().getLocalPart());
|
||||
// We store the message and portType/operation under the same namespace as the binding/operation so that we can match them up later
|
||||
if ( // handler for operation scope -- by boundOperation
|
||||
getHandlers4BoundOperationMap().containsKey(boundOperation)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerOperationScope(
|
||||
getPolicyURIs(getHandlers4BoundOperationMap().get(boundOperation),modelContext)
|
||||
,getPolicyModels()
|
||||
,boundOperation
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName));
|
||||
} // endif handler for binding:operation scope
|
||||
if ( // handler for operation scope -- by operation map
|
||||
getHandlers4OperationMap().containsKey(operation)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerOperationScope(
|
||||
getPolicyURIs(getHandlers4OperationMap().get(operation),modelContext)
|
||||
,getPolicyModels()
|
||||
,operation
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName));
|
||||
} // endif for portType:operation scope
|
||||
// end operation scope
|
||||
|
||||
final EditableWSDLInput input = operation.getInput();
|
||||
if (null!=input) {
|
||||
EditableWSDLMessage inputMsg = input.getMessage();
|
||||
if (inputMsg != null && getHandlers4MessageMap().containsKey(inputMsg)) {
|
||||
messageSet.add(new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(
|
||||
getHandlers4MessageMap().get(inputMsg), modelContext)
|
||||
,getPolicyModels()
|
||||
,inputMsg
|
||||
,BuilderHandlerMessageScope.Scope.InputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null)
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( // binding op input msg
|
||||
getHandlers4BindingInputOpMap().containsKey(boundOperation)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4BindingInputOpMap().get(boundOperation),modelContext)
|
||||
,getPolicyModels()
|
||||
,boundOperation
|
||||
,BuilderHandlerMessageScope.Scope.InputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null));
|
||||
} // endif binding op input msg
|
||||
if ( null != input // portType op input msg
|
||||
&& getHandlers4InputMap().containsKey(input)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4InputMap().get(input),modelContext)
|
||||
,getPolicyModels()
|
||||
,input
|
||||
,BuilderHandlerMessageScope.Scope.InputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null));
|
||||
} // endif portType op input msg
|
||||
// end input message scope
|
||||
|
||||
final EditableWSDLOutput output = operation.getOutput();
|
||||
if (null!=output) {
|
||||
EditableWSDLMessage outputMsg = output.getMessage();
|
||||
if (outputMsg != null && getHandlers4MessageMap().containsKey(outputMsg)) {
|
||||
messageSet.add(new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(
|
||||
getHandlers4MessageMap().get(outputMsg),modelContext)
|
||||
,getPolicyModels()
|
||||
,outputMsg
|
||||
,BuilderHandlerMessageScope.Scope.OutputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null)
|
||||
);
|
||||
}
|
||||
}
|
||||
if ( // binding op output msg
|
||||
getHandlers4BindingOutputOpMap().containsKey(boundOperation)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4BindingOutputOpMap().get(boundOperation),modelContext)
|
||||
,getPolicyModels()
|
||||
,boundOperation
|
||||
,BuilderHandlerMessageScope.Scope.OutputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null));
|
||||
} // endif binding op output msg
|
||||
if ( null != output // portType op output msg
|
||||
&& getHandlers4OutputMap().containsKey(output)) {
|
||||
getPolicyMapBuilder()
|
||||
.registerHandler(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4OutputMap().get(output),modelContext)
|
||||
,getPolicyModels()
|
||||
,output
|
||||
,BuilderHandlerMessageScope.Scope.OutputMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,null));
|
||||
} // endif portType op output msg
|
||||
// end output message scope
|
||||
|
||||
for (EditableWSDLBoundFault boundFault : boundOperation.getFaults()) {
|
||||
final EditableWSDLFault fault = boundFault.getFault();
|
||||
|
||||
// this shouldn't happen ususally,
|
||||
// but since this scenario tested in lagacy tests, dont' fail here
|
||||
if (fault == null) {
|
||||
LOGGER.warning(PolicyMessages.WSP_1021_FAULT_NOT_BOUND(boundFault.getName()));
|
||||
continue;
|
||||
}
|
||||
|
||||
final EditableWSDLMessage faultMessage = fault.getMessage();
|
||||
final QName faultName = new QName(boundOperation.getBoundPortType().getName().getNamespaceURI(), boundFault.getName());
|
||||
// We store the message and portType/fault under the same namespace as the binding/fault so that we can match them up later
|
||||
if (faultMessage != null && getHandlers4MessageMap().containsKey(faultMessage)) {
|
||||
messageSet.add(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4MessageMap().get(faultMessage), modelContext)
|
||||
,getPolicyModels()
|
||||
,new WSDLBoundFaultContainer(boundFault, boundOperation)
|
||||
,BuilderHandlerMessageScope.Scope.FaultMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,faultName)
|
||||
);
|
||||
}
|
||||
if (getHandlers4FaultMap().containsKey(fault)) {
|
||||
messageSet.add(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4FaultMap().get(fault), modelContext)
|
||||
,getPolicyModels()
|
||||
,new WSDLBoundFaultContainer(boundFault, boundOperation)
|
||||
,BuilderHandlerMessageScope.Scope.FaultMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,faultName)
|
||||
);
|
||||
}
|
||||
if (getHandlers4BindingFaultOpMap().containsKey(boundFault)) {
|
||||
messageSet.add(
|
||||
new BuilderHandlerMessageScope(
|
||||
getPolicyURIs(getHandlers4BindingFaultOpMap().get(boundFault), modelContext)
|
||||
,getPolicyModels()
|
||||
,new WSDLBoundFaultContainer(boundFault, boundOperation)
|
||||
,BuilderHandlerMessageScope.Scope.FaultMessageScope
|
||||
,service.getName()
|
||||
,port.getName()
|
||||
,operationName
|
||||
,faultName)
|
||||
);
|
||||
}
|
||||
} // end foreach binding operation fault msg
|
||||
// end fault message scope
|
||||
|
||||
} // end foreach boundOperation in port
|
||||
} // endif port.getBinding() != null
|
||||
} // end foreach port in service
|
||||
} // end foreach service in wsdl
|
||||
// Add handlers for wsdl:message elements
|
||||
for (BuilderHandlerMessageScope scopeHandler : messageSet) {
|
||||
getPolicyMapBuilder().registerHandler(scopeHandler);
|
||||
}
|
||||
} catch(PolicyException e) {
|
||||
LOGGER.logSevereException(e);
|
||||
}
|
||||
// End-preparation of policy map builder
|
||||
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
// time to read possible config file and do alternative selection (on client side)
|
||||
@Override
|
||||
public void postFinished(final WSDLParserExtensionContext context) {
|
||||
// finally register the PolicyMap on the WSDLModel
|
||||
EditableWSDLModel wsdlModel = context.getWSDLModel();
|
||||
PolicyMap effectiveMap;
|
||||
try {
|
||||
if(context.isClientSide())
|
||||
effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ClientContext(policyBuilder.getPolicyMap(),context.getContainer()));
|
||||
else
|
||||
effectiveMap = context.getPolicyResolver().resolve(new PolicyResolver.ServerContext(policyBuilder.getPolicyMap(), context.getContainer(),null));
|
||||
wsdlModel.setPolicyMap(effectiveMap);
|
||||
} catch (PolicyException e) {
|
||||
LOGGER.logSevereException(e);
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1007_POLICY_EXCEPTION_WHILE_FINISHING_PARSING_WSDL(), e));
|
||||
}
|
||||
try {
|
||||
PolicyUtil.configureModel(wsdlModel,effectiveMap);
|
||||
} catch (PolicyException e) {
|
||||
LOGGER.logSevereException(e);
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1012_FAILED_CONFIGURE_WSDL_MODEL(), e));
|
||||
}
|
||||
LOGGER.exiting();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads policy reference URIs from PolicyURIs attribute and returns them
|
||||
* as a String array returns null if there is no such attribute. This method
|
||||
* will attempt to check for the attribute in every supported policy namespace.
|
||||
* Resulting array of URIs is concatenation of URIs defined in all found
|
||||
* PolicyURIs attribute version.
|
||||
*/
|
||||
private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) {
|
||||
final StringBuilder policyUriBuffer = new StringBuilder();
|
||||
for (NamespaceVersion version : NamespaceVersion.values()) {
|
||||
final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString());
|
||||
if (value != null) {
|
||||
policyUriBuffer.append(value).append(" ");
|
||||
}
|
||||
}
|
||||
return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.api.policy.ModelUnmarshaller;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.PolicySourceModel;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion;
|
||||
import com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.XmlToken;
|
||||
import com.sun.xml.internal.ws.resources.PolicyMessages;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import javax.xml.ws.WebServiceException;
|
||||
|
||||
/**
|
||||
* Provides methods to unmarshal policies from a XMLStreamReader safely
|
||||
*
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
public class SafePolicyReader {
|
||||
|
||||
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(SafePolicyReader.class);
|
||||
|
||||
// urls of xml docs policies were read from
|
||||
private final Set<String> urlsRead = new HashSet<String>();
|
||||
|
||||
private final Set<String> qualifiedPolicyUris = new HashSet<String>();
|
||||
|
||||
|
||||
public final class PolicyRecord {
|
||||
PolicyRecord next;
|
||||
PolicySourceModel policyModel;
|
||||
Set<String> unresolvedURIs;
|
||||
private String uri;
|
||||
|
||||
PolicyRecord() {
|
||||
// nothing to initialize
|
||||
}
|
||||
|
||||
PolicyRecord insert(final PolicyRecord insertedRec) {
|
||||
if (null==insertedRec.unresolvedURIs || insertedRec.unresolvedURIs.isEmpty()) {
|
||||
insertedRec.next = this;
|
||||
return insertedRec;
|
||||
}
|
||||
final PolicyRecord head = this;
|
||||
PolicyRecord oneBeforeCurrent = null;
|
||||
PolicyRecord current;
|
||||
for (current = head ; null != current.next ; ) {
|
||||
if ((null != current.unresolvedURIs) && current.unresolvedURIs.contains(insertedRec.uri)) {
|
||||
if (null == oneBeforeCurrent) {
|
||||
insertedRec.next = current;
|
||||
return insertedRec;
|
||||
} else { // oneBeforeCurrent != null
|
||||
oneBeforeCurrent.next = insertedRec;
|
||||
insertedRec.next = current;
|
||||
return head;
|
||||
} // end-if-else oneBeforeCurrent == null
|
||||
}// end-if current record depends on inserted one
|
||||
if (insertedRec.unresolvedURIs.remove(current.uri) && (insertedRec.unresolvedURIs.isEmpty())) {
|
||||
insertedRec.next = current.next;
|
||||
current.next = insertedRec;
|
||||
return head;
|
||||
} // end-if one of unresolved URIs resolved by current record and thus unresolvedURIs empty
|
||||
oneBeforeCurrent = current;
|
||||
current = current.next;
|
||||
} // end for (current = head; null!=current.next; )
|
||||
insertedRec.next = null;
|
||||
current.next = insertedRec;
|
||||
return head;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the URI that identifies the policy.
|
||||
*
|
||||
* @param uri The fully qualified URI of the policy. May be a relative URI
|
||||
* if JAX-WS did not pass on any system id.
|
||||
* @param id The short ID of the policy. Used for error reporting.
|
||||
* @throws PolicyException If there already is a policy recorded with the
|
||||
* same id.
|
||||
*/
|
||||
public void setUri(final String uri, final String id) throws PolicyException {
|
||||
if (qualifiedPolicyUris.contains(uri)) {
|
||||
throw LOGGER.logSevereException(new PolicyException(PolicyMessages.WSP_1020_DUPLICATE_ID(id)));
|
||||
}
|
||||
this.uri = uri;
|
||||
qualifiedPolicyUris.add(uri);
|
||||
}
|
||||
|
||||
public String getUri() {
|
||||
return this.uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String result = uri;
|
||||
if (null!=next) {
|
||||
result += "->" + next.toString();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads a policy expression from the XML stream.
|
||||
*
|
||||
* The XMLStreamReader should be in START_ELEMENT state and point to the policy element.
|
||||
* The content of the stream is copied and then the copy is unmarshalled. The result
|
||||
* is returned as a PolicyRecord.
|
||||
*
|
||||
* @param reader The XMLStreamReader should be in START_ELEMENT state and point to the policy element.
|
||||
* @param baseUrl The system id of the document read by the reader.
|
||||
* @return The policy that was read from the XML stream.
|
||||
*/
|
||||
public PolicyRecord readPolicyElement(final XMLStreamReader reader, final String baseUrl) {
|
||||
if ((null == reader) || (!reader.isStartElement())) {
|
||||
return null;
|
||||
}
|
||||
final StringBuffer elementCode = new StringBuffer();
|
||||
final PolicyRecord policyRec = new PolicyRecord();
|
||||
final QName elementName = reader.getName();
|
||||
boolean insidePolicyReferenceAttr;
|
||||
int depth = 0;
|
||||
try{
|
||||
do {
|
||||
switch (reader.getEventType()) {
|
||||
case XMLStreamConstants.START_ELEMENT: // process start of next element
|
||||
QName curName = reader.getName();
|
||||
insidePolicyReferenceAttr = NamespaceVersion.resolveAsToken(curName) == XmlToken.PolicyReference;
|
||||
if (elementName.equals(curName)) { // it is our element !
|
||||
depth++; // we are then deeper
|
||||
}
|
||||
final StringBuffer xmlnsCode = new StringBuffer(); // take care about namespaces as well
|
||||
final Set<String> tmpNsSet = new HashSet<String>();
|
||||
if ((null == curName.getPrefix()) || ("".equals(curName.getPrefix()))) { // no prefix
|
||||
elementCode
|
||||
.append('<') // start tag
|
||||
.append(curName.getLocalPart());
|
||||
xmlnsCode
|
||||
.append(" xmlns=\"")
|
||||
.append(curName.getNamespaceURI())
|
||||
.append('"');
|
||||
|
||||
} else { // prefix presented
|
||||
elementCode
|
||||
.append('<') // start tag
|
||||
.append(curName.getPrefix())
|
||||
.append(':')
|
||||
.append(curName.getLocalPart());
|
||||
xmlnsCode
|
||||
.append(" xmlns:")
|
||||
.append(curName.getPrefix())
|
||||
.append("=\"")
|
||||
.append(curName.getNamespaceURI())
|
||||
.append('"');
|
||||
tmpNsSet.add(curName.getPrefix());
|
||||
}
|
||||
final int attrCount = reader.getAttributeCount(); // process element attributes
|
||||
final StringBuffer attrCode = new StringBuffer();
|
||||
for (int i=0; i < attrCount; i++) {
|
||||
boolean uriAttrFlg = false;
|
||||
if (insidePolicyReferenceAttr && "URI".equals(
|
||||
reader.getAttributeName(i).getLocalPart())) { // PolicyReference found
|
||||
uriAttrFlg = true;
|
||||
if (null == policyRec.unresolvedURIs) { // first such URI found
|
||||
policyRec.unresolvedURIs = new HashSet<String>(); // initialize URIs set
|
||||
}
|
||||
policyRec.unresolvedURIs.add( // add the URI
|
||||
relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl));
|
||||
} // end-if PolicyReference attribute found
|
||||
if ("xmlns".equals(reader.getAttributePrefix(i)) && tmpNsSet.contains(reader.getAttributeLocalName(i))) {
|
||||
continue; // do not append already defined ns
|
||||
}
|
||||
if ((null == reader.getAttributePrefix(i)) || ("".equals(reader.getAttributePrefix(i)))) { // no attribute prefix
|
||||
attrCode
|
||||
.append(' ')
|
||||
.append(reader.getAttributeLocalName(i))
|
||||
.append("=\"")
|
||||
.append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i))
|
||||
.append('"');
|
||||
} else { // prefix`presented
|
||||
attrCode
|
||||
.append(' ')
|
||||
.append(reader.getAttributePrefix(i))
|
||||
.append(':')
|
||||
.append(reader.getAttributeLocalName(i))
|
||||
.append("=\"")
|
||||
.append(uriAttrFlg ? relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl) : reader.getAttributeValue(i))
|
||||
.append('"');
|
||||
if (!tmpNsSet.contains(reader.getAttributePrefix(i))) {
|
||||
xmlnsCode
|
||||
.append(" xmlns:")
|
||||
.append(reader.getAttributePrefix(i))
|
||||
.append("=\"")
|
||||
.append(reader.getAttributeNamespace(i))
|
||||
.append('"');
|
||||
tmpNsSet.add(reader.getAttributePrefix(i));
|
||||
} // end if prefix already processed
|
||||
}
|
||||
} // end foreach attr
|
||||
elementCode
|
||||
.append(xmlnsCode) // complete the start element tag
|
||||
.append(attrCode)
|
||||
.append('>');
|
||||
break;
|
||||
//case XMLStreamConstants.ATTRIBUTE: Unreachable (I hope ;-)
|
||||
// break;
|
||||
//case XMLStreamConstants.NAMESPACE: Unreachable (I hope ;-)
|
||||
// break;
|
||||
case XMLStreamConstants.END_ELEMENT:
|
||||
curName = reader.getName();
|
||||
if (elementName.equals(curName)) { // it is our element !
|
||||
depth--; // go up
|
||||
}
|
||||
elementCode
|
||||
.append("</") // append appropriate XML code
|
||||
.append("".equals(curName.getPrefix())?"":curName.getPrefix()+':')
|
||||
.append(curName.getLocalPart())
|
||||
.append('>'); // complete the end element tag
|
||||
break;
|
||||
case XMLStreamConstants.CHARACTERS:
|
||||
elementCode.append(reader.getText()); // append text data
|
||||
break;
|
||||
case XMLStreamConstants.CDATA:
|
||||
elementCode
|
||||
.append("<![CDATA[") // append CDATA delimiters
|
||||
.append(reader.getText())
|
||||
.append("]]>");
|
||||
break;
|
||||
case XMLStreamConstants.COMMENT: // Ignore any comments
|
||||
break;
|
||||
case XMLStreamConstants.SPACE: // Ignore spaces as well
|
||||
break;
|
||||
}
|
||||
if (reader.hasNext() && depth>0) {
|
||||
reader.next();
|
||||
}
|
||||
} while (XMLStreamConstants.END_DOCUMENT!=reader.getEventType() && depth>0);
|
||||
policyRec.policyModel = ModelUnmarshaller.getUnmarshaller().unmarshalModel(
|
||||
new StringReader(elementCode.toString()));
|
||||
if (null != policyRec.policyModel.getPolicyId()) {
|
||||
policyRec.setUri(baseUrl + "#" + policyRec.policyModel.getPolicyId(), policyRec.policyModel.getPolicyId());
|
||||
} else if (policyRec.policyModel.getPolicyName() != null) {
|
||||
policyRec.setUri(policyRec.policyModel.getPolicyName(), policyRec.policyModel.getPolicyName());
|
||||
}
|
||||
} catch(Exception e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1013_EXCEPTION_WHEN_READING_POLICY_ELEMENT(elementCode.toString()), e));
|
||||
}
|
||||
urlsRead.add(baseUrl);
|
||||
return policyRec;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getUrlsRead() {
|
||||
return this.urlsRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reads policy reference element <wsp:PolicyReference/> and returns referenced policy URI as String
|
||||
*
|
||||
* @param reader The XMLStreamReader should be in START_ELEMENT state and point to the PolicyReference element.
|
||||
* @return The URI contained in the PolicyReference
|
||||
*/
|
||||
public String readPolicyReferenceElement(final XMLStreamReader reader) {
|
||||
try {
|
||||
if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) { // "PolicyReference" element interests me
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
if (XmlToken.resolveToken(reader.getAttributeName(i).getLocalPart()) == XmlToken.Uri) {
|
||||
final String uriValue = reader.getAttributeValue(i);
|
||||
reader.next();
|
||||
return uriValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
reader.next();
|
||||
return null;
|
||||
} catch(XMLStreamException e) {
|
||||
throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1001_XML_EXCEPTION_WHEN_PROCESSING_POLICY_REFERENCE(), e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Utility method to construct an absolute URL from a relative URI and a base URL.
|
||||
*
|
||||
* If the relativeUri already is an absolute URL, the method returns the relativeUri.
|
||||
*
|
||||
* @param relativeUri The relative URI
|
||||
* @param baseUri The base URL
|
||||
* @return The relative URI appended to the base URL. If relativeUri already is
|
||||
* an absolute URL, the method returns the relativeUri.
|
||||
*/
|
||||
public static String relativeToAbsoluteUrl(final String relativeUri, final String baseUri) {
|
||||
if ('#' != relativeUri.charAt(0)) { // TODO: escaped char could be an issue?
|
||||
return relativeUri; // absolute already
|
||||
}
|
||||
return (null == baseUri) ? relativeUri : baseUri + relativeUri;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws;
|
||||
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundFault;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
|
||||
import com.sun.xml.internal.ws.api.model.wsdl.WSDLObject;
|
||||
|
||||
import org.xml.sax.Locator;
|
||||
|
||||
/**
|
||||
* We need data from the WSDL operation that the default WSDLBoundFault does not
|
||||
* give us. This class holds all the necessary data.
|
||||
*
|
||||
* @author Fabian Ritzmann
|
||||
*/
|
||||
class WSDLBoundFaultContainer implements WSDLObject {
|
||||
|
||||
private final WSDLBoundFault boundFault;
|
||||
private final WSDLBoundOperation boundOperation;
|
||||
|
||||
public WSDLBoundFaultContainer(final WSDLBoundFault fault, final WSDLBoundOperation operation) {
|
||||
this.boundFault = fault;
|
||||
this.boundOperation = operation;
|
||||
}
|
||||
|
||||
public Locator getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public WSDLBoundFault getBoundFault() {
|
||||
return this.boundFault;
|
||||
}
|
||||
|
||||
public WSDLBoundOperation getBoundOperation() {
|
||||
return this.boundOperation;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws.spi;
|
||||
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMapKey;
|
||||
import java.util.Collection;
|
||||
import javax.xml.ws.WebServiceFeature;
|
||||
|
||||
/**
|
||||
* The service provider implementing this interface will be discovered and called to configure
|
||||
* wsdl model based on PolicyMap bound to it.
|
||||
*
|
||||
* @since JAX-WS 2.2
|
||||
*
|
||||
* @author japod
|
||||
* @author Fabian Ritzmann
|
||||
* @author Rama.Pulavarthi@sun.com
|
||||
*/
|
||||
public interface PolicyFeatureConfigurator {
|
||||
|
||||
/**
|
||||
* A callback method that allows to retrieve policy related information from provided PolicyMap
|
||||
* and return a list of corresponding WebServiceFeatures.
|
||||
*
|
||||
* @param key Identifies the policy in the policy map
|
||||
* @param policyMap Provides policies as a source of information on proper configuration
|
||||
* @return A list of features that correspond to the policy identified by the policy map key. May be empty but not null.
|
||||
* @throws PolicyException If an error occurred
|
||||
*/
|
||||
public Collection<WebServiceFeature> getFeatures(PolicyMapKey key, PolicyMap policyMap) throws PolicyException;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle in the LICENSE file that accompanied this code.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package com.sun.xml.internal.ws.policy.jaxws.spi;
|
||||
|
||||
import com.sun.xml.internal.ws.api.WSBinding;
|
||||
import com.sun.xml.internal.ws.api.model.SEIModel;
|
||||
import com.sun.xml.internal.ws.policy.PolicyException;
|
||||
import com.sun.xml.internal.ws.policy.PolicyMap;
|
||||
import com.sun.xml.internal.ws.policy.PolicySubject;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* The service provider implementing this interface will be discovered and called to extend created PolicyMap instance with additional policy
|
||||
* bindings. The call is performed directly after WSIT config file is parsed.
|
||||
*
|
||||
* @since JAX-WS 2.2
|
||||
* @author Marek Potociar (marek.potociar at sun.com)
|
||||
* @author Fabian Ritzmann
|
||||
* @author Rama.Pulavarthi@sun.com
|
||||
*/
|
||||
public interface PolicyMapConfigurator {
|
||||
|
||||
/**
|
||||
* A callback method that allows to retrieve policy related information from provided parameters
|
||||
* return a collection of new policies that are added to the map.
|
||||
*
|
||||
* When new policies are returned, the caller may merge them with existing policies
|
||||
* in the policy map.
|
||||
*
|
||||
* @param policyMap This map contains the policies that were already created
|
||||
* @param model The WSDL model of the service
|
||||
* @param wsBinding The binding of the service
|
||||
* @return A collection of policies and the subject to which they are attached.
|
||||
* May return null or an empty collection.
|
||||
* @throws PolicyException Throw this exception if an error occurs
|
||||
*/
|
||||
Collection<PolicySubject> update(PolicyMap policyMap, SEIModel model, WSBinding wsBinding) throws PolicyException;
|
||||
}
|
||||
Reference in New Issue
Block a user