Author: mmao
Date: Tue Aug 28 01:25:17 2007
New Revision: 570340
URL: http://svn.apache.org/viewvc?rev=570340&view=rev
Log:
CXF-939 Non Unique Body validation on service model
* Turn on the validation by default on service model
* Fix the wrong wsdl in the testutils
Added:
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/Messages.properties
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/UniqueBodyValidator.java
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/resources/META-INF/service.validator.xml
incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/
incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/bug.wsdl
Modified:
incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/validator/ValidatorTest.java
Modified:
incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java?rev=570340&r1=570339&r2=570340&view=diff
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
(original)
+++
incubator/cxf/trunk/tools/wsdlto/core/src/main/java/org/apache/cxf/tools/wsdlto/WSDLToJavaContainer.java
Tue Aug 28 01:25:17 2007
@@ -215,9 +215,8 @@
for (ServiceInfo service : serviceList) {
context.put(ServiceInfo.class, service);
- if (context.optionSet(ToolConstants.CFG_VALIDATE_WSDL)) {
- validate(service);
- }
+
+ validate(service);
// Build the JavaModel from the ServiceModel
processor.setEnvironment(context);
Added:
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/Messages.properties?rev=570340&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/Messages.properties
(added)
+++
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/Messages.properties
Tue Aug 28 01:25:17 2007
@@ -0,0 +1 @@
+NON_UNIQUE_BODY = Non unique body parts! In a port, operations must have
unique operation signaure on the wire for successful dispatch. In port {0},
Operations \"{1}\" and \"{2}\" have the same request body block {3}
\ No newline at end of file
Added:
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/UniqueBodyValidator.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/UniqueBodyValidator.java?rev=570340&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/UniqueBodyValidator.java
(added)
+++
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/java/org/apache/cxf/tools/wsdlto/frontend/jaxws/validator/UniqueBodyValidator.java
Tue Aug 28 01:25:17 2007
@@ -0,0 +1,92 @@
+/**
+ * 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.tools.wsdlto.frontend.jaxws.validator;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+import javax.xml.namespace.QName;
+
+import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.service.model.BindingInfo;
+import org.apache.cxf.service.model.BindingOperationInfo;
+import org.apache.cxf.service.model.EndpointInfo;
+import org.apache.cxf.service.model.MessagePartInfo;
+import org.apache.cxf.service.model.OperationInfo;
+import org.apache.cxf.service.model.ServiceInfo;
+import org.apache.cxf.tools.validator.ServiceValidator;
+
+public class UniqueBodyValidator extends ServiceValidator {
+ public static final Logger LOG =
LogUtils.getL7dLogger(UniqueBodyValidator.class);
+
+ public UniqueBodyValidator() {
+ }
+
+ public UniqueBodyValidator(ServiceInfo s) {
+ this.service = s;
+ }
+
+ @Override
+ public boolean isValid() {
+ return checkUniqueBody();
+ }
+
+ private boolean checkUniqueBody() {
+ Collection<EndpointInfo> endpoints = service.getEndpoints();
+ if (endpoints != null) {
+ for (EndpointInfo endpoint : endpoints) {
+ if (!isValidEndpoint(endpoint)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean isValidEndpoint(EndpointInfo endpoint) {
+ BindingInfo binding = endpoint.getBinding();
+ Map<QName, QName> uniqueNames = new HashMap<QName, QName>();
+
+ Collection<BindingOperationInfo> bos = binding.getOperations();
+ for (BindingOperationInfo bo : bos) {
+ OperationInfo op =
binding.getInterface().getOperation(bo.getName());
+ if (op.getInput() != null
+ && op.getInput().getMessageParts().size() == 1) {
+ MessagePartInfo part =
op.getInput().getMessageParts().iterator().next();
+ if (part.getElementQName() == null) {
+ continue;
+ }
+ QName mName = part.getElementQName();
+ QName opName = uniqueNames.get(mName);
+ if (opName != null) {
+ Message msg = new Message("NON_UNIQUE_BODY", LOG,
+ endpoint.getName(),
op.getName(), opName, mName);
+ addErrorMessage(msg.toString());
+ return false;
+ } else {
+ uniqueNames.put(mName, op.getName());
+ }
+ }
+ }
+ return true;
+ }
+}
Added:
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/resources/META-INF/service.validator.xml
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/resources/META-INF/service.validator.xml?rev=570340&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/resources/META-INF/service.validator.xml
(added)
+++
incubator/cxf/trunk/tools/wsdlto/frontend/jaxws/src/main/resources/META-INF/service.validator.xml
Tue Aug 28 01:25:17 2007
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
+<properties>
+ <entry
key="UniqueBodyValidator">org.apache.cxf.tools.wsdlto.frontend.jaxws.validator.UniqueBodyValidator</entry>
+</properties>
Modified:
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java?rev=570340&r1=570339&r2=570340&view=diff
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
(original)
+++
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/jaxws/CodeGenBugTest.java
Tue Aug 28 01:25:17 2007
@@ -23,10 +23,11 @@
import java.io.File;
import java.io.FileInputStream;
import java.lang.reflect.Modifier;
-
import javax.jws.WebService;
+import javax.xml.namespace.QName;
import javax.xml.ws.WebServiceClient;
+import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.tools.common.ProcessorTestBase;
import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.util.AnnotationUtil;
@@ -35,6 +36,7 @@
import org.apache.cxf.tools.wsdlto.core.FrontEndProfile;
import org.apache.cxf.tools.wsdlto.core.PluginLoader;
import org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer;
+import
org.apache.cxf.tools.wsdlto.frontend.jaxws.validator.UniqueBodyValidator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -626,6 +628,21 @@
assertTrue(str.indexOf("org.apache.hello_world_soap_http.Greeter_SoapPortTest1_Server")
> -1);
assertTrue(str.indexOf("org.apache.hello_world_soap_http.Greeter_SoapPortTest2_Server")
> -1);
}
-
-
-}
\ No newline at end of file
+
+ @Test
+ public void testNonUniqueBody() throws Exception {
+ try {
+ env.put(ToolConstants.CFG_WSDLURL,
+ getLocation("/wsdl2java_wsdl/cxf939/bug.wsdl"));
+ // env.put(ToolConstants.CFG_VALIDATE_WSDL,
ToolConstants.CFG_VALIDATE_WSDL);
+ processor.setContext(env);
+ processor.execute();
+ } catch (Exception e) {
+ String ns = "http://bugs.cxf/services/bug1";
+ QName bug1 = new QName(ns, "myBug1");
+ QName bug2 = new QName(ns, "myBug2");
+ Message msg = new Message("NON_UNIQUE_BODY",
UniqueBodyValidator.LOG, bug1, bug1, bug2, bug1);
+ assertEquals(msg.toString().trim(), e.getMessage().trim());
+ }
+ }
+}
Modified:
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/validator/ValidatorTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/validator/ValidatorTest.java?rev=570340&r1=570339&r2=570340&view=diff
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/validator/ValidatorTest.java
(original)
+++
incubator/cxf/trunk/tools/wsdlto/test/src/test/java/org/apache/cxf/tools/wsdlto/validator/ValidatorTest.java
Tue Aug 28 01:25:17 2007
@@ -27,6 +27,7 @@
import org.apache.cxf.tools.wsdlto.frontend.jaxws.JAXWSContainer;
import org.junit.Before;
import org.junit.Test;
+
public class ValidatorTest extends ProcessorTestBase {
private WSDLToJavaContainer processor;
@@ -38,7 +39,6 @@
env.put(FrontEndProfile.class,
PluginLoader.getInstance().getFrontEndProfile("jaxws"));
env.put(DataBindingProfile.class,
PluginLoader.getInstance().getDataBindingProfile("jaxb"));
env.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
- //env.put(ToolConstants.CFG_VALIDATE_WSDL,
ToolConstants.CFG_VALIDATE_WSDL);
}
@Test
@@ -47,14 +47,13 @@
env.put(ToolConstants.CFG_WSDLURL,
getLocation("/wsdl2java_wsdl/xml_format_root.wsdl"));
processor.setContext(env);
- processor.execute();
-
- // TODO 1: check the exception here:
- //
Binding(Greeter_XMLBinding):BindingOperation({http://apache.org/xml_http_bare}sayHi)-input:
- // missing xml format body element
-
- // TODO 2: turn the validate on
-
- // TODO 3: change the jaxwscontainer to jaxws_wsdl_to_java_processor,
so we can catch the exception
+ try {
+ processor.execute();
+ fail("xml_format_root.wsdl is not a valid wsdl, should throws
exception here");
+ } catch (Exception e) {
+ String expected = "Binding(Greeter_XMLBinding):BindingOperation"
+ + "({http://apache.org/xml_http_bare}sayHi)-input: missing xml
format body element";
+ assertEquals(expected, e.getMessage().trim());
+ }
}
}
Added:
incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/bug.wsdl
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/bug.wsdl?rev=570340&view=auto
==============================================================================
---
incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/bug.wsdl
(added)
+++
incubator/cxf/trunk/tools/wsdlto/test/src/test/resources/wsdl2java_wsdl/cxf939/bug.wsdl
Tue Aug 28 01:25:17 2007
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<wsdl:definitions xmlns:tns="http://bugs.cxf/services/bug1"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ targetNamespace="http://bugs.cxf/services/bug1" name="bug1">
+
+ <!-- customizations with global scope below it shows the default
customizations -->
+ <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
+ <jaxws:enableWrapperStyle>true</jaxws:enableWrapperStyle>
+ <jaxws:enableAsyncMapping>false</jaxws:enableAsyncMapping>
+ </jaxws:bindings>
+
+ <wsdl:types>
+ <schema xmlns="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified"
+ attributeFormDefault="qualified"
+ targetNamespace="http://bugs.cxf/services/bug1">
+
+ <xsd:complexType name="requestDataType">
+ <xsd:sequence>
+ <xsd:element name="myInputString" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <xsd:complexType name="responseDataType">
+ <xsd:sequence>
+ <xsd:element name="myOutputString" type="xsd:string"/>
+ </xsd:sequence>
+ </xsd:complexType>
+
+ <element name="myBug1" type="tns:requestDataType"/>
+ <element name="myBug1Response" type="tns:responseDataType"/>
+ </schema>
+ </wsdl:types>
+
+ <wsdl:message name="myBug1RequestMessage">
+ <wsdl:part name="parameters" element="tns:myBug1"/>
+ </wsdl:message>
+ <wsdl:message name="myBug1ResponseMessage">
+ <wsdl:part name="parameters" element="tns:myBug1Response"/>
+ </wsdl:message>
+
+ <wsdl:portType name="myBug1Port">
+ <wsdl:operation name="myBug1">
+ <wsdl:input message="tns:myBug1RequestMessage"/>
+ <wsdl:output message="tns:myBug1ResponseMessage"/>
+ </wsdl:operation>
+ <wsdl:operation name="myBug2">
+ <wsdl:input message="tns:myBug1RequestMessage"/>
+ <wsdl:output message="tns:myBug1ResponseMessage"/>
+ </wsdl:operation>
+ </wsdl:portType>
+
+ <wsdl:binding name="myBug1PortSoapBinding" type="tns:myBug1Port">
+ <soap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
+
+ <wsdl:operation name="myBug1">
+ <soap:operation style="document"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+
+ <wsdl:operation name="myBug2">
+ <soap:operation style="document"/>
+ <wsdl:input>
+ <soap:body use="literal"/>
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal"/>
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="myBug1Service">
+ <wsdl:port name="myBug1" binding="tns:myBug1PortSoapBinding">
+ <soap:address location="http://REPLACE_WITH_HOST_INFO/myBug1"/>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file