feat(jdk8): move files to new folder to avoid resources compiled.

This commit is contained in:
2025-09-07 15:25:52 +08:00
parent 3f0047bf6f
commit 8c35cfb1c0
17415 changed files with 217 additions and 213 deletions

View File

@@ -0,0 +1,420 @@
/*
* 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.addressing;
import com.sun.xml.internal.ws.api.server.*;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory;
import com.sun.xml.internal.ws.util.xml.XMLStreamWriterFilter;
import com.sun.xml.internal.ws.util.xml.XMLStreamReaderToXMLStreamWriter;
import com.sun.xml.internal.ws.server.WSEndpointImpl;
import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
import com.sun.istack.internal.Nullable;
import com.sun.istack.internal.NotNull;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.namespace.NamespaceContext;
import java.io.IOException;
import java.util.List;
import java.util.Collection;
import java.util.Collections;
/**
* This class acts as a filter for the Extension elements in the wsa:EndpointReference in the wsdl.
* In addition to filtering the EPR extensions from WSDL, it adds the extensions configured by the JAX-WS runtime
* specifc to an endpoint.
*
* @author Rama Pulavarthi
*/
public class EPRSDDocumentFilter implements SDDocumentFilter {
private final WSEndpointImpl<?> endpoint;
//initialize lazily
List<BoundEndpoint> beList;
public EPRSDDocumentFilter(@NotNull WSEndpointImpl<?> endpoint) {
this.endpoint = endpoint;
}
private @Nullable WSEndpointImpl<?> getEndpoint(String serviceName, String portName) {
if (serviceName == null || portName == null)
return null;
if (endpoint.getServiceName().getLocalPart().equals(serviceName) && endpoint.getPortName().getLocalPart().equals(portName))
return endpoint;
if(beList == null) {
//check if it is run in a Java EE Container and get hold of other endpoints in the application
Module module = endpoint.getContainer().getSPI(Module.class);
if (module != null) {
beList = module.getBoundEndpoints();
} else {
beList = Collections.<BoundEndpoint>emptyList();
}
}
for (BoundEndpoint be : beList) {
WSEndpoint wse = be.getEndpoint();
if (wse.getServiceName().getLocalPart().equals(serviceName) && wse.getPortName().getLocalPart().equals(portName)) {
return (WSEndpointImpl) wse;
}
}
return null;
}
public XMLStreamWriter filter(SDDocument doc, XMLStreamWriter w) throws XMLStreamException, IOException {
if (!doc.isWSDL()) {
return w;
}
return new XMLStreamWriterFilter(w) {
private boolean eprExtnFilterON = false; //when true, all writer events are filtered out
private boolean portHasEPR = false;
private int eprDepth = -1; // -1 -> outside wsa:epr, 0 -> on wsa:epr start/end , > 0 inside wsa:epr
private String serviceName = null; //non null when inside wsdl:service scope
private boolean onService = false; //flag to get service name when on wsdl:service element start
private int serviceDepth = -1; // -1 -> outside wsdl:service, 0 -> on wsdl:service start/end , > 0 inside wsdl:service
private String portName = null; //non null when inside wsdl:port scope
private boolean onPort = false; //flag to get port name when on wsdl:port element start
private int portDepth = -1; // -1 -> outside wsdl:port, 0 -> on wsdl:port start/end , > 0 inside wsdl:port
private String portAddress; // when a complete epr is written, endpoint address is used as epr address
private boolean onPortAddress = false; //flag to get endpoint address when on soap:address element start
private void handleStartElement(String localName, String namespaceURI) throws XMLStreamException {
resetOnElementFlags();
if (serviceDepth >= 0) {
serviceDepth++;
}
if (portDepth >= 0) {
portDepth++;
}
if (eprDepth >= 0) {
eprDepth++;
}
if (namespaceURI.equals(WSDLConstants.QNAME_SERVICE.getNamespaceURI()) && localName.equals(WSDLConstants.QNAME_SERVICE.getLocalPart())) {
onService = true;
serviceDepth = 0;
} else if (namespaceURI.equals(WSDLConstants.QNAME_PORT.getNamespaceURI()) && localName.equals(WSDLConstants.QNAME_PORT.getLocalPart())) {
if (serviceDepth >= 1) {
onPort = true;
portDepth = 0;
}
} else if (namespaceURI.equals(W3CAddressingConstants.WSA_NAMESPACE_NAME) && localName.equals("EndpointReference")) {
if (serviceDepth >= 1 && portDepth >= 1) {
portHasEPR = true;
eprDepth = 0;
}
} else if ((namespaceURI.equals(WSDLConstants.NS_SOAP_BINDING_ADDRESS.getNamespaceURI()) || namespaceURI.equals(WSDLConstants.NS_SOAP12_BINDING_ADDRESS.getNamespaceURI()))
&& localName.equals("address") && portDepth ==1) {
onPortAddress = true;
}
WSEndpoint endpoint = getEndpoint(serviceName,portName);
//filter epr for only for the port corresponding to this endpoint
//if (service.getLocalPart().equals(serviceName) && port.getLocalPart().equals(portName)) {
if ( endpoint != null) {
if ((eprDepth == 1) && !namespaceURI.equals(W3CAddressingConstants.WSA_NAMESPACE_NAME)) {
//epr extension element
eprExtnFilterON = true;
}
/*
if (eprExtnFilterON) {
writeEPRExtensions();
}
*/
}
}
private void resetOnElementFlags() {
if (onService) {
onService = false;
}
if (onPort) {
onPort = false;
}
if (onPortAddress) {
onPortAddress = false;
}
}
private void writeEPRExtensions(Collection<WSEndpointReference.EPRExtension> eprExtns) throws XMLStreamException {
if (eprExtns != null) {
for (WSEndpointReference.EPRExtension e : eprExtns) {
XMLStreamReaderToXMLStreamWriter c = new XMLStreamReaderToXMLStreamWriter();
XMLStreamReader r = e.readAsXMLStreamReader();
c.bridge(r, writer);
XMLStreamReaderFactory.recycle(r);
}
}
}
@Override
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
handleStartElement(localName, namespaceURI);
if (!eprExtnFilterON) {
super.writeStartElement(prefix, localName, namespaceURI);
}
}
@Override
public void writeStartElement(String namespaceURI, String localName) throws XMLStreamException {
handleStartElement(localName, namespaceURI);
if (!eprExtnFilterON) {
super.writeStartElement(namespaceURI, localName);
}
}
@Override
public void writeStartElement(String localName) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeStartElement(localName);
}
}
private void handleEndElement() throws XMLStreamException {
resetOnElementFlags();
//End of wsdl:port, write complete EPR if not present.
if (portDepth == 0) {
if (!portHasEPR && getEndpoint(serviceName,portName) != null) {
//write the complete EPR with address.
writer.writeStartElement(AddressingVersion.W3C.getPrefix(),"EndpointReference", AddressingVersion.W3C.nsUri );
writer.writeNamespace(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.nsUri);
writer.writeStartElement(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.eprType.address, AddressingVersion.W3C.nsUri);
writer.writeCharacters(portAddress);
writer.writeEndElement();
writeEPRExtensions(getEndpoint(serviceName, portName).getEndpointReferenceExtensions());
writer.writeEndElement();
}
}
//End of wsa:EndpointReference, write EPR extension elements
if (eprDepth == 0) {
if (portHasEPR && getEndpoint(serviceName,portName) != null) {
writeEPRExtensions(getEndpoint(serviceName, portName).getEndpointReferenceExtensions());
}
eprExtnFilterON = false;
}
if(serviceDepth >= 0 ) {
serviceDepth--;
}
if(portDepth >= 0) {
portDepth--;
}
if(eprDepth >=0) {
eprDepth--;
}
if (serviceDepth == -1) {
serviceName = null;
}
if (portDepth == -1) {
portHasEPR = false;
portAddress = null;
portName = null;
}
}
@Override
public void writeEndElement() throws XMLStreamException {
handleEndElement();
if (!eprExtnFilterON) {
super.writeEndElement();
}
}
private void handleAttribute(String localName, String value) {
if (localName.equals("name")) {
if (onService) {
serviceName = value;
onService = false;
} else if (onPort) {
portName = value;
onPort = false;
}
}
if (localName.equals("location") && onPortAddress) {
portAddress = value;
}
}
@Override
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException {
handleAttribute(localName, value);
if (!eprExtnFilterON) {
super.writeAttribute(prefix, namespaceURI, localName, value);
}
}
@Override
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException {
handleAttribute(localName, value);
if (!eprExtnFilterON) {
super.writeAttribute(namespaceURI, localName, value);
}
}
@Override
public void writeAttribute(String localName, String value) throws XMLStreamException {
handleAttribute(localName, value);
if (!eprExtnFilterON) {
super.writeAttribute(localName, value);
}
}
@Override
public void writeEmptyElement(String namespaceURI, String localName) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeEmptyElement(namespaceURI, localName);
}
}
@Override
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeNamespace(prefix, namespaceURI);
}
}
@Override
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
if (!eprExtnFilterON) {
super.setNamespaceContext(context);
}
}
@Override
public void setDefaultNamespace(String uri) throws XMLStreamException {
if (!eprExtnFilterON) {
super.setDefaultNamespace(uri);
}
}
@Override
public void setPrefix(String prefix, String uri) throws XMLStreamException {
if (!eprExtnFilterON) {
super.setPrefix(prefix, uri);
}
}
@Override
public void writeProcessingInstruction(String target, String data) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeProcessingInstruction(target, data);
}
}
@Override
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeEmptyElement(prefix, localName, namespaceURI);
}
}
@Override
public void writeCData(String data) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeCData(data);
}
}
@Override
public void writeCharacters(String text) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeCharacters(text);
}
}
@Override
public void writeComment(String data) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeComment(data);
}
}
@Override
public void writeDTD(String dtd) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeDTD(dtd);
}
}
@Override
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeDefaultNamespace(namespaceURI);
}
}
@Override
public void writeEmptyElement(String localName) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeEmptyElement(localName);
}
}
@Override
public void writeEntityRef(String name) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeEntityRef(name);
}
}
@Override
public void writeProcessingInstruction(String target) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeProcessingInstruction(target);
}
}
@Override
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException {
if (!eprExtnFilterON) {
super.writeCharacters(text, start, len);
}
}
};
}
}

View File

