use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class StreamMessage method readEnvelope.
private static void readEnvelope(StreamMessage message) {
if (message.envelopeReader == null)
return;
XMLStreamReader reader = message.envelopeReader;
message.envelopeReader = null;
SOAPVersion soapVersion = message.soapVersion;
// Move to soap:Envelope and verify
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT)
XMLStreamReaderUtil.nextElementContent(reader);
XMLStreamReaderUtil.verifyReaderState(reader, XMLStreamConstants.START_ELEMENT);
if (SOAP_ENVELOPE.equals(reader.getLocalName()) && !soapVersion.nsUri.equals(reader.getNamespaceURI())) {
throw new VersionMismatchException(soapVersion, soapVersion.nsUri, reader.getNamespaceURI());
}
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_ENVELOPE);
TagInfoset envelopeTag = new TagInfoset(reader);
// Collect namespaces on soap:Envelope
Map<String, String> namespaces = new HashMap<>();
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
// Move to next element
XMLStreamReaderUtil.nextElementContent(reader);
XMLStreamReaderUtil.verifyReaderState(reader, javax.xml.stream.XMLStreamConstants.START_ELEMENT);
HeaderList headers = null;
TagInfoset headerTag = null;
if (reader.getLocalName().equals(SOAP_HEADER) && reader.getNamespaceURI().equals(soapVersion.nsUri)) {
headerTag = new TagInfoset(reader);
// Collect namespaces on soap:Header
for (int i = 0; i < reader.getNamespaceCount(); i++) {
namespaces.put(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
}
// skip <soap:Header>
XMLStreamReaderUtil.nextElementContent(reader);
// If SOAP header blocks are present (i.e. not <soap:Header/>)
if (reader.getEventType() == XMLStreamConstants.START_ELEMENT) {
headers = new HeaderList(soapVersion);
try {
// Cache SOAP header blocks
StreamHeaderDecoder headerDecoder = SOAPVersion.SOAP_11.equals(soapVersion) ? SOAP11StreamHeaderDecoder : SOAP12StreamHeaderDecoder;
cacheHeaders(reader, namespaces, headers, headerDecoder);
} catch (XMLStreamException e) {
// TODO need to throw more meaningful exception
throw new WebServiceException(e);
}
}
// Move to soap:Body
XMLStreamReaderUtil.nextElementContent(reader);
}
// Verify that <soap:Body> is present
XMLStreamReaderUtil.verifyTag(reader, soapVersion.nsUri, SOAP_BODY);
TagInfoset bodyTag = new TagInfoset(reader);
String bodyPrologue = XMLStreamReaderUtil.nextWhiteSpaceContent(reader);
message.init(envelopeTag, headerTag, message.attachmentSet, headers, bodyPrologue, bodyTag, null, reader, soapVersion);
// when there's no payload,
// it's tempting to use EmptyMessageImpl, but it doesn't preserve the infoset
// of <envelope>,<header>, and <body>, so we need to stick to StreamMessage.
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class AbstractSEIModelImpl method createJAXBContext.
private void createJAXBContext() {
final List<TypeInfo> types = getAllTypeInfos();
final List<Class> cls = new ArrayList<>(types.size() + additionalClasses.size());
cls.addAll(additionalClasses);
for (TypeInfo type : types) {
cls.add((Class) type.type);
}
try {
// jaxbContext = JAXBRIContext.newInstance(cls, types, targetNamespace, false);
// Need to avoid doPriv block once JAXB is fixed. Afterwards, use the above
bindingContext = AccessController.doPrivileged(new PrivilegedExceptionAction<>() {
@Override
public BindingContext run() throws Exception {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Creating JAXBContext with classes={0} and types={1}", new Object[] { cls, types });
}
UsesJAXBContextFeature f = features.get(UsesJAXBContextFeature.class);
com.oracle.webservices.api.databinding.DatabindingModeFeature dmf = features.get(com.oracle.webservices.api.databinding.DatabindingModeFeature.class);
JAXBContextFactory factory = f != null ? f.getFactory() : null;
if (factory == null)
factory = JAXBContextFactory.DEFAULT;
// return factory.createJAXBContext(AbstractSEIModelImpl.this,cls,types);
databindingInfo.properties().put(JAXBContextFactory.class.getName(), factory);
if (dmf != null) {
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, "DatabindingModeFeature in SEI specifies mode: {0}", dmf.getMode());
databindingInfo.setDatabindingMode(dmf.getMode());
}
if (f != null)
databindingInfo.setDatabindingMode(BindingContextFactory.DefaultDatabindingMode);
databindingInfo.setClassLoader(classLoader);
databindingInfo.contentClasses().addAll(cls);
databindingInfo.typeInfos().addAll(types);
databindingInfo.properties().put("c14nSupport", Boolean.FALSE);
databindingInfo.setDefaultNamespace(AbstractSEIModelImpl.this.getDefaultSchemaNamespace());
BindingContext bc = BindingContextFactory.create(databindingInfo);
if (LOGGER.isLoggable(Level.FINE))
LOGGER.log(Level.FINE, "Created binding context: {0}", bc.getClass().getName());
// System.out.println("---------------------- databinding " + bc);
return bc;
}
});
// createBridgeMap(types);
createBondMap(types);
} catch (PrivilegedActionException e) {
throw new WebServiceException(ModelerMessages.UNABLE_TO_CREATE_JAXB_CONTEXT(), e);
}
knownNamespaceURIs = new ArrayList<>();
for (String namespace : bindingContext.getKnownNamespaceURIs()) {
if (namespace.length() > 0) {
if (!namespace.equals(SOAPNamespaceConstants.XSD) && !namespace.equals(SOAPNamespaceConstants.XMLNS))
knownNamespaceURIs.add(namespace);
}
}
marshallers = new Pool.Marshaller(jaxbContext);
// return getJAXBContext();
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class PolicyUtil method getPortScopedFeatures.
/**
* 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<>();
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;
}
use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.
the class PolicyWSDLGeneratorExtension method writePolicyOrReferenceIt.
/**
* 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());
}
}
}
use of jakarta.xml.ws.WebServiceException 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();
}
}
Aggregations