From jbossws-commits at lists.jboss.org Thu Feb 11 07:36:37 2010 Content-Type: multipart/mixed; boundary="===============6953875679746444203==" MIME-Version: 1.0 From: jbossws-commits at lists.jboss.org To: jbossws-commits at lists.jboss.org Subject: [jbossws-commits] JBossWS SVN: r11577 - in stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws: wsaddressing and 1 other directory. Date: Thu, 11 Feb 2010 07:36:36 -0500 Message-ID: <201002111236.o1BCaakn011014@svn01.web.mwc.hst.phx2.redhat.com> --===============6953875679746444203== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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/sp= i/ProviderImpl.java stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/ws= addressing/NativeEndpointReference.java Log: [JBWS-2914] implementing missing bits in NativeEndpointReference Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/j= axws/spi/ProviderImpl.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/s= pi/ProviderImpl.java 2010-02-10 18:31:18 UTC (rev 11576) +++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/s= pi/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 getPort(final EndpointReference epr, final Class sei, f= inal WebServiceFeature... features) { final NativeEndpointReference nepr =3D EndpointReferenceUtil.transfo= rm(NativeEndpointReference.class, epr); - if (nepr.getWsdlLocation() =3D=3D null) - { - nepr.setWsdlLocation(nepr.getAddress() + "?wsdl"); - } final URL wsdlLocation =3D nepr.getWsdlLocation(); final QName serviceName =3D nepr.getServiceName(); final ServiceDelegate delegate =3D createServiceDelegate(wsdlLocatio= n, serviceName, Service.class); Modified: stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/j= axws/wsaddressing/NativeEndpointReference.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/w= saddressing/NativeEndpointReference.java 2010-02-10 18:31:18 UTC (rev 11576) +++ stack/native/trunk/modules/core/src/main/java/org/jboss/ws/core/jaxws/w= saddressing/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 Richard Opalkaok * @since 28-Feb-2009 - * = */ - -// XmlRootElement allows this class to be marshalled on its own -(a)XmlRootElement(name =3D "EndpointReference", namespace =3D NativeEndpoi= ntReference.NS) -(a)XmlType(name =3D "EndpointReferenceType", namespace =3D NativeEndpointR= eference.NS) +(a)XmlRootElement(name =3D "EndpointReference", namespace =3D NativeEndpoi= ntReference.WSA_NS) +(a)XmlType(name =3D "EndpointReferenceType", namespace =3D NativeEndpointR= eference.WSA_NS) public final class NativeEndpointReference extends EndpointReference { - protected static final String NS =3D "http://www.w3.org/2005/08/address= ing"; + protected static final String WSA_NS =3D "http://www.w3.org/2005/08/add= ressing"; + private static final String WSAM_NS =3D "http://www.w3.org/2007/05/addr= essing/metadata"; + private static final QName SERVICE_QNAME =3D new QName(WSAM_NS, "Servic= eName", "wsam"); + private static final QName INTERFACE_QNAME =3D new QName(WSAM_NS, "Inte= rfaceName", "wsam"); + private static final QName WSDL_LOCATION_QNAME =3D new QName("wsdlLocat= ion"); + private static final String ENDPOINT_ATTRIBUTE =3D "EndpointName"; + private static final JAXBContext jc =3D getJaxbContext(); = - private final static JAXBContext jc =3D getJaxbContext(); - = // private but necessary properties for databinding - @XmlElement(name =3D "Address", namespace =3D NS) + @XmlElement(name =3D "Address", namespace =3D WSA_NS) private Address address; - @XmlElement(name =3D "ReferenceParameters", namespace =3D NS) - private Elements referenceParameters; - @XmlElement(name =3D "Metadata", namespace =3D NS) - private Elements metadata; + @XmlElement(name =3D "ReferenceParameters", namespace =3D WSA_NS) + private Elements referenceParameters =3D new Elements(); + @XmlElement(name =3D "Metadata", namespace =3D WSA_NS) + private Elements metadata =3D new Elements(); @XmlAnyAttribute - Map attributes; + private Map attributes; @XmlAnyElement - List elements; + private List 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 =3D jc.createUnmarshaller().unmarshal= (source, NativeEndpointReference.class).getValue(); this.address =3D epr.address; + this.referenceParameters =3D epr.referenceParameters; this.metadata =3D epr.metadata; - this.referenceParameters =3D epr.referenceParameters; + this.attributes =3D epr.attributes; + this.elements =3D epr.elements; + if (epr.metadata !=3D null) + { + Map metadataAttributes =3D epr.metadata.getAttr= ibutes(); + if (metadataAttributes !=3D null) + { + final String wsdlLocation =3D metadataAttributes.get(WSDL_L= OCATION_QNAME); + if (wsdlLocation !=3D null) + { + this.setWsdlLocation(wsdlLocation); + } + } + List metadataElements =3D epr.metadata.getElements(); + if (metadataElements !=3D null) + { + for (Element e : epr.metadata.getElements()) + { + if (WSAM_NS.equals(e.getNamespaceURI())) + { + if (e.getNodeName().equals(SERVICE_QNAME.getLocalPart= ())) + { + QName serviceQName =3D this.getQName(e, e.getNodeV= alue()); + this.setServiceName(serviceQName); + String endpointName =3D e.getAttribute(ENDPOINT_AT= TRIBUTE); = + if (endpointName !=3D null) + { + QName endpointQName =3D this.getQName(e, endpoi= ntName); + this.setEndpointName(endpointQName); + } + } + if (e.getNodeName().equals(INTERFACE_QNAME.getLocalPa= rt())) + { + QName interfaceQName =3D this.getQName(e, e.getNod= eValue()); + this.setServiceName(interfaceQName); + } + } + } + } + } } catch (JAXBException e) { @@ -127,6 +174,9 @@ = public void setAddress(String address) { + if (address =3D=3D null) + return; + = this.address =3D new Address(address); } = @@ -136,9 +186,17 @@ return serviceName; } = - public void setServiceName(QName serviceName) + public void setServiceName(final QName serviceName) { + if (serviceName =3D=3D null) + return; + = this.serviceName =3D serviceName; + this.serviceNameElement =3D DOMUtils.createElement(SERVICE_QNAME); + final String attrName =3D "xmlns:" + serviceName.getPrefix(); + this.serviceNameElement.setAttribute(attrName, serviceName.getNamesp= aceURI()); + this.serviceNameElement.setTextContent(this.toString(serviceName)); + this.metadata.addElement(this.serviceNameElement); } = @XmlTransient @@ -149,47 +207,85 @@ = public void setEndpointName(QName endpointName) { + if (endpointName =3D=3D null) + return; + = this.endpointName =3D endpointName; } = @XmlTransient + public QName getInterfaceName() + { + return interfaceName; + } + + public void setInterfaceName(final QName interfaceName) + { + if (interfaceName =3D=3D null) + return; + = + this.interfaceName =3D interfaceName; + Element interfaceNameElement =3D DOMUtils.createElement(INTERFACE_Q= NAME); + final String attrName =3D "xmlns:" + interfaceName.getPrefix(); + interfaceNameElement.setAttribute(attrName, interfaceName.getNamespa= ceURI()); + interfaceNameElement.setTextContent(this.toString(interfaceName)); + this.metadata.addElement(interfaceNameElement); + } + = + @XmlTransient public List getMetadata() { - return metadata !=3D null ? metadata.getElements() : null; + return this.metadata.getElements(); } = public void setMetadata(List metadata) { - this.metadata =3D new Elements(metadata); + if ((metadata =3D=3D null) || (metadata.size() =3D=3D 0)) + return; + = + this.metadata.setElements(metadata); } = @XmlTransient public URL getWsdlLocation() { - return wsdlLocation; - } - - public void setWsdlLocation(String wsdlLocation) - { - try + if (this.wsdlLocation !=3D null) { - this.wsdlLocation =3D wsdlLocation !=3D null ? new URL(wsdlLocati= on) : null; + return this.toURL(this.wsdlLocation); } - catch (MalformedURLException e) + else { - throw new IllegalArgumentException("Invalid URL: " + wsdlLocation= ); + String address =3D this.getAddress(); + if (address !=3D null) + { + return this.toURL(address + "?wsdl"); + } } + = + return null; } + = + public void setWsdlLocation(String wsdlLocation) + { + if (wsdlLocation =3D=3D null) + return; + = + this.wsdlLocation =3D wsdlLocation; + this.metadata.addAttribute(WSDL_LOCATION_QNAME, wsdlLocation); + } = @XmlTransient public List getReferenceParameters() { - return referenceParameters !=3D null ? referenceParameters.getElemen= ts() : null; + return this.referenceParameters.getElements(); } = public void setReferenceParameters(List metadata) { - this.referenceParameters =3D new Elements(metadata); + if ((metadata =3D=3D null) || (metadata.size() =3D=3D 0)) + return; + = + this.referenceParameters.setElements(metadata); } = /** @@ -218,6 +314,10 @@ */ public void writeTo(Result result) { + if (this.endpointName !=3D null && this.serviceName !=3D null) + { + this.serviceNameElement.setAttribute(ENDPOINT_ATTRIBUTE, this.toS= tring(this.endpointName)); + } try { Marshaller marshaller =3D 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 =3D new StringBuilder(); + if (qname.getPrefix() !=3D 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 =3D nodeValue.indexOf(':'); + if (separatorIndex =3D=3D -1) + { + return new QName(nodeValue); + } + else + { + final String prefix =3D nodeValue.substring(0, separatorIndex); + final String localPart =3D nodeValue.substring(separatorIndex + 1= ); + final String namespace =3D e.lookupNamespaceURI(prefix); + return new QName(namespace, localPart, prefix); + } + } + private static class Address { @XmlValue @@ -305,8 +445,24 @@ = public void setElements(List elements) { - this.elements =3D elements; + if (this.elements =3D=3D null) + { + this.elements =3D elements; + } + else + { + this.elements.addAll(elements); + } } + = + public void addElement(Element e) + { + if (this.elements =3D=3D null) + { + this.elements =3D new LinkedList(); + } + this.elements.add(e); + } = @XmlTransient public Map getAttributes() @@ -316,7 +472,24 @@ = public void setAttributes(Map attributes) { - this.attributes =3D attributes; + if (this.attributes =3D=3D null) + { + this.attributes =3D attributes; + } + else + { + this.attributes.putAll(attributes); + } } + = + public void addAttribute(QName attrName, String attrValue) + { + if (this.attributes =3D=3D null) + { + this.attributes =3D new HashMap(); + } + this.attributes.put(attrName, attrValue); + } } + = } --===============6953875679746444203==--