@@ -0,0 +1,411 @@
/*
* 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.addressing;
import com.sun.istack.internal.Nullable;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.stream.buffer.XMLStreamBufferSource;
import com.sun.xml.internal.stream.buffer.stax.StreamWriterBufferCreator;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.developer.MemberSubmissionEndpointReference;
import com.sun.xml.internal.ws.util.DOMUtil;
import com.sun.xml.internal.ws.util.xml.XmlUtil;
import com.sun.xml.internal.ws.wsdl.parser.WSDLConstants;
import com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants;
import org.w3c.dom.*;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.transform.dom.DOMResult;
import javax.xml.ws.EndpointReference;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.wsaddressing.W3CEndpointReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* @author Rama Pulavarthi
*/
public class EndpointReferenceUtil {
/**
* Gives the EPR based on the clazz. It may need to perform tranformation from
* W3C EPR to MS EPR or vise-versa.
*/
public static <T extends EndpointReference> T transform(Class<T> clazz, @NotNull EndpointReference epr) {
assert epr != null;
if (clazz.isAssignableFrom(W3CEndpointReference.class)) {
if (epr instanceof W3CEndpointReference) {
return (T) epr;
} else if (epr instanceof MemberSubmissionEndpointReference) {
return (T) toW3CEpr((MemberSubmissionEndpointReference) epr);
}
} else if (clazz.isAssignableFrom(MemberSubmissionEndpointReference.class)) {
if (epr instanceof W3CEndpointReference) {
return (T) toMSEpr((W3CEndpointReference) epr);
} else if (epr instanceof MemberSubmissionEndpointReference) {
return (T) epr;
}
}
//This must be an EPR that we dont know
throw new WebServiceException("Unknwon EndpointReference: " + epr.getClass());
}
//TODO: bit of redundency on writes of w3c epr, should modularize it
private static W3CEndpointReference toW3CEpr(MemberSubmissionEndpointReference msEpr) {
StreamWriterBufferCreator writer = new StreamWriterBufferCreator();
w3cMetadataWritten = false;
try {
writer.writeStartDocument();
writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
"EndpointReference", AddressingVersion.W3C.nsUri);
writer.writeNamespace(AddressingVersion.W3C.getPrefix(),
AddressingVersion.W3C.nsUri);
//write wsa:Address
writer.writeStartElement(AddressingVersion.W3C.getPrefix(),
AddressingVersion.W3C.eprType.address
, AddressingVersion.W3C.nsUri);
writer.writeCharacters(msEpr.addr.uri);
writer.writeEndElement();
//TODO: write extension attributes on wsa:Address
if ((msEpr.referenceProperties != null && msEpr.referenceProperties.elements.size() > 0) ||
(msEpr.referenceParameters != null && msEpr.referenceParameters.elements.size() > 0)) {
writer.writeStartElement(AddressingVersion.W3C.getPrefix(), "ReferenceParameters", AddressingVersion.W3C.nsUri);
//write ReferenceProperties
if (msEpr.referenceProperties != null) {
for (Element e : msEpr.referenceProperties.elements) {
DOMUtil.serializeNode(e, writer);
}
}
//write referenceParameters
if (msEpr.referenceParameters != null) {
for (Element e : msEpr.referenceParameters.elements) {
DOMUtil.serializeNode(e, writer);
}
}
writer.writeEndElement();
}
// Supress writing ServiceName and EndpointName in W3CEPR,
// Until the ns for those metadata elements is resolved.
/*
//Write Interface info
if (msEpr.portTypeName != null) {
writeW3CMetadata(writer);
writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
AddressingVersion.W3C.eprType.portTypeName ,
AddressingVersion.W3C.wsdlNsUri);
writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
AddressingVersion.W3C.wsdlNsUri);
String portTypePrefix = fixNull(msEpr.portTypeName.name.getPrefix());
writer.writeNamespace(portTypePrefix, msEpr.portTypeName.name.getNamespaceURI());
if (portTypePrefix.equals(""))
writer.writeCharacters(msEpr.portTypeName.name.getLocalPart());
else
writer.writeCharacters(portTypePrefix + ":" + msEpr.portTypeName.name.getLocalPart());
writer.writeEndElement();
}
if (msEpr.serviceName != null) {
writeW3CMetadata(writer);
//Write service and Port info
writer.writeStartElement(AddressingVersion.W3C.getWsdlPrefix(),
AddressingVersion.W3C.eprType.serviceName ,
AddressingVersion.W3C.wsdlNsUri);
writer.writeNamespace(AddressingVersion.W3C.getWsdlPrefix(),
AddressingVersion.W3C.wsdlNsUri);
String servicePrefix = fixNull(msEpr.serviceName.name.getPrefix());
if (msEpr.serviceName.portName != null)
writer.writeAttribute(AddressingVersion.W3C.eprType.portName,
msEpr.serviceName.portName);
writer.writeNamespace(servicePrefix, msEpr.serviceName.name.getNamespaceURI());
if (servicePrefix.length() > 0)
writer.writeCharacters(servicePrefix + ":" + msEpr.serviceName.name.getLocalPart());
else
writer.writeCharacters(msEpr.serviceName.name.getLocalPart());
writer.writeEndElement();
}
*/
//TODO: revisit this
Element wsdlElement = null;
//Check for wsdl in extension elements
if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
for (Element e : msEpr.elements) {
if(e.getNamespaceURI().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI()) &&
e.getLocalName().equals(MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart())) {
NodeList nl = e.getElementsByTagNameNS(WSDLConstants.NS_WSDL,
WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
if(nl != null) {
wsdlElement = (Element) nl.item(0);
}
}
}
}
//write WSDL
if (wsdlElement != null) {
DOMUtil.serializeNode(wsdlElement, writer);
}
if (w3cMetadataWritten) {
writer.writeEndElement();
}
//TODO revisit this
//write extension elements
if ((msEpr.elements != null) && (msEpr.elements.size() > 0)) {
for (Element e : msEpr.elements) {
if (e.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
e.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
// Don't write it as this is written already in Metadata
}
DOMUtil.serializeNode(e, writer);
}
}
//TODO:write extension attributes
//</EndpointReference>
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
} catch (XMLStreamException e) {
throw new WebServiceException(e);
}
return new W3CEndpointReference(new XMLStreamBufferSource(writer.getXMLStreamBuffer()));
}
private static boolean w3cMetadataWritten = false;
// private static void writeW3CMetadata(StreamWriterBufferCreator writer) throws XMLStreamException {
// if (!w3cMetadataWritten) {
// writer.writeStartElement(AddressingVersion.W3C.getPrefix(), AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart(), AddressingVersion.W3C.nsUri);
// w3cMetadataWritten = true;
// }
// }
//
private static MemberSubmissionEndpointReference toMSEpr(W3CEndpointReference w3cEpr) {
DOMResult result = new DOMResult();
w3cEpr.writeTo(result);
Node eprNode = result.getNode();
Element e = DOMUtil.getFirstElementChild(eprNode);
if (e == null) {
return null;
}
MemberSubmissionEndpointReference msEpr = new MemberSubmissionEndpointReference();
NodeList nodes = e.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNodeType() == Node.ELEMENT_NODE) {
Element child = (Element) nodes.item(i);
if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) &&
child.getLocalName().equals(AddressingVersion.W3C.eprType.address)) {
if (msEpr.addr == null) {
msEpr.addr = new MemberSubmissionEndpointReference.Address();
}
msEpr.addr.uri = XmlUtil.getTextForNode(child);
} else if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) &&
child.getLocalName().equals("ReferenceParameters")) {
NodeList refParams = child.getChildNodes();
for (int j = 0; j < refParams.getLength(); j++) {
if (refParams.item(j).getNodeType() == Node.ELEMENT_NODE) {
if (msEpr.referenceParameters == null) {
msEpr.referenceParameters = new MemberSubmissionEndpointReference.Elements();
msEpr.referenceParameters.elements = new ArrayList<Element>();
}
msEpr.referenceParameters.elements.add((Element) refParams.item(j));
}
}
} else if (child.getNamespaceURI().equals(AddressingVersion.W3C.nsUri) &&
child.getLocalName().equals(AddressingVersion.W3C.eprType.wsdlMetadata.getLocalPart())) {
NodeList metadata = child.getChildNodes();
String wsdlLocation = child.getAttributeNS(W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_NAMESPACE,
W3CAddressingMetadataConstants.WSAM_WSDLI_ATTRIBUTE_LOCALNAME);
Element wsdlDefinitions = null;
for (int j = 0; j < metadata.getLength(); j++) {
Node node = metadata.item(j);
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element elm = (Element) node;
if ((elm.getNamespaceURI().equals(AddressingVersion.W3C.wsdlNsUri) ||
elm.getNamespaceURI().equals(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME)) &&
elm.getLocalName().equals(AddressingVersion.W3C.eprType.serviceName)) {
msEpr.serviceName = new MemberSubmissionEndpointReference.ServiceNameType();
msEpr.serviceName.portName = elm.getAttribute(AddressingVersion.W3C.eprType.portName);
String service = elm.getTextContent();
String prefix = XmlUtil.getPrefix(service);
String name = XmlUtil.getLocalPart(service);
//if there is no service name then its not a valid EPR but lets continue as its optional anyway
if (name == null) {
continue;
}
if (prefix != null) {
String ns = elm.lookupNamespaceURI(prefix);
if (ns != null) {
msEpr.serviceName.name = new QName(ns, name, prefix);
}
} else {
msEpr.serviceName.name = new QName(null, name);
}
msEpr.serviceName.attributes = getAttributes(elm);
} else if ((elm.getNamespaceURI().equals(AddressingVersion.W3C.wsdlNsUri) ||
elm.getNamespaceURI().equals(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME)) &&
elm.getLocalName().equals(AddressingVersion.W3C.eprType.portTypeName)) {
msEpr.portTypeName = new MemberSubmissionEndpointReference.AttributedQName();
String portType = elm.getTextContent();
String prefix = XmlUtil.getPrefix(portType);
String name = XmlUtil.getLocalPart(portType);
//if there is no portType name then its not a valid EPR but lets continue as its optional anyway
if (name == null) {
continue;
}
if (prefix != null) {
String ns = elm.lookupNamespaceURI(prefix);
if (ns != null) {
msEpr.portTypeName.name = new QName(ns, name, prefix);
}
} else {
msEpr.portTypeName.name = new QName(null, name);
}
msEpr.portTypeName.attributes = getAttributes(elm);
} else if(elm.getNamespaceURI().equals(WSDLConstants.NS_WSDL) &&
elm.getLocalName().equals(WSDLConstants.QNAME_DEFINITIONS.getLocalPart())) {
wsdlDefinitions = elm;
} else {
//TODO : Revisit this
//its extensions in META-DATA and should be copied to extensions in MS EPR
if (msEpr.elements == null) {
msEpr.elements = new ArrayList<Element>();
}
msEpr.elements.add(elm);
}
}
Document doc = DOMUtil.createDom();
Element mexEl = doc.createElementNS(MemberSubmissionAddressingConstants.MEX_METADATA.getNamespaceURI(),
MemberSubmissionAddressingConstants.MEX_METADATA.getPrefix() + ":"
+ MemberSubmissionAddressingConstants.MEX_METADATA.getLocalPart());
Element metadataEl = doc.createElementNS(MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getNamespaceURI(),
MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getPrefix() + ":"
+ MemberSubmissionAddressingConstants.MEX_METADATA_SECTION.getLocalPart());
metadataEl.setAttribute(MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_ATTRIBUTE,
MemberSubmissionAddressingConstants.MEX_METADATA_DIALECT_VALUE);
if (wsdlDefinitions == null && wsdlLocation != null && !wsdlLocation.equals("")) {
wsdlLocation = wsdlLocation.trim();
String wsdlTns = wsdlLocation.substring(0, wsdlLocation.indexOf(' '));
wsdlLocation = wsdlLocation.substring(wsdlLocation.indexOf(' ') + 1);
Element wsdlEl = doc.createElementNS(WSDLConstants.NS_WSDL,
WSDLConstants.PREFIX_NS_WSDL + ":"
+ WSDLConstants.QNAME_DEFINITIONS.getLocalPart());
Element wsdlImportEl = doc.createElementNS(WSDLConstants.NS_WSDL,
WSDLConstants.PREFIX_NS_WSDL + ":"
+ WSDLConstants.QNAME_IMPORT.getLocalPart());
wsdlImportEl.setAttribute("namespace", wsdlTns);
wsdlImportEl.setAttribute("location", wsdlLocation);
wsdlEl.appendChild(wsdlImportEl);
metadataEl.appendChild(wsdlEl);
} else if(wsdlDefinitions != null){
metadataEl.appendChild(wsdlDefinitions);
}
mexEl.appendChild(metadataEl);
if (msEpr.elements == null) {
msEpr.elements = new ArrayList<Element>();
}
msEpr.elements.add(mexEl);
} else {
//its extensions
if (msEpr.elements == null) {
msEpr.elements = new ArrayList<Element>();
}
msEpr.elements.add((Element) child);
}
} else if (nodes.item(i).getNodeType() == Node.ATTRIBUTE_NODE) {
Node n = nodes.item(i);
if (msEpr.attributes == null) {
msEpr.attributes = new HashMap<QName, String>();
String prefix = fixNull(n.getPrefix());
String ns = fixNull(n.getNamespaceURI());
String localName = n.getLocalName();
msEpr.attributes.put(new QName(ns, localName, prefix), n.getNodeValue());
}
}
}
return msEpr;
}
private static Map<QName, String> getAttributes(Node node) {
Map<QName, String> attribs = null;
NamedNodeMap nm = node.getAttributes();
for (int i = 0; i < nm.getLength(); i++) {
if (attribs == null) {
attribs = new HashMap<QName, String>();
}
Node n = nm.item(i);
String prefix = fixNull(n.getPrefix());
String ns = fixNull(n.getNamespaceURI());
String localName = n.getLocalName();
if (prefix.equals("xmlns") || prefix.length() == 0 && localName.equals("xmlns")) {
continue;
}
//exclude some attributes
if (!localName.equals(AddressingVersion.W3C.eprType.portName)) {
attribs.put(new QName(ns, localName, prefix), n.getNodeValue());
}
}
return attribs;
}
private static
@NotNull
String fixNull(@Nullable String s) {
if (s == null) {
return "";
} else {
return s;
}
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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.addressing;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
import com.sun.xml.internal.ws.addressing.W3CAddressingConstants;
/**
* @author Arun Gupta
*/
@XmlRootElement(name="ProblemAction", namespace= W3CAddressingConstants.WSA_NAMESPACE_NAME)
public class ProblemAction {
@XmlElement(name="Action", namespace=W3CAddressingConstants.WSA_NAMESPACE_NAME)
private String action;
@XmlElement(name="SoapAction", namespace=W3CAddressingConstants.WSA_NAMESPACE_NAME)
private String soapAction;
/** Creates a new instance of ProblemAction */
public ProblemAction() {
}
public ProblemAction(String action) {
this.action = action;
}
public ProblemAction(String action, String soapAction) {
this.action = action;
this.soapAction = soapAction;
}
public String getAction() {
return action;
}
public String getSoapAction() {
return soapAction;
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.addressing;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.namespace.QName;
import static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.WSA_NAMESPACE_NAME;
/**
* @author Arun Gupta
*/
@XmlRootElement(name="ProblemHeaderQName", namespace= WSA_NAMESPACE_NAME)
public class ProblemHeaderQName {
@XmlValue
private QName value;
/** Creates a new instance of ProblemHeaderQName */
public ProblemHeaderQName() {
}
public ProblemHeaderQName(QName name) {
this.value = name;
}
}

View File

@@ -0,0 +1,119 @@
/*
* 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.addressing;
import javax.xml.namespace.QName;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
/**
* Constants for W3C WS-Addressing version
*
* @author Arun Gupta
*/
public interface W3CAddressingConstants {
public static final String WSA_NAMESPACE_NAME = "http://www.w3.org/2005/08/addressing";
public static final String WSA_NAMESPACE_WSDL_NAME = "http://www.w3.org/2006/05/addressing/wsdl";
public static final String WSAW_SERVICENAME_NAME = "ServiceName";
public static final String WSAW_INTERFACENAME_NAME = "InterfaceName";
public static final String WSAW_ENDPOINTNAME_NAME = "EndpointName";
public static final String WSA_REFERENCEPROPERTIES_NAME = "ReferenceParameters";
public static final QName WSA_REFERENCEPROPERTIES_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_REFERENCEPROPERTIES_NAME);
public static final String WSA_REFERENCEPARAMETERS_NAME = "ReferenceParameters";
public static final QName WSA_REFERENCEPARAMETERS_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_REFERENCEPARAMETERS_NAME);
public static final String WSA_METADATA_NAME = "Metadata";
public static final QName WSA_METADATA_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_METADATA_NAME);
public static final String WSA_ADDRESS_NAME = "Address";
public static final QName WSA_ADDRESS_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_ADDRESS_NAME);
public static final String WSA_ANONYMOUS_ADDRESS = WSA_NAMESPACE_NAME + "/anonymous";
public static final String WSA_NONE_ADDRESS = WSA_NAMESPACE_NAME + "/none";
public static final String WSA_DEFAULT_FAULT_ACTION = WSA_NAMESPACE_NAME + "/fault";
public static final String WSA_EPR_NAME = "EndpointReference";
public static final QName WSA_EPR_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_EPR_NAME);
public static final String WSAW_USING_ADDRESSING_NAME = "UsingAddressing";
public static final QName WSAW_USING_ADDRESSING_QNAME = new QName(WSA_NAMESPACE_WSDL_NAME, WSAW_USING_ADDRESSING_NAME);
public static final QName INVALID_MAP_QNAME = new QName(WSA_NAMESPACE_NAME, "InvalidAddressingHeader");
public static final QName MAP_REQUIRED_QNAME = new QName(WSA_NAMESPACE_NAME, "MessageAddressingHeaderRequired");
public static final QName DESTINATION_UNREACHABLE_QNAME = new QName(WSA_NAMESPACE_NAME, "DestinationUnreachable");
public static final QName ACTION_NOT_SUPPORTED_QNAME = new QName(WSA_NAMESPACE_NAME, "ActionNotSupported");
public static final QName ENDPOINT_UNAVAILABLE_QNAME = new QName(WSA_NAMESPACE_NAME, "EndpointUnavailable");
public static final String ACTION_NOT_SUPPORTED_TEXT = "The \"%s\" cannot be processed at the receiver";
public static final String DESTINATION_UNREACHABLE_TEXT = "No route can be determined to reach %s";
public static final String ENDPOINT_UNAVAILABLE_TEXT = "The endpoint is unable to process the message at this time";
public static final String INVALID_MAP_TEXT = "A header representing a Message Addressing Property is not valid and the message cannot be processed";
public static final String MAP_REQUIRED_TEXT = "A required header representing a Message Addressing Property is not present";
public static final QName PROBLEM_ACTION_QNAME = new QName(WSA_NAMESPACE_NAME, "ProblemAction");
public static final QName PROBLEM_HEADER_QNAME_QNAME = new QName(WSA_NAMESPACE_NAME, "ProblemHeaderQName");
public static final QName FAULT_DETAIL_QNAME = new QName(WSA_NAMESPACE_NAME, "FaultDetail");
// Fault subsubcode when an invalid address is specified.
public static final QName INVALID_ADDRESS_SUBCODE = new QName(WSA_NAMESPACE_NAME, "InvalidAddress",
AddressingVersion.W3C.getPrefix());
// Fault subsubcode when an invalid header was expected to be EndpointReference but was not valid.
public static final QName INVALID_EPR = new QName(WSA_NAMESPACE_NAME, "InvalidEPR", AddressingVersion.W3C.getPrefix());
// Fault subsubcode when greater than expected number of the specified header is received.
public static final QName INVALID_CARDINALITY = new QName(WSA_NAMESPACE_NAME, "InvalidCardinality",
AddressingVersion.W3C.getPrefix());
// Fault subsubcode when an invalid header was expected to be EndpointReference but did not contain address.
public static final QName MISSING_ADDRESS_IN_EPR = new QName(WSA_NAMESPACE_NAME, "MissingAddressInEPR",
AddressingVersion.W3C.getPrefix());
// Fault subsubcode when a header contains a message id that was a duplicate of one already received.
public static final QName DUPLICATE_MESSAGEID = new QName(WSA_NAMESPACE_NAME, "DuplicateMessageID",
AddressingVersion.W3C.getPrefix());
// Fault subsubcode when <code>Action</code> and <code>SOAPAction</code> for the mesage did not match.
public static final QName ACTION_MISMATCH = new QName(WSA_NAMESPACE_NAME, "ActionMismatch",
AddressingVersion.W3C.getPrefix());
// Fault subsubcode when the only address supported is the anonymous address.
public static final QName ONLY_ANONYMOUS_ADDRESS_SUPPORTED = new QName(WSA_NAMESPACE_NAME, "OnlyAnonymousAddressSupported",
AddressingVersion.W3C.getPrefix());
//Fault subsubcode when anonymous address is not supported.
public static final QName ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED = new QName(WSA_NAMESPACE_NAME, "OnlyNonAnonymousAddressSupported",
AddressingVersion.W3C.getPrefix());
public static final String ANONYMOUS_EPR = "<EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\">\n" +
" <Address>http://www.w3.org/2005/08/addressing/anonymous</Address>\n" +
"</EndpointReference>";
}

