Author: richard.opalka(a)jboss.com
Date: 2010-02-11 07:36:36 -0500 (Thu, 11 Feb 2010)
New Revision: 11577
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ProviderImpl.java
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/wsaddressing/NativeEndpointReference.java
Log:
[JBWS-2914] implementing missing bits in NativeEndpointReference
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ProviderImpl.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ProviderImpl.java 2010-02-10
18:31:18 UTC (rev 11576)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/spi/ProviderImpl.java 2010-02-11
12:36:36 UTC (rev 11577)
@@ -141,6 +141,7 @@
epr.setAddress(address);
epr.setServiceName(serviceName);
epr.setEndpointName(portName);
+ epr.setInterfaceName(interfaceName);
epr.setMetadata(metadata);
epr.setWsdlLocation(wsdlDocumentLocation);
epr.setReferenceParameters(referenceParameters);
@@ -158,10 +159,6 @@
public <T> T getPort(final EndpointReference epr, final Class<T> sei,
final WebServiceFeature... features)
{
final NativeEndpointReference nepr =
EndpointReferenceUtil.transform(NativeEndpointReference.class, epr);
- if (nepr.getWsdlLocation() == null)
- {
- nepr.setWsdlLocation(nepr.getAddress() + "?wsdl");
- }
final URL wsdlLocation = nepr.getWsdlLocation();
final QName serviceName = nepr.getServiceName();
final ServiceDelegate delegate = createServiceDelegate(wsdlLocation, serviceName,
Service.class);
Modified:
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/wsaddressing/NativeEndpointReference.java
===================================================================
---
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/wsaddressing/NativeEndpointReference.java 2010-02-10
18:31:18 UTC (rev 11576)
+++
stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/wsaddressing/NativeEndpointReference.java 2010-02-11
12:36:36 UTC (rev 11577)
@@ -23,6 +23,8 @@
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -42,6 +44,7 @@
import javax.xml.ws.EndpointReference;
import javax.xml.ws.WebServiceException;
+import org.jboss.wsf.common.DOMUtils;
import org.w3c.dom.Element;
/**
@@ -53,35 +56,39 @@
* @see EndpointReferenceUtil class.
*
* @author alessio.soldano(a)jboss.com
+ * @author <a href="mailto:ropalka@redhat.com">Richard
Opalka</a>ok
* @since 28-Feb-2009
- *
*/
-
-// XmlRootElement allows this class to be marshalled on its own
-@XmlRootElement(name = "EndpointReference", namespace =
NativeEndpointReference.NS)
-@XmlType(name = "EndpointReferenceType", namespace =
NativeEndpointReference.NS)
+@XmlRootElement(name = "EndpointReference", namespace =
NativeEndpointReference.WSA_NS)
+@XmlType(name = "EndpointReferenceType", namespace =
NativeEndpointReference.WSA_NS)
public final class NativeEndpointReference extends EndpointReference
{
- protected static final String NS = "http://www.w3.org/2005/08/addressing";
+ protected static final String WSA_NS =
"http://www.w3.org/2005/08/addressing";
+ private static final String WSAM_NS =
"http://www.w3.org/2007/05/addressing/metadata";
+ private static final QName SERVICE_QNAME = new QName(WSAM_NS, "ServiceName",
"wsam");
+ private static final QName INTERFACE_QNAME = new QName(WSAM_NS,
"InterfaceName", "wsam");
+ private static final QName WSDL_LOCATION_QNAME = new QName("wsdlLocation");
+ private static final String ENDPOINT_ATTRIBUTE = "EndpointName";
+ private static final JAXBContext jc = getJaxbContext();
- private final static JAXBContext jc = getJaxbContext();
-
// private but necessary properties for databinding
- @XmlElement(name = "Address", namespace = NS)
+ @XmlElement(name = "Address", namespace = WSA_NS)
private Address address;
- @XmlElement(name = "ReferenceParameters", namespace = NS)
- private Elements referenceParameters;
- @XmlElement(name = "Metadata", namespace = NS)
- private Elements metadata;
+ @XmlElement(name = "ReferenceParameters", namespace = WSA_NS)
+ private Elements referenceParameters = new Elements();
+ @XmlElement(name = "Metadata", namespace = WSA_NS)
+ private Elements metadata = new Elements();
@XmlAnyAttribute
- Map<QName, String> attributes;
+ private Map<QName, String> attributes;
@XmlAnyElement
- List<Element> elements;
+ private List<Element> elements;
// not marshalled
private QName serviceName;
+ private Element serviceNameElement;
private QName endpointName;
- private URL wsdlLocation;
+ private QName interfaceName;
+ private String wsdlLocation;
public NativeEndpointReference()
{
@@ -106,8 +113,48 @@
{
NativeEndpointReference epr = jc.createUnmarshaller().unmarshal(source,
NativeEndpointReference.class).getValue();
this.address = epr.address;
+ this.referenceParameters = epr.referenceParameters;
this.metadata = epr.metadata;
- this.referenceParameters = epr.referenceParameters;
+ this.attributes = epr.attributes;
+ this.elements = epr.elements;
+ if (epr.metadata != null)
+ {
+ Map<QName, String> metadataAttributes = epr.metadata.getAttributes();
+ if (metadataAttributes != null)
+ {
+ final String wsdlLocation = metadataAttributes.get(WSDL_LOCATION_QNAME);
+ if (wsdlLocation != null)
+ {
+ this.setWsdlLocation(wsdlLocation);
+ }
+ }
+ List<Element> metadataElements = epr.metadata.getElements();
+ if (metadataElements != null)
+ {
+ for (Element e : epr.metadata.getElements())
+ {
+ if (WSAM_NS.equals(e.getNamespaceURI()))
+ {
+ if (e.getNodeName().equals(SERVICE_QNAME.getLocalPart()))
+ {
+ QName serviceQName = this.getQName(e, e.getNodeValue());
+ this.setServiceName(serviceQName);
+ String endpointName = e.getAttribute(ENDPOINT_ATTRIBUTE);
+ if (endpointName != null)
+ {
+ QName endpointQName = this.getQName(e, endpointName);
+ this.setEndpointName(endpointQName);
+ }
+ }
+ if (e.getNodeName().equals(INTERFACE_QNAME.getLocalPart()))
+ {
+ QName interfaceQName = this.getQName(e, e.getNodeValue());
+ this.setServiceName(interfaceQName);
+ }
+ }
+ }
+ }
+ }
}
catch (JAXBException e)
{
@@ -127,6 +174,9 @@
public void setAddress(String address)
{
+ if (address == null)
+ return;
+
this.address = new Address(address);
}
@@ -136,9 +186,17 @@
return serviceName;
}
- public void setServiceName(QName serviceName)
+ public void setServiceName(final QName serviceName)
{
+ if (serviceName == null)
+ return;
+
this.serviceName = serviceName;
+ this.serviceNameElement = DOMUtils.createElement(SERVICE_QNAME);
+ final String attrName = "xmlns:" + serviceName.getPrefix();
+ this.serviceNameElement.setAttribute(attrName, serviceName.getNamespaceURI());
+ this.serviceNameElement.setTextContent(this.toString(serviceName));
+ this.metadata.addElement(this.serviceNameElement);
}
@XmlTransient
@@ -149,47 +207,85 @@
public void setEndpointName(QName endpointName)
{
+ if (endpointName == null)
+ return;
+
this.endpointName = endpointName;
}
@XmlTransient
+ public QName getInterfaceName()
+ {
+ return interfaceName;
+ }
+
+ public void setInterfaceName(final QName interfaceName)
+ {
+ if (interfaceName == null)
+ return;
+
+ this.interfaceName = interfaceName;
+ Element interfaceNameElement = DOMUtils.createElement(INTERFACE_QNAME);
+ final String attrName = "xmlns:" + interfaceName.getPrefix();
+ interfaceNameElement.setAttribute(attrName, interfaceName.getNamespaceURI());
+ interfaceNameElement.setTextContent(this.toString(interfaceName));
+ this.metadata.addElement(interfaceNameElement);
+ }
+
+ @XmlTransient
public List<Element> getMetadata()
{
- return metadata != null ? metadata.getElements() : null;
+ return this.metadata.getElements();
}
public void setMetadata(List<Element> metadata)
{
- this.metadata = new Elements(metadata);
+ if ((metadata == null) || (metadata.size() == 0))
+ return;
+
+ this.metadata.setElements(metadata);
}
@XmlTransient
public URL getWsdlLocation()
{
- return wsdlLocation;
- }
-
- public void setWsdlLocation(String wsdlLocation)
- {
- try
+ if (this.wsdlLocation != null)
{
- this.wsdlLocation = wsdlLocation != null ? new URL(wsdlLocation) : null;
+ return this.toURL(this.wsdlLocation);
}
- catch (MalformedURLException e)
+ else
{
- throw new IllegalArgumentException("Invalid URL: " + wsdlLocation);
+ String address = this.getAddress();
+ if (address != null)
+ {
+ return this.toURL(address + "?wsdl");
+ }
}
+
+ return null;
}
+
+ public void setWsdlLocation(String wsdlLocation)
+ {
+ if (wsdlLocation == null)
+ return;
+
+ this.wsdlLocation = wsdlLocation;
+ this.metadata.addAttribute(WSDL_LOCATION_QNAME, wsdlLocation);
+ }
@XmlTransient
public List<Element> getReferenceParameters()
{
- return referenceParameters != null ? referenceParameters.getElements() : null;
+ return this.referenceParameters.getElements();
}
public void setReferenceParameters(List<Element> metadata)
{
- this.referenceParameters = new Elements(metadata);
+ if ((metadata == null) || (metadata.size() == 0))
+ return;
+
+ this.referenceParameters.setElements(metadata);
}
/**
@@ -218,6 +314,10 @@
*/
public void writeTo(Result result)
{
+ if (this.endpointName != null && this.serviceName != null)
+ {
+ this.serviceNameElement.setAttribute(ENDPOINT_ATTRIBUTE,
this.toString(this.endpointName));
+ }
try
{
Marshaller marshaller = jc.createMarshaller();
@@ -230,6 +330,18 @@
}
}
+ private URL toURL(final String s)
+ {
+ try
+ {
+ return new URL(s);
+ }
+ catch (MalformedURLException e)
+ {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ }
+
private static JAXBContext getJaxbContext()
{
try
@@ -242,6 +354,34 @@
}
}
+ private String toString(final QName qname)
+ {
+ StringBuilder sb = new StringBuilder();
+ if (qname.getPrefix() != null && qname.getPrefix().length() > 0)
+ {
+ sb.append(qname.getPrefix());
+ sb.append(':');
+ }
+ sb.append(qname.getLocalPart());
+ return sb.toString();
+ }
+
+ private QName getQName(Element e, String nodeValue)
+ {
+ final int separatorIndex = nodeValue.indexOf(':');
+ if (separatorIndex == -1)
+ {
+ return new QName(nodeValue);
+ }
+ else
+ {
+ final String prefix = nodeValue.substring(0, separatorIndex);
+ final String localPart = nodeValue.substring(separatorIndex + 1);
+ final String namespace = e.lookupNamespaceURI(prefix);
+ return new QName(namespace, localPart, prefix);
+ }
+ }
+
private static class Address
{
@XmlValue
@@ -305,8 +445,24 @@
public void setElements(List<Element> elements)
{
- this.elements = elements;
+ if (this.elements == null)
+ {
+ this.elements = elements;
+ }
+ else
+ {
+ this.elements.addAll(elements);
+ }
}
+
+ public void addElement(Element e)
+ {
+ if (this.elements == null)
+ {
+ this.elements = new LinkedList<Element>();
+ }
+ this.elements.add(e);
+ }
@XmlTransient
public Map<QName, String> getAttributes()
@@ -316,7 +472,24 @@
public void setAttributes(Map<QName, String> attributes)
{
- this.attributes = attributes;
+ if (this.attributes == null)
+ {
+ this.attributes = attributes;
+ }
+ else
+ {
+ this.attributes.putAll(attributes);
+ }
}
+
+ public void addAttribute(QName attrName, String attrValue)
+ {
+ if (this.attributes == null)
+ {
+ this.attributes = new HashMap<QName, String>();
+ }
+ this.attributes.put(attrName, attrValue);
+ }
}
+
}