You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jl...@apache.org on 2007/11/22 08:16:47 UTC
svn commit: r597314 - in /incubator/cxf/trunk/rt/frontend/jaxws/src:
main/java/org/apache/cxf/jaxws/spi/ test/java/org/apache/cxf/jaxws/
test/java/org/apache/cxf/jaxws/resources/
Author: jliu
Date: Wed Nov 21 23:16:45 2007
New Revision: 597314
URL: http://svn.apache.org/viewvc?rev=597314&view=rev
Log:
Support JAX-WS 2.1 Provider.createW3CEndpointReference()
Modified:
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/Messages.properties
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/resources/hello_world_soap_http_infoset.xml
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/Messages.properties
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/Messages.properties?rev=597314&r1=597313&r2=597314&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/Messages.properties (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/Messages.properties Wed Nov 21 23:16:45 2007
@@ -21,4 +21,4 @@
INVALID_IMPLEMENTOR_EXC = Cannot create Endpoint for implementor that does not have a WebService annotation and does not implement the Provider interface
ENDPOINT_CREATION_FAILED_MSG = Failed to create endpoint
JAXBCONTEXT_CREATION_FAILED = Failed to create JAXBContext for W3CEndpointReference.
-ERROR_UNMARSHAL_ENDPOINTREFERENCE = Failed to unmarshal EndpointReference from inforset.
+ERROR_UNMARSHAL_ENDPOINTREFERENCE = Failed to unmarshal EndpointReference from infoset.
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java?rev=597314&r1=597313&r2=597314&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java Wed Nov 21 23:16:45 2007
@@ -19,6 +19,8 @@
package org.apache.cxf.jaxws.spi;
+
+import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.logging.Logger;
@@ -27,6 +29,8 @@
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Source;
import javax.xml.ws.Endpoint;
import javax.xml.ws.EndpointReference;
@@ -41,22 +45,22 @@
import org.apache.cxf.BusFactory;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.jaxws.EndpointUtils;
import org.apache.cxf.jaxws.ServiceImpl;
-
+import org.apache.cxf.staxutils.StaxUtils;
public class ProviderImpl extends javax.xml.ws.spi.Provider {
public static final String JAXWS_PROVIDER = ProviderImpl.class.getName();
-
+ protected static final String W3C_NS = "http://www.w3.org/2005/08/addressing";
private static final Logger LOG = LogUtils.getL7dLogger(ProviderImpl.class);
-
+
+
private static JAXBContext jaxbContext;
@Override
- public ServiceDelegate createServiceDelegate(URL url,
- QName qname,
- Class cls) {
+ public ServiceDelegate createServiceDelegate(URL url, QName qname, Class cls) {
Bus bus = BusFactory.getThreadDefaultBus();
return new ServiceImpl(bus, url, qname, cls);
}
@@ -81,19 +85,84 @@
return ep;
}
- // TODO JAX-WS 2.1
-
- public W3CEndpointReference createW3CEndpointReference(String address,
- QName serviceName,
- QName portName,
+ public W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, QName portName,
List<Element> metadata,
String wsdlDocumentLocation,
List<Element> referenceParameters) {
- throw new UnsupportedOperationException();
+ CachedOutputStream cos = new CachedOutputStream();
+ XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(cos);
+
+ try {
+ //TODO: when serviceName/portName is null
+
+ writer.setPrefix("wsa", W3C_NS);
+
+ String portNamePrefix = null;
+ String serviceNamePrefix = (serviceName.getPrefix() == null
+ || serviceName.getPrefix().length() == 0)
+ ? "ns" : serviceName.getPrefix();
+
+ writer.writeStartElement("wsa", "EndpointReference", W3C_NS);
+ writer.writeNamespace("wsa", W3C_NS);
+ writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI());
+
+ if (!portName.getNamespaceURI().equals(serviceName.getNamespaceURI())) {
+ portNamePrefix = (portName.getPrefix() == null
+ || portName.getPrefix().length() == 0)
+ ? "ns1" : portName.getPrefix();
+
+ writer.writeNamespace(portNamePrefix, portName.getNamespaceURI());
+ } else {
+ portNamePrefix = serviceNamePrefix;
+ }
+
+ writer.writeStartElement("wsa", "Address", W3C_NS);
+ writer.writeCharacters(address);
+ writer.writeEndElement();
+
+ writer.writeStartElement("wsa", "portName", W3C_NS);
+ writer.writeCharacters(portNamePrefix + ":" + portName.getLocalPart());
+ writer.writeEndElement();
+
+ writer.writeStartElement("wsa", "ServiceName", W3C_NS);
+ writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart());
+ writer.writeEndElement();
+
+ if (referenceParameters != null) {
+ for (Element referenceParameter : referenceParameters) {
+ StaxUtils.writeElement(referenceParameter, writer, true);
+ }
+ }
+
+ if (metadata != null) {
+ for (Element meta : metadata) {
+ StaxUtils.writeElement(meta, writer, true);
+ }
+ }
+
+ writer.writeEndElement();
+ writer.flush();
+
+ } catch (XMLStreamException e) {
+ throw new WebServiceException(
+ new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
+ }
+
+ try {
+ Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller();
+ return (W3CEndpointReference)unmarshaller.unmarshal(cos.getInputStream());
+
+ } catch (JAXBException e) {
+ throw new WebServiceException(
+ new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
+ } catch (IOException e) {
+ throw new WebServiceException(
+ new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
+ }
+
}
- public <T> T getPort(EndpointReference endpointReference,
- Class<T> serviceEndpointInterface,
+ public <T> T getPort(EndpointReference endpointReference, Class<T> serviceEndpointInterface,
WebServiceFeature... features) {
throw new UnsupportedOperationException();
}
@@ -107,7 +176,7 @@
new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
}
}
-
+
private JAXBContext getJAXBContext() {
if (jaxbContext == null) {
try {
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java?rev=597314&r1=597313&r2=597314&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/EndpointReferenceTest.java Wed Nov 21 23:16:45 2007
@@ -237,7 +237,7 @@
Document doc = XMLUtils.parse(is);
Element referenceParameters = XMLUtils.fetchElementByNameAttribute(doc.getDocumentElement(),
"wsa:ReferenceParameters",
- "wsa:ReferenceParameters");
+ "");
endpoint.getEndpointReference(MyEndpointReference.class, referenceParameters);
fail("Did not get expected WebServiceException");
@@ -262,7 +262,6 @@
}
@Test
- @Ignore("Not implemented yet")
public void testProviderCreateW3CEndpointReference() throws Exception {
ProviderImpl provider = new ProviderImpl();
@@ -270,14 +269,17 @@
Document doc = XMLUtils.parse(is);
Element referenceParameter = XMLUtils.fetchElementByNameAttribute(doc.getDocumentElement(),
"wsa:ReferenceParameters",
- "wsa:ReferenceParameters");
+ "");
List<Element> referenceParameters = new ArrayList<Element>();
- referenceParameters.add(referenceParameter);
+ if (referenceParameter != null) {
+ referenceParameters.add(referenceParameter);
+ }
- Element metadata = XMLUtils.fetchElementByNameAttribute(doc.getDocumentElement(), "wsa:metadata",
- "wsa:metadata");
+ Element metadata = XMLUtils.fetchElementByNameAttribute(doc.getDocumentElement(), "wsa:metadata", "");
List<Element> metadataList = new ArrayList<Element>();
- metadataList.add(metadata);
+ if (metadata != null) {
+ metadataList.add(metadata);
+ }
W3CEndpointReference endpointReference = provider
.createW3CEndpointReference("http://localhost:8080/test", serviceName, portName, metadataList,
Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/resources/hello_world_soap_http_infoset.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/resources/hello_world_soap_http_infoset.xml?rev=597314&r1=597313&r2=597314&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/resources/hello_world_soap_http_infoset.xml (original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/resources/hello_world_soap_http_infoset.xml Wed Nov 21 23:16:45 2007
@@ -1,7 +1,10 @@
<wsa:EndpointReference xmlns:wsa="http://www.w3.org/2005/08/addressing">
<wsa:Address>http://localhost:8080/test</wsa:Address>
<wsa:ReferenceProperties></wsa:ReferenceProperties>
- <wsa:ReferenceParameters></wsa:ReferenceParameters>
+ <wsa:ReferenceParameters>
+ <testParameter1>testValue1</testParameter1>
+ <testParameter2>testValue2</testParameter2>
+ </wsa:ReferenceParameters>
<wsa:PortType></wsa:PortType>
<wsa:ServiceName></wsa:ServiceName>
<wsa:Policies></wsa:Policies>