View File

@@ -0,0 +1,56 @@
/*
* 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.addressing;
import javax.xml.namespace.QName;
/**
* Constants for W3C Addressing Metadata specification
* @author Rama Pulavarthi
*/
public class W3CAddressingMetadataConstants {
public static final String WSAM_NAMESPACE_NAME = "http://www.w3.org/2007/05/addressing/metadata";
public static final String WSAM_PREFIX_NAME = "wsam";
public static final QName WSAM_ACTION_QNAME = new QName(WSAM_NAMESPACE_NAME,"Action",WSAM_PREFIX_NAME);
public static final String WSAM_ADDRESSING_ASSERTION_NAME="Addressing";
public static final String WSAM_ANONYMOUS_NESTED_ASSERTION_NAME="AnonymousResponses";
public static final String WSAM_NONANONYMOUS_NESTED_ASSERTION_NAME="NonAnonymousResponses";
public static final QName WSAM_ADDRESSING_ASSERTION = new QName(WSAM_NAMESPACE_NAME,
WSAM_ADDRESSING_ASSERTION_NAME, WSAM_PREFIX_NAME );
public static final QName WSAM_ANONYMOUS_NESTED_ASSERTION = new QName(WSAM_NAMESPACE_NAME,
WSAM_ANONYMOUS_NESTED_ASSERTION_NAME, WSAM_PREFIX_NAME );
public static final QName WSAM_NONANONYMOUS_NESTED_ASSERTION = new QName(WSAM_NAMESPACE_NAME,
WSAM_NONANONYMOUS_NESTED_ASSERTION_NAME, WSAM_PREFIX_NAME );
public static final String WSAM_WSDLI_ATTRIBUTE_NAMESPACE="http://www.w3.org/ns/wsdl-instance";
public static final String WSAM_WSDLI_ATTRIBUTE_PREFIX="wsdli";
public static final String WSAM_WSDLI_ATTRIBUTE_LOCALNAME="wsdlLocation";
}

View File

@@ -0,0 +1,71 @@
/*
* 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.addressing;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
/**
* @author Rama Pulavarthi
*/
public class W3CWsaClientTube extends WsaClientTube {
public W3CWsaClientTube(WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(wsdlPort, binding, next);
}
public W3CWsaClientTube(WsaClientTube that, TubeCloner cloner) {
super(that, cloner);
}
@Override
public W3CWsaClientTube copy(TubeCloner cloner) {
return new W3CWsaClientTube(this, cloner);
}
@Override
protected void checkMandatoryHeaders(Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
boolean foundFaultTo, boolean foundMessageID, boolean foundRelatesTo) {
super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo, foundFaultTo, foundMessageID, foundRelatesTo);
// if it is not one-way, response must contain wsa:RelatesTo
// RelatesTo required as per
// Table 5-3 of http://www.w3.org/TR/2006/WD-ws-addr-wsdl-20060216/#wsdl11requestresponse
if (expectReply && (packet.getMessage() != null) && !foundRelatesTo) {
String action = AddressingUtils.getAction(packet.getMessage().getHeaders(), addressingVersion, soapVersion);
// Don't check for AddressingFaults as
// Faults for requests with duplicate MessageId will have no wsa:RelatesTo
if (!packet.getMessage().isFault() || !action.equals(addressingVersion.getDefaultFaultAction())) {
throw new MissingAddressingHeaderException(addressingVersion.relatesToTag,packet);
}
}
}
}

View 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.addressing;
import com.sun.xml.internal.ws.api.server.WSEndpoint;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
import static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED;
import static com.sun.xml.internal.ws.addressing.W3CAddressingConstants.ONLY_ANONYMOUS_ADDRESS_SUPPORTED;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import javax.xml.ws.soap.AddressingFeature;
/**
* @author Rama Pulavarthi
*/
public class W3CWsaServerTube extends WsaServerTube{
private final AddressingFeature af;
public W3CWsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(endpoint, wsdlPort, binding, next);
af = binding.getFeature(AddressingFeature.class);
}
public W3CWsaServerTube(W3CWsaServerTube that, TubeCloner cloner) {
super(that, cloner);
this.af = that.af;
}
@Override
public W3CWsaServerTube copy(TubeCloner cloner) {
return new W3CWsaServerTube(this, cloner);
}
@Override
protected void checkMandatoryHeaders(
Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo,
foundFaultTo, foundMessageId, foundRelatesTo);
// find Req/Response or Oneway using WSDLModel(if it is availabe)
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
// Taking care of protocol messages as they do not have any corresponding operations
if (wbo != null) {
// if two-way and no wsa:MessageID is found
if (!wbo.getOperation().isOneWay() && !foundMessageId) {
throw new MissingAddressingHeaderException(addressingVersion.messageIDTag,packet);
}
}
}
@Override
protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
return getResponseRequirement(wbo) == WSDLBoundOperation.ANONYMOUS.required;
}
private WSDLBoundOperation.ANONYMOUS getResponseRequirement(@Nullable WSDLBoundOperation wbo) {
try {
if (af.getResponses() == AddressingFeature.Responses.ANONYMOUS) {
return WSDLBoundOperation.ANONYMOUS.required;
} else if (af.getResponses() == AddressingFeature.Responses.NON_ANONYMOUS) {
return WSDLBoundOperation.ANONYMOUS.prohibited;
}
} catch (NoSuchMethodError e) {
//Ignore error, defaut to optional
}
//wsaw wsdl binding case will have some value set on wbo
return wbo != null ? wbo.getAnonymous() : WSDLBoundOperation.ANONYMOUS.optional;
}
@Override
protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
String replyToValue = null;
String faultToValue = null;
if (replyTo != null)
replyToValue = replyTo.getAddress();
if (faultTo != null)
faultToValue = faultTo.getAddress();
WSDLBoundOperation.ANONYMOUS responseRequirement = getResponseRequirement(wbo);
switch (responseRequirement) {
case prohibited:
if (replyToValue != null && replyToValue.equals(addressingVersion.anonymousUri))
throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
if (faultToValue != null && faultToValue.equals(addressingVersion.anonymousUri))
throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_NON_ANONYMOUS_ADDRESS_SUPPORTED);
break;
case required:
if (replyToValue != null && !replyToValue.equals(addressingVersion.anonymousUri))
throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
if (faultToValue != null && !faultToValue.equals(addressingVersion.anonymousUri))
throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, ONLY_ANONYMOUS_ADDRESS_SUPPORTED);
break;
default:
// ALL: no check
}
}
}

View File

@@ -0,0 +1,58 @@
/*
* Copyright (c) 2009, 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.addressing;
import com.sun.xml.internal.stream.buffer.XMLStreamBuffer;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamException;
/**
* Implementation backed by XMLStreamBuffer
*
* @author Rama.Pulavarthi@sun.com
*/
public class WSEPRExtension extends WSEndpointReference.EPRExtension {
XMLStreamBuffer xsb;
final QName qname;
public WSEPRExtension(XMLStreamBuffer xsb, QName qname) {
this.xsb = xsb;
this.qname = qname;
}
public XMLStreamReader readAsXMLStreamReader() throws XMLStreamException {
return xsb.readAsXMLStreamReader();
}
public QName getQName() {
return qname;
}
}

View File

