use of jakarta.xml.ws.WebServiceException 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 jakarta.xml.ws.WebServiceException 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();
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class JavaMethodImpl method freeze.
/*package*/
void freeze(WSDLPort portType) {
this.wsdlOperation = portType.getBinding().get(new QName(portType.getBinding().getPortType().getName().getNamespaceURI(), getOperationName()));
// TODO: replace this with proper error handling
if (wsdlOperation == null)
throw new WebServiceException("Method " + seiMethod.getName() + " is exposed as WebMethod, but there is no corresponding wsdl operation with name " + operationName + " in the wsdl:portType" + portType.getBinding().getPortType().getName());
// set the values from WSDLModel, if such annotations are not present or defaulted
if (inputAction.equals("")) {
inputAction = wsdlOperation.getOperation().getInput().getAction();
} else if (!inputAction.equals(wsdlOperation.getOperation().getInput().getAction()))
// TODO input action might be from @Action or WebMethod(action)
LOGGER.warning("Input Action on WSDL operation " + wsdlOperation.getName().getLocalPart() + " and @Action on its associated Web Method " + seiMethod.getName() + " did not match and will cause problems in dispatching the requests");
if (!mep.isOneWay()) {
if (outputAction.equals(""))
outputAction = wsdlOperation.getOperation().getOutput().getAction();
for (CheckedExceptionImpl ce : exceptions) {
if (ce.getFaultAction().equals("")) {
QName detailQName = ce.getDetailType().tagName;
WSDLFault wsdlfault = wsdlOperation.getOperation().getFault(detailQName);
if (wsdlfault == null) {
// mismatch between wsdl model and SEI model, log a warning and use SEI model for Action determination
LOGGER.warning("Mismatch between Java model and WSDL model found, For wsdl operation " + wsdlOperation.getName() + ",There is no matching wsdl fault with detail QName " + ce.getDetailType().tagName);
ce.setFaultAction(ce.getDefaultFaultAction());
} else {
ce.setFaultAction(wsdlfault.getAction());
}
}
}
}
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLParserExtension method postFinished.
// 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();
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class SafePolicyReader method readPolicyElement.
/**
* 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 StringBuilder elementCode = new StringBuilder();
final PolicyRecord policyRec = new PolicyRecord();
final QName elementName = reader.getName();
boolean insidePolicyReferenceAttr;
int depth = 0;
try {
do {
switch(reader.getEventType()) {
case // process start of next element
XMLStreamConstants.START_ELEMENT:
QName curName = reader.getName();
insidePolicyReferenceAttr = NamespaceVersion.resolveAsToken(curName) == XmlToken.PolicyReference;
if (elementName.equals(curName)) {
// it is our element !
// we are then deeper
depth++;
}
// take care about namespaces as well
final StringBuilder xmlnsCode = new StringBuilder();
final Set<String> tmpNsSet = new HashSet<>();
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());
}
// process element attributes
final int attrCount = reader.getAttributeCount();
final StringBuilder attrCode = new StringBuilder();
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
// initialize URIs set
policyRec.unresolvedURIs = new HashSet<>();
}
// add the URI
policyRec.unresolvedURIs.add(relativeToAbsoluteUrl(reader.getAttributeValue(i), baseUrl));
}
// end-if PolicyReference attribute found
if ("xmlns".equals(reader.getAttributePrefix(i)) && tmpNsSet.contains(reader.getAttributeLocalName(i))) {
// do not append already defined ns
continue;
}
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(// complete the start element tag
xmlnsCode).append(attrCode).append('>');
break;
// break;
case XMLStreamConstants.END_ELEMENT:
curName = reader.getName();
if (elementName.equals(curName)) {
// it is our element !
// go up
depth--;
}
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:
// append text data
elementCode.append(reader.getText());
break;
case XMLStreamConstants.CDATA:
elementCode.append(// append CDATA delimiters
"<![CDATA[").append(reader.getText()).append("]]>");
break;
case // Ignore any comments
XMLStreamConstants.COMMENT:
break;
case // Ignore spaces as well
XMLStreamConstants.SPACE:
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;
}
Aggregations