use of com.sun.xml.ws.policy.PolicySubject in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method addBindingOperationFaultExtension.
@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();
}
use of com.sun.xml.ws.policy.PolicySubject in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method selectAndProcessSubject.
/**
* 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();
}
use of com.sun.xml.ws.policy.PolicySubject in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method start.
@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<>();
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();
}
}
use of com.sun.xml.ws.policy.PolicySubject in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method addDefinitionsExtension.
@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<>();
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();
}
}
use of com.sun.xml.ws.policy.PolicySubject in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method selectAndProcessSubject.
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 (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();
}
Aggregations