@@ -0,0 +1,68 @@
/*
* 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.addressing;
import com.sun.xml.internal.ws.api.model.CheckedException;
import com.sun.xml.internal.ws.api.model.JavaMethod;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Logger;
/**
* @author Rama Pulavarthi
*/
public class WsaActionUtil {
@SuppressWarnings("FinalStaticMethod")
public static final String getDefaultFaultAction(JavaMethod method, CheckedException ce) {
String tns = method.getOwner().getTargetNamespace();
String delim = getDelimiter(tns);
if (tns.endsWith(delim)) {
tns = tns.substring(0, tns.length() - 1);
}
return new StringBuilder(tns).append(delim).append(
method.getOwner().getPortTypeName().getLocalPart()).append(
delim).append(method.getOperationName()).append(delim).append("Fault").append(delim).append(ce.getExceptionClass().getSimpleName()).toString();
}
private static String getDelimiter(String tns) {
String delim = "/";
// TODO: is this the correct way to find the separator ?
try {
URI uri = new URI(tns);
if ((uri.getScheme() != null) && uri.getScheme().equalsIgnoreCase("urn")) {
delim = ":";
}
} catch (URISyntaxException e) {
LOGGER.warning("TargetNamespace of WebService is not a valid URI");
}
return delim;
}
private static final Logger LOGGER =
Logger.getLogger(WsaActionUtil.class.getName());
}

View File

@@ -0,0 +1,107 @@
/*
* 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.addressing;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.ws.addressing.model.ActionNotSupportedException;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.pipe.NextAction;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.ws.WebServiceException;
/**
* WsaClientTube appears in the Tubeline only if addressing is enabled.
* This tube checks the validity of addressing headers in the incoming messages
* based on the WSDL model.
* @author Rama Pulavarthi
* @author Arun Gupta
*/
public class WsaClientTube extends WsaTube {
// capture if the request expects a reply so that it can be used to
// determine if its oneway for response validation.
protected boolean expectReply = true;
public WsaClientTube(WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(wsdlPort, binding, next);
}
public WsaClientTube(WsaClientTube that, TubeCloner cloner) {
super(that, cloner);
}
public WsaClientTube copy(TubeCloner cloner) {
return new WsaClientTube(this, cloner);
}
@Override
public @NotNull NextAction processRequest(Packet request) {
expectReply = request.expectReply;
return doInvoke(next,request);
}
@Override
public @NotNull NextAction processResponse(Packet response) {
// if one-way then, no validation
if (response.getMessage() != null) {
response = validateInboundHeaders(response);
response.addSatellite(new WsaPropertyBag(addressingVersion,soapVersion,response));
String msgId = AddressingUtils.
getMessageID(response.getMessage().getHeaders(),
addressingVersion, soapVersion);
response.put(WsaPropertyBag.WSA_MSGID_FROM_REQUEST, msgId);
}
return doReturnWith(response);
}
@Override
protected void validateAction(Packet packet) {
//There may not be a WSDL operation. There may not even be a WSDL.
//For instance this may be a RM CreateSequence message.
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
if (wbo == null) return;
String gotA = AddressingUtils.getAction(
packet.getMessage().getHeaders(),
addressingVersion, soapVersion);
if (gotA == null)
throw new WebServiceException(AddressingMessages.VALIDATION_CLIENT_NULL_ACTION());
String expected = helper.getOutputAction(packet);
if (expected != null && !gotA.equals(expected))
throw new ActionNotSupportedException(gotA);
}
}

View File

@@ -0,0 +1,195 @@
/*
* 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.addressing;
import com.oracle.webservices.internal.api.message.BasePropertySet;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.developer.JAXWSProperties;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
/**
* Provides access to the Addressing headers.
*
* @author Kohsuke Kawaguchi
* @author Rama Pulavarthi
* @since 2.1.3
*/
public class WsaPropertyBag extends BasePropertySet {
public static final String WSA_REPLYTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.ReplyToFromRequest";
public static final String WSA_FAULTTO_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.FaultToFromRequest";
public static final String WSA_MSGID_FROM_REQUEST = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.MessageIdFromRequest";
public static final String WSA_TO = "com.sun.xml.internal.ws.addressing.WsaPropertyBag.To";
private final @NotNull AddressingVersion addressingVersion;
private final @NotNull SOAPVersion soapVersion;
/**
* We can't store {@link Message} here as those may get replaced as
* the packet travels through the pipeline.
*/
private final @NotNull Packet packet;
public WsaPropertyBag(AddressingVersion addressingVersion, SOAPVersion soapVersion, Packet packet) {
this.addressingVersion = addressingVersion;
this.soapVersion = soapVersion;
this.packet = packet;
}
/**
* Gets the <tt>wsa:To</tt> header.
*
* @return
* null if the incoming SOAP message didn't have the header.
*/
@Property(JAXWSProperties.ADDRESSING_TO)
public String getTo() throws XMLStreamException {
if (packet.getMessage() == null) {
return null;
}
Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
if(h==null) return null;
return h.getStringContent();
}
/**
* Gets the <tt>wsa:To</tt> header.
*
* @return
* null if the incoming SOAP message didn't have the header.
*/
@Property(WSA_TO)
public WSEndpointReference getToAsReference() throws XMLStreamException {
if (packet.getMessage() == null) {
return null;
}
Header h = packet.getMessage().getHeaders().get(addressingVersion.toTag, false);
if(h==null) return null;
return new WSEndpointReference(h.getStringContent(),addressingVersion);
}
/**
* Gets the <tt>wsa:From</tt> header.
*
* @return
* null if the incoming SOAP message didn't have the header.
*/
@Property(JAXWSProperties.ADDRESSING_FROM)
public WSEndpointReference getFrom() throws XMLStreamException {
return getEPR(addressingVersion.fromTag);
}
/**
* Gets the <tt>wsa:Action</tt> header content as String.
*
* @return
* null if the incoming SOAP message didn't have the header.
*/
@Property(JAXWSProperties.ADDRESSING_ACTION)
public String getAction() {
if (packet.getMessage() == null) {
return null;
}
Header h = packet.getMessage().getHeaders().get(addressingVersion.actionTag, false);
if(h==null) return null;
return h.getStringContent();
}
/**
* Gets the <tt>wsa:MessageID</tt> header content as String.
*
* @return
* null if the incoming SOAP message didn't have the header.
*/
// WsaServerTube.REQUEST_MESSAGE_ID is exposed for backward compatibility with 2.1
@Property({JAXWSProperties.ADDRESSING_MESSAGEID,WsaServerTube.REQUEST_MESSAGE_ID})
public String getMessageID() {
if (packet.getMessage() == null) {
return null;
}
return AddressingUtils.getMessageID(packet.getMessage().getHeaders(), addressingVersion,soapVersion);
}
private WSEndpointReference getEPR(QName tag) throws XMLStreamException {
if (packet.getMessage() == null) {
return null;
}
Header h = packet.getMessage().getHeaders().get(tag, false);
if(h==null) return null;
return h.readAsEPR(addressingVersion);
}
protected PropertyMap getPropertyMap() {
return model;
}
private static final PropertyMap model;
static {
model = parse(WsaPropertyBag.class);
}
private WSEndpointReference _replyToFromRequest = null;
@Property(WSA_REPLYTO_FROM_REQUEST)
public WSEndpointReference getReplyToFromRequest() {
return _replyToFromRequest;
}
public void setReplyToFromRequest(WSEndpointReference ref) {
_replyToFromRequest = ref;
}
private WSEndpointReference _faultToFromRequest = null;
@Property(WSA_FAULTTO_FROM_REQUEST)
public WSEndpointReference getFaultToFromRequest() {
return _faultToFromRequest;
}
public void setFaultToFromRequest(WSEndpointReference ref) {
_faultToFromRequest = ref;
}
private String _msgIdFromRequest = null;
@Property(WSA_MSGID_FROM_REQUEST)
public String getMessageIdFromRequest() {
return _msgIdFromRequest;
}
public void setMessageIdFromRequest(String id) {
_msgIdFromRequest = id;
}
}

View File

