Author: ema
Date: Wed Dec 26 06:53:29 2007
New Revision: 606906
URL: http://svn.apache.org/viewvc?rev=606906&view=rev
Log:
[CXF-1317]Support generating wsdl location in ProviderImpl
Added:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProverImplTest.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/spi/ProviderImpl.java
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java?rev=606906&r1=606905&r2=606906&view=diff
==============================================================================
---
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
(original)
+++
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/ws/addressing/JAXWSAConstants.java
Wed Dec 26 06:53:29 2007
@@ -37,6 +37,18 @@
public static final String NS_WSA = "http://www.w3.org/2005/08/addressing";
public static final String WSA_PREFIX = "wsa";
+
+ public static final String WSA_ERF_NAME = "EndpointReference";
+ public static final String WSA_REFERENCEPARAMETERS_NAME =
"ReferenceParameters";
+ public static final String WSA_METADATA_NAME = "Metadata";
+ public static final String WSA_ADDRESS_NAME = "Address";
+
+ public static final String WSAW_SERVICENAME_NAME = "ServiceName";
+ public static final String WSAW_INTERFACE_NAME = "InterfaceName";
+ public static final String WSAW_ENDPOINT_NAME = "EndpointName";
+
+
+
/**
* Well-known Property names for AddressingProperties in BindingProvider
Modified:
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java?rev=606906&r1=606905&r2=606906&view=diff
==============================================================================
---
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
(original)
+++
incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/WSDLConstants.java
Wed Dec 26 06:53:29 2007
@@ -25,6 +25,7 @@
public static final String WSDL_PREFIX = "wsdl";
public static final String NS_WSDL11 = "http://schemas.xmlsoap.org/wsdl/";
+
public static final String NP_XMLNS = "xmlns";
public static final String NS_XMLNS = "http://www.w3.org/2000/xmlns/";
@@ -115,6 +116,7 @@
public static final String ATTR_TRANSPORT = "transport";
public static final String ATTR_LOCATION = "location";
public static final String ATTR_NAME = "name";
+ public static final String ATTR_NAMESPACE = "namespace";
public static final String ATTR_TNS = "targetNamespace";
// usual prefix for the targetNamespace.
public static final String CONVENTIONAL_TNS_PREFIX = "tns";
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=606906&r1=606905&r2=606906&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 Dec 26 06:53:29 2007
@@ -19,12 +19,12 @@
package org.apache.cxf.jaxws.spi;
-
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.logging.Logger;
+import javax.wsdl.Definition;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
@@ -43,7 +43,6 @@
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
-import org.apache.cxf.NSManager;
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.io.CachedOutputStream;
@@ -52,14 +51,14 @@
import org.apache.cxf.jaxws.ServiceImpl;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.ws.addressing.JAXWSAConstants;
+import org.apache.cxf.wsdl.WSDLConstants;
+import org.apache.cxf.wsdl.WSDLManager;
public class ProviderImpl extends javax.xml.ws.spi.Provider {
public static final String JAXWS_PROVIDER = ProviderImpl.class.getName();
private static final Logger LOG =
LogUtils.getL7dLogger(ProviderImpl.class);
private static JAXBContext jaxbContext;
- private final NSManager nsMan = new NSManager();
-
@Override
public ServiceDelegate createServiceDelegate(URL url, QName qname, Class
cls) {
Bus bus = BusFactory.getThreadDefaultBus();
@@ -90,78 +89,110 @@
List<Element>
metadata,
String
wsdlDocumentLocation,
List<Element>
referenceParameters) {
+ QName portType = null;
+ if (serviceName != null && portName != null && wsdlDocumentLocation !=
null) {
+ Bus bus = BusFactory.getThreadDefaultBus();
+ WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
+ try {
+ Definition def =
wsdlManager.getDefinition(wsdlDocumentLocation);
+ portType =
def.getService(serviceName).getPort(portName.getLocalPart()).getBinding()
+ .getPortType().getQName();
+ } catch (Exception e) {
+ // do nothing
+ }
+ }
CachedOutputStream cos = new CachedOutputStream();
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(cos);
- final String wsaPrefix =
nsMan.getPrefixFromNS(JAXWSAConstants.NS_WSA);
try {
- //TODO: when serviceName/portName is null
+ // TODO: when serviceName/portName is null
if (serviceName == null && portName == null && address == null) {
- throw new IllegalStateException("Address in an EPR cannot be
null, "
- + " when serviceName or portName is null");
+ throw new IllegalStateException("Address in an EPR cannot be
null, "
+ + " when serviceName or
portName is null");
}
- writer.setPrefix(wsaPrefix, JAXWSAConstants.NS_WSA);
+ writer.setPrefix(JAXWSAConstants.WSA_PREFIX,
JAXWSAConstants.NS_WSA);
+ writer.writeStartElement(JAXWSAConstants.WSA_PREFIX,
JAXWSAConstants.WSA_ERF_NAME,
+ JAXWSAConstants.NS_WSA);
+ writer.writeNamespace(JAXWSAConstants.WSA_PREFIX,
JAXWSAConstants.NS_WSA);
- String portNamePrefix = null;
- String serviceNamePrefix = null;
- if (serviceName != null) {
- serviceNamePrefix = (serviceName.getPrefix() == null ||
serviceName.getPrefix()
- .length() == 0) ? "ns" : serviceName.getPrefix();
- }
- writer.writeStartElement(wsaPrefix, "EndpointReference",
JAXWSAConstants.NS_WSA);
- writer.writeNamespace(wsaPrefix, JAXWSAConstants.NS_WSA);
- if (serviceName != null) {
- writer.writeNamespace(serviceNamePrefix,
serviceName.getNamespaceURI());
- }
- if (portName != null &&
!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(wsaPrefix, "Address",
JAXWSAConstants.NS_WSA);
+ writer.writeStartElement(JAXWSAConstants.WSA_PREFIX,
JAXWSAConstants.WSA_ADDRESS_NAME,
+ JAXWSAConstants.NS_WSA);
address = address == null ? "" : address;
writer.writeCharacters(address);
-
writer.writeEndElement();
-
-
- if (portName != null) {
- writer.writeStartElement(wsaPrefix, "portName",
JAXWSAConstants.NS_WSA);
- writer.writeCharacters(portNamePrefix + ":" +
portName.getLocalPart());
+
+ if (referenceParameters != null) {
+ writer
+ .writeStartElement(JAXWSAConstants.WSA_PREFIX,
+
JAXWSAConstants.WSA_REFERENCEPARAMETERS_NAME, JAXWSAConstants.NS_WSA);
+ for (Element ele : referenceParameters) {
+ StaxUtils.writeElement(ele, writer, true);
+ }
writer.writeEndElement();
}
+
+ writer.writeStartElement(JAXWSAConstants.WSA_PREFIX,
JAXWSAConstants.WSA_METADATA_NAME,
+ JAXWSAConstants.NS_WSA);
+ writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX,
JAXWSAConstants.NS_WSAW);
+
+ if (portType != null) {
+ writer.writeStartElement(JAXWSAConstants.WSAW_PREFIX,
JAXWSAConstants.WSAW_INTERFACE_NAME,
+ JAXWSAConstants.NS_WSAW);
+ String portTypePrefix = portType.getPrefix();
+ if (portTypePrefix == null || portTypePrefix.equals("")) {
+ portTypePrefix = "ns1";
+ }
+ writer.writeNamespace(portTypePrefix,
portType.getNamespaceURI());
+ writer.writeCharacters(portTypePrefix + ":" +
portType.getLocalPart());
+ writer.writeEndElement();
+ }
+
+ String serviceNamePrefix = null;
+
if (serviceName != null) {
- writer.writeStartElement(wsaPrefix, "ServiceName",
JAXWSAConstants.NS_WSA);
+ serviceNamePrefix = (serviceName.getPrefix() == null ||
serviceName.getPrefix().length() == 0)
+ ? "ns2" : serviceName.getPrefix();
+
+ writer.writeStartElement(JAXWSAConstants.WSAW_PREFIX,
JAXWSAConstants.WSAW_SERVICENAME_NAME,
+ JAXWSAConstants.NS_WSAW);
+
+ if (portName != null) {
+ writer.writeAttribute(JAXWSAConstants.WSAW_ENDPOINT_NAME,
portName.getLocalPart());
+ }
+ writer.writeNamespace(serviceNamePrefix,
serviceName.getNamespaceURI());
writer.writeCharacters(serviceNamePrefix + ":" +
serviceName.getLocalPart());
+
writer.writeEndElement();
}
- if (referenceParameters != null) {
- for (Element referenceParameter : referenceParameters) {
- StaxUtils.writeElement(referenceParameter, writer, true);
+ if (wsdlDocumentLocation != null) {
+
+ writer.writeStartElement(WSDLConstants.WSDL_PREFIX,
WSDLConstants.QNAME_DEFINITIONS
+ .getLocalPart(), WSDLConstants.NS_WSDL11);
+ writer.writeNamespace(WSDLConstants.WSDL_PREFIX,
WSDLConstants.NS_WSDL11);
+ writer.writeStartElement(WSDLConstants.WSDL_PREFIX,
+
WSDLConstants.QNAME_IMPORT.getLocalPart(),
+
WSDLConstants.QNAME_IMPORT.getNamespaceURI());
+ if (serviceName != null) {
+ writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE,
serviceName.getNamespaceURI());
}
- }
-
+ writer.writeAttribute(WSDLConstants.ATTR_LOCATION,
wsdlDocumentLocation);
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
+
if (metadata != null) {
- for (Element meta : metadata) {
- StaxUtils.writeElement(meta, writer, true);
+ for (Element e : metadata) {
+ StaxUtils.writeElement(e, writer, true);
}
- }
-
- //TODO: Write wsdlDocumentLocation
-
+ }
+
+ writer.writeEndElement();
writer.writeEndElement();
writer.flush();
-
} catch (XMLStreamException e) {
- throw new WebServiceException(
- new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE",
LOG).toString(), e);
+ throw new WebServiceException(new
Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(),
+ e);
}
try {
@@ -169,11 +200,11 @@
return
(W3CEndpointReference)unmarshaller.unmarshal(cos.getInputStream());
} catch (JAXBException e) {
- throw new WebServiceException(
- new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE",
LOG).toString(), 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);
+ throw new WebServiceException(new
Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(),
+ e);
}
}
@@ -189,8 +220,8 @@
Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller();
return (EndpointReference)unmarshaller.unmarshal(eprInfoset);
} catch (JAXBException e) {
- throw new WebServiceException(
- new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE",
LOG).toString(), e);
+ throw new WebServiceException(new
Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(),
+ e);
}
}
Added:
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProverImplTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProverImplTest.java?rev=606906&view=auto
==============================================================================
---
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProverImplTest.java
(added)
+++
incubator/cxf/trunk/rt/frontend/jaxws/src/test/java/org/apache/cxf/jaxws/spi/ProverImplTest.java
Wed Dec 26 06:53:29 2007
@@ -0,0 +1,55 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.jaxws.spi;
+
+import javax.xml.namespace.QName;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+
+import org.apache.cxf.BusFactory;
+import org.junit.After;
+
+
+public class ProverImplTest extends org.junit.Assert {
+ @org.junit.Test
+ public void testCreateW3CEpr() throws Exception {
+ QName serviceName = new QName("http://cxf.apache.org", "ServiceName");
+ QName portName = new QName("http://cxf.apache.org", "PortName");
+ ProviderImpl impl = new ProviderImpl();
+ W3CEndpointReference w3Epr =
impl.createW3CEndpointReference("http://myaddress", serviceName,
+
portName, null, "wsdlLoc",
+ null);
+
+ java.io.StringWriter sw = new java.io.StringWriter();
+ StreamResult result = new StreamResult(sw);
+ w3Epr.writeTo(result);
+ String expected = "<wsdl:definitions";
+ assertTrue("Embeded wsdl element is not generated",
sw.toString().indexOf(expected) > -1);
+
+
+ }
+ @After
+ public void tearDown() {
+ BusFactory.setDefaultBus(null);
+ }
+
+
+
+}