@@ -0,0 +1,371 @@
/*
* 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.addressing;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.addressing.model.ActionNotSupportedException;
import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
import com.sun.xml.internal.ws.api.EndpointAddress;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.api.addressing.NonAnonymousResponseProcessor;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.MessageHeaders;
import com.sun.xml.internal.ws.api.message.Messages;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.pipe.*;
import com.sun.xml.internal.ws.api.server.WSEndpoint;
import com.sun.xml.internal.ws.client.Stub;
import com.sun.xml.internal.ws.developer.JAXWSProperties;
import com.sun.xml.internal.ws.fault.SOAPFaultBuilder;
import com.sun.xml.internal.ws.message.FaultDetailHeader;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.soap.SOAPFault;
import javax.xml.ws.WebServiceException;
import java.net.URI;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Handles WS-Addressing for the server.
*
* @author Rama Pulavarthi
* @author Kohsuke Kawaguchi
* @author Arun Gupta
*/
public class WsaServerTube extends WsaTube {
private WSEndpoint endpoint;
// store the replyTo/faultTo of the message currently being processed.
// both will be set to non-null in processRequest
private WSEndpointReference replyTo;
private WSEndpointReference faultTo;
private boolean isAnonymousRequired = false;
// Used by subclasses to avoid this class closing the transport back
// channel based on the ReplyTo/FaultTo addrs being non-anonymous. False
// can be useful in cases where special back-channel handling is required.
protected boolean isEarlyBackchannelCloseAllowed = true;
/**
* WSDLBoundOperation calculated on the Request payload.
* Used for determining ReplyTo or Fault Action for non-anonymous responses *
*/
private WSDLBoundOperation wbo;
public WsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(wsdlPort, binding, next);
this.endpoint = endpoint;
}
public WsaServerTube(WsaServerTube that, TubeCloner cloner) {
super(that, cloner);
endpoint = that.endpoint;
}
@Override
public WsaServerTube copy(TubeCloner cloner) {
return new WsaServerTube(this, cloner);
}
@Override
public @NotNull NextAction processRequest(Packet request) {
Message msg = request.getMessage();
if (msg == null) {
return doInvoke(next,request);
} // hmm?
// expose bunch of addressing related properties for advanced applications
request.addSatellite(new WsaPropertyBag(addressingVersion,soapVersion,request));
// Store request ReplyTo and FaultTo in requestPacket.invocationProperties
// so that they can be used after responsePacket is received.
// These properties are used if a fault is thrown from the subsequent Pipe/Tubes.
MessageHeaders hl = request.getMessage().getHeaders();
String msgId;
try {
replyTo = AddressingUtils.getReplyTo(hl, addressingVersion, soapVersion);
faultTo = AddressingUtils.getFaultTo(hl, addressingVersion, soapVersion);
msgId = AddressingUtils.getMessageID(hl, addressingVersion, soapVersion);
} catch (InvalidAddressingHeaderException e) {
LOGGER.log(Level.WARNING, addressingVersion.getInvalidMapText()+", Problem header:" + e.getProblemHeader()+ ", Reason: "+ e.getSubsubcode(),e);
// problematic header must be removed since it can fail during Fault message processing
hl.remove(e.getProblemHeader());
SOAPFault soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
// WS-A fault processing for one-way methods
if ((wsdlPort!=null) && request.getMessage().isOneWay(wsdlPort)) {
Packet response = request.createServerResponse(null, wsdlPort, null, binding);
return doReturnWith(response);
}
Message m = Messages.create(soapFault);
if (soapVersion == SOAPVersion.SOAP_11) {
FaultDetailHeader s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
m.getHeaders().add(s11FaultDetailHeader);
}
Packet response = request.createServerResponse(m, wsdlPort, null, binding);
return doReturnWith(response);
}
// defaulting
if (replyTo == null) {
replyTo = addressingVersion.anonymousEpr;
}
if (faultTo == null) {
faultTo = replyTo;
}
// Save a copy into the packet such that we can save it with that
// packet if we're going to deliver the response at a later time
// (async from the request).
request.put(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST, replyTo);
request.put(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST, faultTo);
request.put(WsaPropertyBag.WSA_MSGID_FROM_REQUEST, msgId);
wbo = getWSDLBoundOperation(request);
isAnonymousRequired = isAnonymousRequired(wbo);
Packet p = validateInboundHeaders(request);
// if one-way message and WS-A header processing fault has occurred,
// then do no further processing
if (p.getMessage() == null) {
return doReturnWith(p);
}
// if we find an error in addressing header, just turn around the direction here
if (p.getMessage().isFault()) {
// close the transportBackChannel if we know that
// we'll never use them
if (isEarlyBackchannelCloseAllowed &&
!(isAnonymousRequired) &&
!faultTo.isAnonymous() && request.transportBackChannel != null) {
request.transportBackChannel.close();
}
return processResponse(p);
}
// close the transportBackChannel if we know that
// we'll never use them
if (isEarlyBackchannelCloseAllowed &&
!(isAnonymousRequired) &&
!replyTo.isAnonymous() && !faultTo.isAnonymous() &&
request.transportBackChannel != null) {
request.transportBackChannel.close();
}
return doInvoke(next,p);
}
protected boolean isAnonymousRequired(@Nullable WSDLBoundOperation wbo) {
//this requirement can only be specified in W3C case, Override this in W3C case.
return false;
}
protected void checkAnonymousSemantics(WSDLBoundOperation wbo, WSEndpointReference replyTo, WSEndpointReference faultTo) {
//this requirement can only be specified in W3C case, Override this in W3C case.
}
@Override
public @NotNull NextAction processException(Throwable t) {
final Packet response = Fiber.current().getPacket();
ThrowableContainerPropertySet tc = response.getSatellite(ThrowableContainerPropertySet.class);
if (tc == null) {
tc = new ThrowableContainerPropertySet(t);
response.addSatellite(tc);
} else if (t != tc.getThrowable()) {
// This is a pathological case where an exception happens after a previous exception.
// Make sure you report the latest one.
tc.setThrowable(t);
}
return processResponse(response.endpoint.createServiceResponseForException(tc, response, soapVersion, wsdlPort,
response.endpoint.getSEIModel(),
binding));
}
@Override
public @NotNull NextAction processResponse(Packet response) {
Message msg = response.getMessage();
if (msg ==null) {
return doReturnWith(response);
} // one way message. Nothing to see here. Move on.
String to = AddressingUtils.getTo(msg.getHeaders(),
addressingVersion, soapVersion);
if (to != null) {
replyTo = faultTo = new WSEndpointReference(to, addressingVersion);
}
if (replyTo == null) {
// This is an async response or we're not processing the response in
// the same tube instance as we processed the request. Get the ReplyTo
// now, from the properties we stored into the request packet. We
// assume anyone that interrupted the request->response flow will have
// saved the ReplyTo and put it back into the packet for our use.
replyTo = (WSEndpointReference)response.
get(WsaPropertyBag.WSA_REPLYTO_FROM_REQUEST);
}
if (faultTo == null) {
// This is an async response or we're not processing the response in
// the same tube instance as we processed the request. Get the FaultTo
// now, from the properties we stored into the request packet. We
// assume anyone that interrupted the request->response flow will have
// saved the FaultTo and put it back into the packet for our use.
faultTo = (WSEndpointReference)response.
get(WsaPropertyBag.WSA_FAULTTO_FROM_REQUEST);
}
WSEndpointReference target = msg.isFault() ? faultTo : replyTo;
if (target == null && response.proxy instanceof Stub) {
target = ((Stub) response.proxy).getWSEndpointReference();
}
if (target == null || target.isAnonymous() || isAnonymousRequired) {
return doReturnWith(response);
}
if (target.isNone()) {
// the caller doesn't want to hear about it, so proceed like one-way
response.setMessage(null);
return doReturnWith(response);
}
if ((wsdlPort!=null) && response.getMessage().isOneWay(wsdlPort)) {
// one way message but with replyTo. I believe this is a hack for WS-TX - KK.
LOGGER.fine(AddressingMessages.NON_ANONYMOUS_RESPONSE_ONEWAY());
return doReturnWith(response);
}
// MTU: If we're not sending a response that corresponds to a WSDL op,
// then take whatever soapAction is set on the packet (as allowing
// helper.getOutputAction() will only result in a bogus 'unset'
// action value.
if (wbo != null || response.soapAction == null) {
String action = response.getMessage().isFault() ?
helper.getFaultAction(wbo, response) :
helper.getOutputAction(wbo);
//set the SOAPAction, as its got to be same as wsa:Action
if (response.soapAction == null ||
(action != null &&
!action.equals(AddressingVersion.UNSET_OUTPUT_ACTION))) {
response.soapAction = action;
}
}
response.expectReply = false;
EndpointAddress adrs;
try {
adrs = new EndpointAddress(URI.create(target.getAddress()));
} catch (NullPointerException e) {
throw new WebServiceException(e);
} catch (IllegalArgumentException e) {
throw new WebServiceException(e);
}
response.endpointAddress = adrs;
if (response.isAdapterDeliversNonAnonymousResponse) {
return doReturnWith(response);
}
return doReturnWith(NonAnonymousResponseProcessor.getDefault().process(response));
}
@Override
protected void validateAction(Packet packet) {
//There may not be a WSDL operation. There may not even be a WSDL.
//For instance this may be a RM CreateSequence message.
WSDLBoundOperation wsdlBoundOperation = getWSDLBoundOperation(packet);
if (wsdlBoundOperation == null) {
return;
}
String gotA = AddressingUtils.getAction(
packet.getMessage().getHeaders(),
addressingVersion, soapVersion);
if (gotA == null) {
throw new WebServiceException(AddressingMessages.VALIDATION_SERVER_NULL_ACTION());
}
String expected = helper.getInputAction(packet);
String soapAction = helper.getSOAPAction(packet);
if (helper.isInputActionDefault(packet) && (soapAction != null && !soapAction.equals(""))) {
expected = soapAction;
}
if (expected != null && !gotA.equals(expected)) {
throw new ActionNotSupportedException(gotA);
}
}
@Override
protected void checkMessageAddressingProperties(Packet packet) {
super.checkMessageAddressingProperties(packet);
// wsaw:Anonymous validation
WSDLBoundOperation wsdlBoundOperation = getWSDLBoundOperation(packet);
checkAnonymousSemantics(wsdlBoundOperation, replyTo, faultTo);
// check if addresses are valid
checkNonAnonymousAddresses(replyTo,faultTo);
}
@SuppressWarnings("ResultOfObjectAllocationIgnored")
private void checkNonAnonymousAddresses(WSEndpointReference replyTo, WSEndpointReference faultTo) {
if (!replyTo.isAnonymous()) {
try {
new EndpointAddress(URI.create(replyTo.getAddress()));
} catch (Exception e) {
throw new InvalidAddressingHeaderException(addressingVersion.replyToTag, addressingVersion.invalidAddressTag);
}
}
//for now only validate ReplyTo
/*
if (!faultTo.isAnonymous()) {
try {
new EndpointAddress(URI.create(faultTo.getAddress()));
} catch (IllegalArgumentException e) {
throw new InvalidAddressingHeaderException(addressingVersion.faultToTag, addressingVersion.invalidAddressTag);
}
}
*/
}
/**
* @deprecated
* Use {@link JAXWSProperties#ADDRESSING_MESSAGEID}.
*/
public static final String REQUEST_MESSAGE_ID = "com.sun.xml.internal.ws.addressing.request.messageID";
private static final Logger LOGGER = Logger.getLogger(WsaServerTube.class.getName());
}

View File

@@ -0,0 +1,405 @@
/*
* 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.addressing;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Header;
import com.sun.xml.internal.ws.api.message.Message;
import com.sun.xml.internal.ws.api.message.Messages;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.pipe.NextAction;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.pipe.helper.AbstractFilterTubeImpl;
import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
import com.sun.xml.internal.ws.message.FaultDetailHeader;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.namespace.QName;
import javax.xml.soap.SOAPFault;
import javax.xml.stream.XMLStreamException;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.AddressingFeature;
import javax.xml.ws.soap.SOAPBinding;
import java.util.Iterator;
import java.util.logging.Logger;
import java.util.logging.Level;
/**
* WS-Addressing processing code shared between client and server.
*
* <p>
* This tube is used only when WS-Addressing is enabled.
*
* @author Rama Pulavarthi
* @author Arun Gupta
*/
abstract class WsaTube extends AbstractFilterTubeImpl {
/**
* Port that we are processing.
*/
protected final @NotNull WSDLPort wsdlPort;
protected final WSBinding binding;
final WsaTubeHelper helper;
protected final @NotNull AddressingVersion addressingVersion;
protected final SOAPVersion soapVersion;
/**
* True if the addressing headers are mandatory.
*/
private final boolean addressingRequired;
public WsaTube(WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(next);
this.wsdlPort = wsdlPort;
this.binding = binding;
addKnownHeadersToBinding(binding);
addressingVersion = binding.getAddressingVersion();
soapVersion = binding.getSOAPVersion();
helper = getTubeHelper();
addressingRequired = AddressingVersion.isRequired(binding);
}
public WsaTube(WsaTube that, TubeCloner cloner) {
super(that, cloner);
this.wsdlPort = that.wsdlPort;
this.binding = that.binding;
this.helper = that.helper;
addressingVersion = that.addressingVersion;
soapVersion = that.soapVersion;
addressingRequired = that.addressingRequired;
}
private void addKnownHeadersToBinding(WSBinding binding) {
for (AddressingVersion addrVersion: AddressingVersion.values()) {
binding.addKnownHeader(addrVersion.actionTag);
binding.addKnownHeader(addrVersion.faultDetailTag);
binding.addKnownHeader(addrVersion.faultToTag);
binding.addKnownHeader(addrVersion.fromTag);
binding.addKnownHeader(addrVersion.messageIDTag);
binding.addKnownHeader(addrVersion.relatesToTag);
binding.addKnownHeader(addrVersion.replyToTag);
binding.addKnownHeader(addrVersion.toTag);
}
}
@Override
public @NotNull NextAction processException(Throwable t) {
return super.processException(t);
}
protected WsaTubeHelper getTubeHelper() {
if(binding.isFeatureEnabled(AddressingFeature.class)) {
return new WsaTubeHelperImpl(wsdlPort, null, binding);
} else if(binding.isFeatureEnabled(MemberSubmissionAddressingFeature.class)) {
//seiModel is null as it is not needed.
return new com.sun.xml.internal.ws.addressing.v200408.WsaTubeHelperImpl(wsdlPort, null, binding);
} else {
// Addressing is not enabled, WsaTube should not be included in the pipeline
throw new WebServiceException(AddressingMessages.ADDRESSING_NOT_ENABLED(this.getClass().getSimpleName()));
}
}
/**
* Validates the inbound message. If an error is found, create
* a fault message and returns that. Otherwise
* it will pass through the parameter 'packet' object to the return value.
*/
protected Packet validateInboundHeaders(Packet packet) {
SOAPFault soapFault;
FaultDetailHeader s11FaultDetailHeader;
try {
checkMessageAddressingProperties(packet);
return packet;
} catch (InvalidAddressingHeaderException e) {
LOGGER.log(Level.WARNING,
addressingVersion.getInvalidMapText()+", Problem header:" + e.getProblemHeader()+ ", Reason: "+ e.getSubsubcode(),e);
soapFault = helper.createInvalidAddressingHeaderFault(e, addressingVersion);
s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getProblemHeader());
} catch (MissingAddressingHeaderException e) {
LOGGER.log(Level.WARNING,addressingVersion.getMapRequiredText()+", Problem header:"+ e.getMissingHeaderQName(),e);
soapFault = helper.newMapRequiredFault(e);
s11FaultDetailHeader = new FaultDetailHeader(addressingVersion, addressingVersion.problemHeaderQNameTag.getLocalPart(), e.getMissingHeaderQName());
}
if (soapFault != null) {
// WS-A fault processing for one-way methods
if ((wsdlPort !=null) && packet.getMessage().isOneWay(wsdlPort)) {
return packet.createServerResponse(null, wsdlPort, null, binding);
}
Message m = Messages.create(soapFault);
if (soapVersion == SOAPVersion.SOAP_11) {
m.getHeaders().add(s11FaultDetailHeader);
}
return packet.createServerResponse(m, wsdlPort, null, binding);
}
return packet;
}
/**
* This method checks all the WS-Addressing headers are valid and as per the spec definded rules.
* Mainly it checks the cardinality of the WSA headers and checks that mandatory headers exist.
* It also checks if the SOAPAction is equal to wsa:Action value when non-empty.
*
* Override this method if you need to additional checking of headers other than just existence of the headers.
* For ex: On server-side, check Anonymous and Non-Anonymous semantics in addition to checking cardinality.
*
* Override checkMandatoryHeaders(Packet p) to have different validation rules for different versions
*
* @param packet
*/
protected void checkMessageAddressingProperties(Packet packet) {
checkCardinality(packet);
}
final boolean isAddressingEngagedOrRequired(Packet packet, WSBinding binding) {
if (AddressingVersion.isRequired(binding))
return true;
if (packet == null)
return false;
if (packet.getMessage() == null)
return false;
if (packet.getMessage().getHeaders() != null)
return false;
String action = AddressingUtils.getAction(
packet.getMessage().getHeaders(),
addressingVersion, soapVersion);
if (action == null)
return true;
return true;
}
/**
* Checks the cardinality of WS-Addressing headers on an inbound {@link Packet}. This method
* checks for the cardinality if WS-Addressing is engaged (detected by the presence of wsa:Action
* header) or wsdl:required=true.
*
* @param packet The inbound packet.
* @throws WebServiceException if:
* <ul>
* <li>there is an error reading ReplyTo or FaultTo</li>
* <li>WS-Addressing is required and {@link Message} within <code>packet</code> is null</li>
* <li>WS-Addressing is required and no headers are found in the {@link Message}</li>
* <li>an uknown WS-Addressing header is present</li>
* </ul>
*/
protected void checkCardinality(Packet packet) {
Message message = packet.getMessage();
if (message == null) {
if (addressingRequired)
throw new WebServiceException(AddressingMessages.NULL_MESSAGE());
else
return;
}
Iterator<Header> hIter = message.getHeaders().getHeaders(addressingVersion.nsUri, true);
if (!hIter.hasNext()) {
// no WS-A headers are found
if (addressingRequired)
// if WS-A is required, then throw an exception looking for wsa:Action header
throw new MissingAddressingHeaderException(addressingVersion.actionTag,packet);
else
// else no need to process
return;
}
boolean foundFrom = false;
boolean foundTo = false;
boolean foundReplyTo = false;
boolean foundFaultTo = false;
boolean foundAction = false;
boolean foundMessageId = false;
boolean foundRelatesTo = false;
QName duplicateHeader = null;
while (hIter.hasNext()) {
Header h = hIter.next();
// check if the Header is in current role
if (!isInCurrentRole(h, binding)) {
continue;
}
String local = h.getLocalPart();
if (local.equals(addressingVersion.fromTag.getLocalPart())) {
if (foundFrom) {
duplicateHeader = addressingVersion.fromTag;
break;
}
foundFrom = true;
} else if (local.equals(addressingVersion.toTag.getLocalPart())) {
if (foundTo) {
duplicateHeader = addressingVersion.toTag;
break;
}
foundTo = true;
} else if (local.equals(addressingVersion.replyToTag.getLocalPart())) {
if (foundReplyTo) {
duplicateHeader = addressingVersion.replyToTag;
break;
}
foundReplyTo = true;
try { // verify that the header is in a good shape
h.readAsEPR(addressingVersion);
} catch (XMLStreamException e) {
throw new WebServiceException(AddressingMessages.REPLY_TO_CANNOT_PARSE(), e);
}
} else if (local.equals(addressingVersion.faultToTag.getLocalPart())) {
if (foundFaultTo) {
duplicateHeader = addressingVersion.faultToTag;
break;
}
foundFaultTo = true;
try { // verify that the header is in a good shape
h.readAsEPR(addressingVersion);
} catch (XMLStreamException e) {
throw new WebServiceException(AddressingMessages.FAULT_TO_CANNOT_PARSE(), e);
}
} else if (local.equals(addressingVersion.actionTag.getLocalPart())) {
if (foundAction) {
duplicateHeader = addressingVersion.actionTag;
break;
}
foundAction = true;
} else if (local.equals(addressingVersion.messageIDTag.getLocalPart())) {
if (foundMessageId) {
duplicateHeader = addressingVersion.messageIDTag;
break;
}
foundMessageId = true;
} else if (local.equals(addressingVersion.relatesToTag.getLocalPart())) {
foundRelatesTo = true;
} else if (local.equals(addressingVersion.faultDetailTag.getLocalPart())) {
// TODO: should anything be done here ?
// TODO: fault detail element - only for SOAP 1.1
} else {
System.err.println(AddressingMessages.UNKNOWN_WSA_HEADER());
}
}
// check for invalid cardinality first before checking for mandatory headers
if (duplicateHeader != null) {
throw new InvalidAddressingHeaderException(duplicateHeader, addressingVersion.invalidCardinalityTag);
}
// WS-A is engaged if wsa:Action header is found
boolean engaged = foundAction;
// check for mandatory set of headers only if:
// 1. WS-A is engaged or
// 2. wsdl:required=true
// Both wsa:Action and wsa:To MUST be present on request (for oneway MEP) and
// response messages (for oneway and request/response MEP only)
if (engaged || addressingRequired) {
// Check for mandatory headers always (even for Protocol messages).
// If it breaks any interop scenarios, Remove the comments.
/*
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
// no need to check for for non-application messages
if (wbo == null)
return;
*/
checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo,
foundFaultTo, foundMessageId, foundRelatesTo);
}
}
final boolean isInCurrentRole(Header header, WSBinding binding) {
// TODO: binding will be null for protocol messages
// TODO: returning true assumes that protocol messages are
// TODO: always in current role, this may not to be fixed.
if (binding == null)
return true;
return ((SOAPBinding)binding).getRoles().contains(header.getRole(soapVersion));
}
protected final WSDLBoundOperation getWSDLBoundOperation(Packet packet) {
//we can find Req/Response or Oneway only with WSDLModel
if(wsdlPort == null)
return null;
QName opName = packet.getWSDLOperation();
if(opName != null)
return wsdlPort.getBinding().get(opName);
return null;
}
protected void validateSOAPAction(Packet packet) {
String gotA = AddressingUtils.getAction(
packet.getMessage().getHeaders(),
addressingVersion, soapVersion);
if (gotA == null)
throw new WebServiceException(AddressingMessages.VALIDATION_SERVER_NULL_ACTION());
if(packet.soapAction != null && !packet.soapAction.equals("\"\"") && !packet.soapAction.equals("\""+gotA+"\"")) {
throw new InvalidAddressingHeaderException(addressingVersion.actionTag, addressingVersion.actionMismatchTag);
}
}
protected abstract void validateAction(Packet packet);
/**
* This should be called only when Addressing is engaged.
*
* Checks only for presence of wsa:Action and validates that wsa:Action
* equals SOAPAction header when non-empty
* Should be overridden if other wsa headers need to be checked based on version.
*
* @param packet
* @param foundAction
* @param foundTo
* @param foundReplyTo
* @param foundFaultTo
* @param foundMessageId
* @param foundRelatesTo
*/
protected void checkMandatoryHeaders(
Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
// if no wsa:Action header is found
if (!foundAction)
throw new MissingAddressingHeaderException(addressingVersion.actionTag,packet);
validateSOAPAction(packet);
}
private static final Logger LOGGER = Logger.getLogger(WsaTube.class.getName());
}

View File

@@ -0,0 +1,360 @@
/*
* 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.addressing;
import com.sun.xml.internal.ws.addressing.model.InvalidAddressingHeaderException;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLFault;
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.SEIModel;
import com.sun.xml.internal.ws.api.model.JavaMethod;
import com.sun.xml.internal.ws.api.model.WSDLOperationMapping;
import com.sun.xml.internal.ws.model.JavaMethodImpl;
import com.sun.xml.internal.ws.model.CheckedExceptionImpl;
import com.sun.istack.internal.Nullable;
import org.w3c.dom.Element;
import javax.xml.namespace.QName;
import javax.xml.soap.Detail;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPFactory;
import javax.xml.soap.SOAPFault;
import javax.xml.soap.SOAPMessage;
import javax.xml.ws.WebServiceException;
/**
* @author Rama Pulavarthi
* @author Arun Gupta
*/
public abstract class WsaTubeHelper {
public WsaTubeHelper(WSBinding binding, SEIModel seiModel, WSDLPort wsdlPort) {
this.binding = binding;
this.wsdlPort = wsdlPort;
this.seiModel = seiModel;
this.soapVer = binding.getSOAPVersion();
this.addVer = binding.getAddressingVersion();
}
public String getFaultAction(Packet requestPacket, Packet responsePacket) {
String action = null;
if(seiModel != null) {
action = getFaultActionFromSEIModel(requestPacket,responsePacket);
}
if (action != null) {
return action;
} else {
action = addVer.getDefaultFaultAction();
}
if (wsdlPort != null) {
WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
if (wsdlOp != null) {
WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
return getFaultAction(wbo, responsePacket);
}
}
return action;
}
String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
String action = null;
if (seiModel == null || wsdlPort == null) {
return action;
}
try {
SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
if (sm == null) {
return action;
}
if (sm.getSOAPBody() == null) {
return action;
}
if (sm.getSOAPBody().getFault() == null) {
return action;
}
Detail detail = sm.getSOAPBody().getFault().getDetail();
if (detail == null) {
return action;
}
String ns = detail.getFirstChild().getNamespaceURI();
String name = detail.getFirstChild().getLocalName();
WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl)wsdlOp.getJavaMethod() : null;
if (jm != null) {
for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
if (ce.getDetailType().tagName.getLocalPart().equals(name) &&
ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
return ce.getFaultAction();
}
}
}
return action;
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
String getFaultAction(@Nullable WSDLBoundOperation wbo, Packet responsePacket) {
String action = AddressingUtils.getAction(responsePacket.getMessage().getHeaders(), addVer, soapVer);
if (action != null) {
return action;
}
action = addVer.getDefaultFaultAction();
if (wbo == null) {
return action;
}
try {
SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
if (sm == null) {
return action;
}
if (sm.getSOAPBody() == null) {
return action;
}
if (sm.getSOAPBody().getFault() == null) {
return action;
}
Detail detail = sm.getSOAPBody().getFault().getDetail();
if (detail == null) {
return action;
}
String ns = detail.getFirstChild().getNamespaceURI();
String name = detail.getFirstChild().getLocalName();
WSDLOperation o = wbo.getOperation();
WSDLFault fault = o.getFault(new QName(ns, name));
if (fault == null) {
return action;
}
action = fault.getAction();
return action;
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
public String getInputAction(Packet packet) {
String action = null;
if (wsdlPort != null) {
WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
if (wsdlOp != null) {
WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
WSDLOperation op = wbo.getOperation();
action = op.getInput().getAction();
}
}
return action;
}
/**
* This method gives the Input addressing Action for a message.
* It gives the Action set in the wsdl operation for the corresponding payload.
* If it is not explicitly set, it gives the soapAction
* @param packet
* @return input Action
*/
public String getEffectiveInputAction(Packet packet) {
//non-default SOAPAction beomes wsa:action
if(packet.soapAction != null && !packet.soapAction.equals("")) {
return packet.soapAction;
}
String action;
if (wsdlPort != null) {
WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
if (wsdlOp != null) {
WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
WSDLOperation op = wbo.getOperation();
action = op.getInput().getAction();
} else {
action = packet.soapAction;
}
} else {
action = packet.soapAction;
}
return action;
}
public boolean isInputActionDefault(Packet packet) {
if (wsdlPort == null) {
return false;
}
WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
if(wsdlOp == null) {
return false;
}
WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
WSDLOperation op = wbo.getOperation();
return op.getInput().isDefaultAction();
}
public String getSOAPAction(Packet packet) {
String action = "";
if (packet == null || packet.getMessage() == null) {
return action;
}
if (wsdlPort == null) {
return action;
}
WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
if (wsdlOp == null) {
return action;
}
WSDLBoundOperation op = wsdlOp.getWSDLBoundOperation();
action = op.getSOAPAction();
return action;
}
public String getOutputAction(Packet packet) {
//String action = AddressingVersion.UNSET_OUTPUT_ACTION;
String action = null;
WSDLOperationMapping wsdlOp = packet.getWSDLOperationMapping();
if (wsdlOp != null) {
JavaMethod javaMethod = wsdlOp.getJavaMethod();
if (javaMethod != null) {
JavaMethodImpl jm = (JavaMethodImpl) javaMethod;
if (jm != null && jm.getOutputAction() != null && !jm.getOutputAction().equals("")) {
return jm.getOutputAction();
}
}
WSDLBoundOperation wbo = wsdlOp.getWSDLBoundOperation();
if (wbo != null) return getOutputAction(wbo);
}
return action;
}
String getOutputAction(@Nullable WSDLBoundOperation wbo) {
String action = AddressingVersion.UNSET_OUTPUT_ACTION;
if (wbo != null) {
WSDLOutput op = wbo.getOperation().getOutput();
if (op != null) {
action = op.getAction();
}
}
return action;
}
public SOAPFault createInvalidAddressingHeaderFault(InvalidAddressingHeaderException e, AddressingVersion av) {
QName name = e.getProblemHeader();
QName subsubcode = e.getSubsubcode();
QName subcode = av.invalidMapTag;
String faultstring = String.format(av.getInvalidMapText(), name, subsubcode);
try {
SOAPFactory factory;
SOAPFault fault;
if (soapVer == SOAPVersion.SOAP_12) {
factory = SOAPVersion.SOAP_12.getSOAPFactory();
fault = factory.createFault();
fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
fault.appendFaultSubcode(subcode);
fault.appendFaultSubcode(subsubcode);
getInvalidMapDetail(name, fault.addDetail());
} else {
factory = SOAPVersion.SOAP_11.getSOAPFactory();
fault = factory.createFault();
fault.setFaultCode(subsubcode);
}
fault.setFaultString(faultstring);
return fault;
} catch (SOAPException se) {
throw new WebServiceException(se);
}
}
public SOAPFault newMapRequiredFault(MissingAddressingHeaderException e) {
QName subcode = addVer.mapRequiredTag;
QName subsubcode = addVer.mapRequiredTag;
String faultstring = addVer.getMapRequiredText();
try {
SOAPFactory factory;
SOAPFault fault;
if (soapVer == SOAPVersion.SOAP_12) {
factory = SOAPVersion.SOAP_12.getSOAPFactory();
fault = factory.createFault();
fault.setFaultCode(SOAPConstants.SOAP_SENDER_FAULT);
fault.appendFaultSubcode(subcode);
fault.appendFaultSubcode(subsubcode);
getMapRequiredDetail(e.getMissingHeaderQName(), fault.addDetail());
} else {
factory = SOAPVersion.SOAP_11.getSOAPFactory();
fault = factory.createFault();
fault.setFaultCode(subsubcode);
}
fault.setFaultString(faultstring);
return fault;
} catch (SOAPException se) {
throw new WebServiceException(se);
}
}
public abstract void getProblemActionDetail(String action, Element element);
public abstract void getInvalidMapDetail(QName name, Element element);
public abstract void getMapRequiredDetail(QName name, Element element);
protected SEIModel seiModel;
protected WSDLPort wsdlPort;
protected WSBinding binding;
protected final SOAPVersion soapVer;
protected final AddressingVersion addVer;
}

View File

@@ -0,0 +1,88 @@
/*
* 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.addressing;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceException;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.model.SEIModel;
import org.w3c.dom.Element;
/**
* @author Arun Gupta
*/
public class WsaTubeHelperImpl extends WsaTubeHelper {
static final JAXBContext jc;
static {
try {
jc = JAXBContext.newInstance(ProblemAction.class,
ProblemHeaderQName.class);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public WsaTubeHelperImpl(WSDLPort wsdlPort, SEIModel seiModel, WSBinding binding) {
super(binding,seiModel,wsdlPort);
}
private Marshaller createMarshaller() throws JAXBException {
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
return marshaller;
}
@Override
public final void getProblemActionDetail(String action, Element element) {
ProblemAction pa = new ProblemAction(action);
try {
createMarshaller().marshal(pa, element);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
@Override
public final void getInvalidMapDetail(QName name, Element element) {
ProblemHeaderQName phq = new ProblemHeaderQName(name);
try {
createMarshaller().marshal(phq, element);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
@Override
public final void getMapRequiredDetail(QName name, Element element) {
getInvalidMapDetail(name, element);
}
}

View File

@@ -0,0 +1,46 @@
/*
* 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.addressing.model;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.ws.WebServiceException;
/**
* @author Arun Gupta
*/
public class ActionNotSupportedException extends WebServiceException {
private String action;
public ActionNotSupportedException(String action) {
super(AddressingMessages.ACTION_NOT_SUPPORTED_EXCEPTION(action));
this.action = action;
}
public String getAction() {
return action;
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.addressing.model;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.ws.WebServiceException;
import javax.xml.namespace.QName;
/**
* This exception captures SOAP Fault information when a WS-Addressing 1.0 Message Addressing
* Property is invalid and cannot be processed.
*
* @author Rama Pulavarthi
*/
public class InvalidAddressingHeaderException extends WebServiceException {
private QName problemHeader;
private QName subsubcode;
/**
* Creates a InvalidAddressingHeader exception capturing information about the invalid
* Addressing Message Property and the reason in Subsubcode.
* @param problemHeader
* represents the invalid Addressing Header.
* @param subsubcode
* represents the reason why the Addressing header in question is invalid.
*/
public InvalidAddressingHeaderException(QName problemHeader, QName subsubcode) {
super(AddressingMessages.INVALID_ADDRESSING_HEADER_EXCEPTION(problemHeader,subsubcode));
this.problemHeader = problemHeader;
this.subsubcode = subsubcode;
}
public QName getProblemHeader() {
return problemHeader;
}
public QName getSubsubcode() {
return subsubcode;
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.addressing.model;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.resources.AddressingMessages;
import javax.xml.ws.WebServiceException;
import javax.xml.namespace.QName;
/**
* This exception signals that a particular WS-Addressing header is missing in a SOAP message.
*
* @author Rama Pulavarthi
*/
public class MissingAddressingHeaderException extends WebServiceException {
private final QName name;
private transient final Packet packet;
/**
*
* @param name QName of the missing WS-Addressing Header
*/
public MissingAddressingHeaderException(@NotNull QName name) {
this(name,null);
}
public MissingAddressingHeaderException(@NotNull QName name, @Nullable Packet p) {
super(AddressingMessages.MISSING_HEADER_EXCEPTION(name));
this.name = name;
this.packet = p;
}
/**
* Gets the QName of the missing WS-Addressing Header.
*
* @return
* never null.
*/
public QName getMissingHeaderQName() {
return name;
}
/**
* The {@link Packet} in which a header was missing.
*
* <p>
* This object can be used to deep-inspect the problematic SOAP message.
*/
public Packet getPacket() {
return packet;
}
}

View File

@@ -0,0 +1,146 @@
/*
* 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.addressing.policy;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.policy.AssertionSet;
import com.sun.xml.internal.ws.policy.NestedPolicy;
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.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.addressing.W3CAddressingMetadataConstants;
import com.sun.xml.internal.ws.resources.ModelerMessages;
import com.sun.xml.internal.bind.util.Which;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Level;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceFeature;
import javax.xml.ws.WebServiceException;
import javax.xml.ws.soap.AddressingFeature;
/**
* This Policy extension configures the WSDLModel with AddressingFeature when Addressing assertions are present in the
* PolicyMap.
*
* @author japod
* @author Rama Pulavarthi
*/
public class AddressingFeatureConfigurator implements PolicyFeatureConfigurator {
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingFeatureConfigurator.class);
private static final QName[] ADDRESSING_ASSERTIONS = {
new QName(AddressingVersion.MEMBER.policyNsUri, "UsingAddressing")};
/**
* Creates a new instance of AddressingFeatureConfigurator
*/
public AddressingFeatureConfigurator() {
}
public Collection<WebServiceFeature> getFeatures(final PolicyMapKey key, final PolicyMap policyMap) throws PolicyException {
LOGGER.entering(key, policyMap);
final Collection<WebServiceFeature> features = new LinkedList<WebServiceFeature>();
if ((key != null) && (policyMap != null)) {
final Policy policy = policyMap.getEndpointEffectivePolicy(key);
for (QName addressingAssertionQName : ADDRESSING_ASSERTIONS) {
if ((policy != null) && policy.contains(addressingAssertionQName)) {
final Iterator <AssertionSet> assertions = policy.iterator();
while(assertions.hasNext()){
final AssertionSet assertionSet = assertions.next();
final Iterator<PolicyAssertion> policyAssertion = assertionSet.iterator();
while(policyAssertion.hasNext()){
final PolicyAssertion assertion = policyAssertion.next();
if(assertion.getName().equals(addressingAssertionQName)){
final WebServiceFeature feature = AddressingVersion.getFeature(addressingAssertionQName.getNamespaceURI(), true, !assertion.isOptional());
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
}
features.add(feature);
} // end-if non optional wsa assertion found
} // next assertion
} // next alternative
} // end-if policy contains wsa assertion
} //end foreach addr assertion
// Deal with WS-Addressing 1.0 Metadata assertions
if (policy != null && policy.contains(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
for (AssertionSet assertions : policy) {
for (PolicyAssertion assertion : assertions) {
if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
NestedPolicy nestedPolicy = assertion.getNestedPolicy();
boolean requiresAnonymousResponses = false;
boolean requiresNonAnonymousResponses = false;
if (nestedPolicy != null) {
requiresAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
requiresNonAnonymousResponses = nestedPolicy.contains(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
}
if(requiresAnonymousResponses && requiresNonAnonymousResponses) {
throw new WebServiceException("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
}
final WebServiceFeature feature;
try {
if (requiresAnonymousResponses) {
feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.ANONYMOUS);
} else if (requiresNonAnonymousResponses) {
feature = new AddressingFeature(true, !assertion.isOptional(), AddressingFeature.Responses.NON_ANONYMOUS);
} else {
feature = new AddressingFeature(true, !assertion.isOptional());
}
} catch (NoSuchMethodError e) {
throw LOGGER.logSevereException(new PolicyException(ModelerMessages.RUNTIME_MODELER_ADDRESSING_RESPONSES_NOSUCHMETHOD(toJar(Which.which(AddressingFeature.class))), e));
}
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Added addressing feature \"" + feature + "\" for element \"" + key + "\"");
}
features.add(feature);
}
}
}
}
}
LOGGER.exiting(features);
return features;
}
/**
* Given the URL String inside jar, returns the URL to the jar itself.
*/
private static String toJar(String url) {
if(!url.startsWith("jar:"))
return url;
url = url.substring(4); // cut off jar:
return url.substring(0,url.lastIndexOf('!')); // cut off everything after '!'
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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.addressing.policy;
import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.model.SEIModel;
import com.sun.xml.internal.ws.policy.AssertionSet;
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.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.AssertionData;
import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.logging.Level;
import javax.xml.namespace.QName;
import javax.xml.ws.soap.AddressingFeature;
/**
* Generate an addressing policy and updates the PolicyMap if AddressingFeature is enabled.
*
* @author Fabian Ritzmann
* @author Rama Pulavarthi
*/
public class AddressingPolicyMapConfigurator implements PolicyMapConfigurator {
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingPolicyMapConfigurator.class);
private static final class AddressingAssertion extends PolicyAssertion {
/**
* Creates an assertion with nested alternatives.
*
* @param assertionData
* @param nestedAlternative
*/
AddressingAssertion(AssertionData assertionData, final AssertionSet nestedAlternative) {
super(assertionData, null, nestedAlternative);
}
/**
* Creates an assertion with no nested alternatives.
*
* @param assertionData
*/
AddressingAssertion(AssertionData assertionData) {
super(assertionData, null, null);
}
}
/**
* Puts an addressing policy into the PolicyMap if the addressing feature was set.
*/
public Collection<PolicySubject> update(final PolicyMap policyMap, final SEIModel model, final WSBinding wsBinding)
throws PolicyException {
LOGGER.entering(policyMap, model, wsBinding);
Collection<PolicySubject> subjects = new ArrayList<PolicySubject>();
if (policyMap != null) {
final AddressingFeature addressingFeature = wsBinding.getFeature(AddressingFeature.class);
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.finest("addressingFeature = " + addressingFeature);
}
if ((addressingFeature != null) && addressingFeature.isEnabled()) {
//add wsam:Addrressing assertion if not exists.
addWsamAddressing(subjects, policyMap, model, addressingFeature);
}
} // endif policy map not null
LOGGER.exiting(subjects);
return subjects;
}
private void addWsamAddressing(Collection<PolicySubject> subjects, PolicyMap policyMap, SEIModel model, AddressingFeature addressingFeature)
throws PolicyException {
final QName bindingName = model.getBoundPortTypeName();
final WsdlBindingSubject wsdlSubject = WsdlBindingSubject.createBindingSubject(bindingName);
final Policy addressingPolicy = createWsamAddressingPolicy(bindingName, addressingFeature);
final PolicySubject addressingPolicySubject = new PolicySubject(wsdlSubject, addressingPolicy);
subjects.add(addressingPolicySubject);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.fine("Added addressing policy with ID \"" + addressingPolicy.getIdOrName() + "\" to binding element \"" + bindingName + "\"");
}
}
/**
* Create a policy with an WSAM Addressing assertion.
*/
private Policy createWsamAddressingPolicy(final QName bindingName, AddressingFeature af) {
final ArrayList<AssertionSet> assertionSets = new ArrayList<AssertionSet>(1);
final ArrayList<PolicyAssertion> assertions = new ArrayList<PolicyAssertion>(1);
final AssertionData addressingData =
AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION);
if (!af.isRequired()) {
addressingData.setOptionalAttribute(true);
}
try {
AddressingFeature.Responses responses = af.getResponses();
if (responses == AddressingFeature.Responses.ANONYMOUS) {
AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null);
assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser))));
} else if (responses == AddressingFeature.Responses.NON_ANONYMOUS) {
final AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null);
assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser))));
} else {
assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null)));
}
} catch (NoSuchMethodError e) {
//If JAX-WS 2.2 API is really required, it would been reported in @Addressing or wsam:Addressing processing
//Don't add any nested assertion to mimic the 2.1 behavior
assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null)));
}
assertionSets.add(AssertionSet.createAssertionSet(assertions));
return Policy.createPolicy(null, bindingName.getLocalPart() + "_WSAM_Addressing_Policy", assertionSets);
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.addressing.policy;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.policy.PolicyAssertion;
import com.sun.xml.internal.ws.policy.NestedPolicy;
import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
import com.sun.xml.internal.ws.policy.spi.PolicyAssertionValidator;
import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
import java.util.ArrayList;
import javax.xml.namespace.QName;
/**
* This class validates the Addressing assertions.
* If the assertion is wsam:Addressing, it makes sure that only valid assertions are nested.
*
* @author japod
* @author Rama Pulavarthi
*/
public class AddressingPolicyValidator implements PolicyAssertionValidator {
private static final ArrayList<QName> supportedAssertions = new ArrayList<QName>();
static {
supportedAssertions.add(new QName(AddressingVersion.MEMBER.policyNsUri, "UsingAddressing"));
supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION);
supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
supportedAssertions.add(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
}
/**
* Creates a new instance of AddressingPolicyValidator
*/
public AddressingPolicyValidator() {
}
public Fitness validateClientSide(PolicyAssertion assertion) {
return supportedAssertions.contains(assertion.getName()) ? Fitness.SUPPORTED : Fitness.UNKNOWN;
}
public Fitness validateServerSide(PolicyAssertion assertion) {
if (!supportedAssertions.contains(assertion.getName()))
return Fitness.UNKNOWN;
//Make sure wsam:Addressing contains only one of the allowed nested assertions.
if (assertion.getName().equals(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION)) {
NestedPolicy nestedPolicy = assertion.getNestedPolicy();
if (nestedPolicy != null) {
boolean requiresAnonymousResponses = false;
boolean requiresNonAnonymousResponses = false;
for (PolicyAssertion nestedAsser : nestedPolicy.getAssertionSet()) {
if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION)) {
requiresAnonymousResponses = true;
} else if (nestedAsser.getName().equals(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION)) {
requiresNonAnonymousResponses = true;
} else {
LOGGER.warning("Found unsupported assertion:\n" + nestedAsser + "\nnested into assertion:\n" + assertion);
return Fitness.UNSUPPORTED;
}
}
if (requiresAnonymousResponses && requiresNonAnonymousResponses) {
LOGGER.warning("Only one among AnonymousResponses and NonAnonymousResponses can be nested in an Addressing assertion");
return Fitness.INVALID;
}
}
}
return Fitness.SUPPORTED;
}
public String[] declareSupportedDomains() {
return new String[]{AddressingVersion.MEMBER.policyNsUri, AddressingVersion.W3C.policyNsUri, W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME};
}
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingPolicyValidator.class);
}

View File

@@ -0,0 +1,55 @@
/*
* 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.addressing.policy;
import com.sun.xml.internal.ws.api.addressing.AddressingVersion;
import com.sun.xml.internal.ws.policy.spi.PrefixMapper;
import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants;
import java.util.HashMap;
import java.util.Map;
/**
* This supplies the prefixes for the namespaces under Addressing domain.
*
* @author Fabian Ritzmann
* @author Rama Pulavarthi
*/
public class AddressingPrefixMapper implements PrefixMapper {
private static final Map<String, String> prefixMap = new HashMap<String, String>();
static {
prefixMap.put(AddressingVersion.MEMBER.policyNsUri, "wsap");
prefixMap.put(AddressingVersion.MEMBER.nsUri, "wsa");
prefixMap.put(W3CAddressingMetadataConstants.WSAM_NAMESPACE_NAME,W3CAddressingMetadataConstants.WSAM_PREFIX_NAME);
}
public Map<String, String> getPrefixMap() {
return prefixMap;
}
}

View File

@@ -0,0 +1,82 @@
/*
* 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.addressing.v200408;
import javax.xml.namespace.QName;
/**
* Constants for Member Submission WS-Addressing version
*
* @author Arun Gupta
*/
public interface MemberSubmissionAddressingConstants {
public static final String WSA_NAMESPACE_NAME = "http://schemas.xmlsoap.org/ws/2004/08/addressing";
public static final String WSA_NAMESPACE_WSDL_NAME = WSA_NAMESPACE_NAME;
public static final String WSA_NAMESPACE_POLICY_NAME = "http://schemas.xmlsoap.org/ws/2004/08/addressing/policy";
public static final QName WSA_ACTION_QNAME = new QName(WSA_NAMESPACE_NAME,"Action");
public static final String WSA_SERVICENAME_NAME = "ServiceName";
public static final String WSA_PORTTYPE_NAME = "PortType";
public static final String WSA_PORTNAME_NAME = "PortName";
public static final String WSA_ADDRESS_NAME = "Address";
public static final QName WSA_ADDRESS_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_ADDRESS_NAME);
public static final String WSA_EPR_NAME = "EndpointReference";
public static final QName WSA_EPR_QNAME = new QName(WSA_NAMESPACE_NAME, WSA_EPR_NAME);
public static final String WSA_ANONYMOUS_ADDRESS = WSA_NAMESPACE_NAME + "/role/anonymous";
public static final String WSA_NONE_ADDRESS = "";
public static final String WSA_DEFAULT_FAULT_ACTION = WSA_NAMESPACE_NAME + "/fault";
public static final QName INVALID_MAP_QNAME = new QName(WSA_NAMESPACE_NAME, "InvalidMessageInformationHeader");
public static final QName MAP_REQUIRED_QNAME = new QName(WSA_NAMESPACE_NAME, "MessageInformationHeaderRequired");
public static final QName DESTINATION_UNREACHABLE_QNAME = new QName(WSA_NAMESPACE_NAME, "DestinationUnreachable");
public static final QName ACTION_NOT_SUPPORTED_QNAME = new QName(WSA_NAMESPACE_NAME, "ActionNotSupported");
public static final QName ENDPOINT_UNAVAILABLE_QNAME = new QName(WSA_NAMESPACE_NAME, "EndpointUnavailable");
public static final String ACTION_NOT_SUPPORTED_TEXT = "The \"%s\" cannot be processed at the receiver.";
public static final String DESTINATION_UNREACHABLE_TEXT = "No route can be determined to reach the destination role defined by the WS-Addressing To.";
public static final String ENDPOINT_UNAVAILABLE_TEXT = "The endpoint is unable to process the message at this time.";
public static final String INVALID_MAP_TEXT = "A message information header is not valid and the message cannot be processed.";
public static final String MAP_REQUIRED_TEXT = "A required message information header, To, MessageID, or Action, is not present.";
public static final QName PROBLEM_ACTION_QNAME = new QName(WSA_NAMESPACE_NAME, "ProblemAction");
public static final QName PROBLEM_HEADER_QNAME_QNAME = new QName(WSA_NAMESPACE_NAME, "ProblemHeaderQName");
public static final QName FAULT_DETAIL_QNAME = new QName(WSA_NAMESPACE_NAME, "FaultDetail");
public
static final String ANONYMOUS_EPR = "<EndpointReference xmlns=\"http://schemas.xmlsoap.org/ws/2004/08/addressing\">\n"+
" <Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</Address>\n"+
"</EndpointReference>";
public static final QName MEX_METADATA = new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "Metadata","mex");
public static final QName MEX_METADATA_SECTION = new QName("http://schemas.xmlsoap.org/ws/2004/09/mex", "MetadataSection","mex");
public static final String MEX_METADATA_DIALECT_ATTRIBUTE = "Dialect";
public static final String MEX_METADATA_DIALECT_VALUE = "http://schemas.xmlsoap.org/wsdl/";
}

View File

@@ -0,0 +1,85 @@
/*
* 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.addressing.v200408;
import com.sun.xml.internal.ws.addressing.WsaClientTube;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.AddressingUtils;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing;
import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
/**
* @author Rama Pulavarthi
*/
public class MemberSubmissionWsaClientTube extends WsaClientTube {
private final MemberSubmissionAddressing.Validation validation;
public MemberSubmissionWsaClientTube(WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(wsdlPort, binding, next);
validation = binding.getFeature(MemberSubmissionAddressingFeature.class).getValidation();
}
public MemberSubmissionWsaClientTube(MemberSubmissionWsaClientTube that, TubeCloner cloner) {
super(that, cloner);
this.validation = that.validation;
}
public MemberSubmissionWsaClientTube copy(TubeCloner cloner) {
return new MemberSubmissionWsaClientTube(this, cloner);
}
@Override
protected void checkMandatoryHeaders(Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
boolean foundFaultTo, boolean foundMessageID, boolean foundRelatesTo) {
super.checkMandatoryHeaders(packet,foundAction,foundTo,foundReplyTo,foundFaultTo,foundMessageID,foundRelatesTo);
// if no wsa:To header is found
if (!foundTo) {
throw new MissingAddressingHeaderException(addressingVersion.toTag,packet);
}
if (!validation.equals(MemberSubmissionAddressing.Validation.LAX)) {
// if it is not one-way, response must contain wsa:RelatesTo
// RelatesTo required as per
// Table 5-3 of http://www.w3.org/TR/2006/WD-ws-addr-wsdl-20060216/#wsdl11requestresponse
if (expectReply && (packet.getMessage() != null) && !foundRelatesTo) {
String action = AddressingUtils.getAction(packet.getMessage().getHeaders(), addressingVersion, soapVersion);
// Don't check for AddressingFaults as
// Faults for requests with duplicate MessageId will have no wsa:RelatesTo
if (!packet.getMessage().isFault() || !action.equals(addressingVersion.getDefaultFaultAction())) {
throw new MissingAddressingHeaderException(addressingVersion.relatesToTag,packet);
}
}
}
}
}

View File

@@ -0,0 +1,88 @@
/*
* 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.addressing.v200408;
import com.sun.istack.internal.NotNull;
import com.sun.xml.internal.ws.addressing.WsaServerTube;
import com.sun.xml.internal.ws.addressing.model.MissingAddressingHeaderException;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.TubeCloner;
import com.sun.xml.internal.ws.api.server.WSEndpoint;
import com.sun.xml.internal.ws.developer.MemberSubmissionAddressing;
import com.sun.xml.internal.ws.developer.MemberSubmissionAddressingFeature;
/**
* @author Rama Pulavarthi
*/
public class MemberSubmissionWsaServerTube extends WsaServerTube {
private final MemberSubmissionAddressing.Validation validation;
public MemberSubmissionWsaServerTube(WSEndpoint endpoint, @NotNull WSDLPort wsdlPort, WSBinding binding, Tube next) {
super(endpoint, wsdlPort, binding, next);
validation = binding.getFeature(MemberSubmissionAddressingFeature.class).getValidation();
}
public MemberSubmissionWsaServerTube(MemberSubmissionWsaServerTube that, TubeCloner cloner) {
super(that, cloner);
this.validation = that.validation;
}
@Override
public MemberSubmissionWsaServerTube copy(TubeCloner cloner) {
return new MemberSubmissionWsaServerTube(this, cloner);
}
@Override
protected void checkMandatoryHeaders(Packet packet, boolean foundAction, boolean foundTo, boolean foundReplyTo,
boolean foundFaultTo, boolean foundMessageId, boolean foundRelatesTo) {
super.checkMandatoryHeaders(packet, foundAction, foundTo, foundReplyTo,
foundFaultTo, foundMessageId, foundRelatesTo);
// if no wsa:To header is found
if (!foundTo)
throw new MissingAddressingHeaderException(addressingVersion.toTag,packet);
//we can find Req/Response or Oneway only with WSDLModel
if (wsdlPort != null) {
WSDLBoundOperation wbo = getWSDLBoundOperation(packet);
// if two-way, must contain wsa:ReplyTo
// Unlike W3C version, we cannot assume default value as anonymous if not present.
// For protocol messages, don't check as they do not have any corresponding wsdl operations
if (wbo != null && !wbo.getOperation().isOneWay() && !foundReplyTo) {
throw new MissingAddressingHeaderException(addressingVersion.replyToTag,packet);
}
}
if (!validation.equals(MemberSubmissionAddressing.Validation.LAX)) {
// wsa:MessageId is required if wsa:ReplyTo is present.
if ((foundReplyTo || foundFaultTo) && !foundMessageId)
throw new MissingAddressingHeaderException(addressingVersion.messageIDTag,packet);
}
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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.addressing.v200408;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import static com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants.WSA_NAMESPACE_NAME;
/**
* @author Arun Gupta
*/
@XmlRootElement(name="ProblemAction", namespace= WSA_NAMESPACE_NAME)
public class ProblemAction {
@XmlElement(name="Action", namespace= WSA_NAMESPACE_NAME)
private String action;
@XmlElement(name="SoapAction", namespace=WSA_NAMESPACE_NAME)
private String soapAction;
/** Creates a new instance of ProblemAction */
public ProblemAction() {
}
public ProblemAction(String action) {
this.action = action;
}
public ProblemAction(String action, String soapAction) {
this.action = action;
this.soapAction = soapAction;
}
public String getAction() {
return action;
}
public String getSoapAction() {
return soapAction;
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.addressing.v200408;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import javax.xml.namespace.QName;
import static com.sun.xml.internal.ws.addressing.v200408.MemberSubmissionAddressingConstants.WSA_NAMESPACE_NAME;
/**
* @author Arun Gupta
*/
@XmlRootElement(name="ProblemHeaderQName", namespace= WSA_NAMESPACE_NAME)
public class ProblemHeaderQName {
@XmlValue
private QName value;
/** Creates a new instance of ProblemHeaderQName */
public ProblemHeaderQName() {
}
public ProblemHeaderQName(QName name) {
this.value = name;
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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.addressing.v200408;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceException;
import com.sun.xml.internal.ws.addressing.WsaTubeHelper;
import com.sun.xml.internal.ws.api.WSBinding;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLPort;
import com.sun.xml.internal.ws.api.model.SEIModel;
import org.w3c.dom.Element;
/**
* @author Arun Gupta
*/
public class WsaTubeHelperImpl extends WsaTubeHelper {
static final JAXBContext jc;
static {
try {
jc = JAXBContext.newInstance(ProblemAction.class,
ProblemHeaderQName.class);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
public WsaTubeHelperImpl(WSDLPort wsdlPort, SEIModel seiModel, WSBinding binding) {
super(binding,seiModel,wsdlPort);
}
private Marshaller createMarshaller() throws JAXBException {
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
return marshaller;
}
@Override
public final void getProblemActionDetail(String action, Element element) {
ProblemAction pa = new ProblemAction(action);
try {
createMarshaller().marshal(pa, element);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
@Override
public final void getInvalidMapDetail(QName name, Element element) {
ProblemHeaderQName phq = new ProblemHeaderQName(name);
try {
createMarshaller().marshal(phq, element);
} catch (JAXBException e) {
throw new WebServiceException(e);
}
}
@Override
public final void getMapRequiredDetail(QName name, Element element) {
getInvalidMapDetail(name, element);
}
}