You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2016/04/22 05:29:24 UTC
cxf git commit: CXF-6877:Have @SchemaValidation working on service
endpoint implementation class method
Repository: cxf
Updated Branches:
refs/heads/master fd5e32511 -> 90e94a51e
CXF-6877:Have @SchemaValidation working on service endpoint implementation class method
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/90e94a51
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/90e94a51
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/90e94a51
Branch: refs/heads/master
Commit: 90e94a51ee3b3adec741c9022465a83c2a5f7729
Parents: fd5e325
Author: Jim Ma <em...@apache.org>
Authored: Fri Apr 22 11:28:33 2016 +0800
Committer: Jim Ma <em...@apache.org>
Committed: Fri Apr 22 11:28:58 2016 +0800
----------------------------------------------------------------------
.../factory/AnnotationsFactoryBeanListener.java | 18 ++++++++++++--
.../ValidationClientServerTest.java | 25 ++++++++++++++++++++
.../schema_validation/ValidationServer.java | 14 +++++++++++
3 files changed, 55 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/90e94a51/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java b/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
index 0fcb914..8eb7d0e 100644
--- a/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
+++ b/core/src/main/java/org/apache/cxf/service/factory/AnnotationsFactoryBeanListener.java
@@ -123,7 +123,22 @@ public class AnnotationsFactoryBeanListener implements FactoryBeanListener {
docs.toArray(new WSDLDocumentation[docs.size()]));
}
addBindingOperationDocs(ep);
-
+ for (Method method : implCls.getMethods()) {
+ if (method.getAnnotation(SchemaValidation.class) != null) {
+ try {
+ Method interfaceMethod = cls.getMethod(method.getName(), method.getParameterTypes());
+ for (BindingOperationInfo bopInfo : ep.getBinding().getBindingInfo().getOperations()) {
+ if (interfaceMethod.equals(bopInfo.getOperationInfo()
+ .getProperty("operation.method"))) {
+ addSchemaValidationSupport(bopInfo.getOperationInfo(),
+ method.getAnnotation(SchemaValidation.class));
+ }
+ }
+ } catch (Exception e) {
+ // ignore this
+ }
+ }
+ }
break;
}
case SERVER_CREATED: {
@@ -156,7 +171,6 @@ public class AnnotationsFactoryBeanListener implements FactoryBeanListener {
if (col != null) {
addDocumentation(inf, WSDLDocumentation.Placement.PORT_TYPE_OPERATION, col.value());
}
-
SchemaValidation methodValidation = m.getAnnotation(SchemaValidation.class);
if (methodValidation != null) {
addSchemaValidationSupport(inf, methodValidation);
http://git-wip-us.apache.org/repos/asf/cxf/blob/90e94a51/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
index 3dfb0a9..8fe92bb 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationClientServerTest.java
@@ -98,6 +98,31 @@ public class ValidationClientServerTest extends AbstractBusClientServerTestBase
runSchemaValidationTest(validation);
((java.io.Closeable)validation).close();
}
+
+ @Test
+ public void testSchemaValidationServerForMethod() throws Exception {
+ SchemaValidation validation = createService(Boolean.FALSE, "SoapPortMethodValidate");
+ ComplexStruct complexStruct = new ComplexStruct();
+ complexStruct.setElem1("one");
+ complexStruct.setElem3(3);
+ try {
+ validation.setComplexStruct(complexStruct);
+ fail("Set ComplexStruct should have thrown ProtocolException");
+ } catch (WebServiceException e) {
+ String expected = "'{\"http://apache.org/schema_validation/types\":elem2}' is expected.";
+ assertTrue(e.getMessage(), e.getMessage().indexOf(expected) != -1);
+ }
+
+ SchemaValidation novlidation = createService(Boolean.FALSE, "SoapPort");
+ try {
+ novlidation.setComplexStruct(complexStruct);
+
+ } catch (WebServiceException e) {
+ fail("Exception is not expected :" + e);
+ }
+
+ }
+
@Test
public void testSchemaValidationClient() throws Exception {
SchemaValidation validation = createService(Boolean.TRUE, "SoapPort");
http://git-wip-us.apache.org/repos/asf/cxf/blob/90e94a51/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
----------------------------------------------------------------------
diff --git a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
index 5f2404d..dd6d3a8 100644
--- a/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
+++ b/systests/uncategorized/src/test/java/org/apache/cxf/systest/schema_validation/ValidationServer.java
@@ -42,6 +42,7 @@ import org.apache.cxf.annotations.SchemaValidation;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.staxutils.StaxUtils;
import org.apache.cxf.testutil.common.AbstractBusTestServerBase;
+import org.apache.schema_validation.types.ComplexStruct;
public class ValidationServer extends AbstractBusTestServerBase {
public static final String PORT = allocatePort(ValidationServer.class);
@@ -58,6 +59,7 @@ public class ValidationServer extends AbstractBusTestServerBase {
eps.add(Endpoint.publish(address + "/SoapPortValidate", new ValidatingSchemaValidationImpl()));
eps.add(Endpoint.publish(address + "/PProvider", new PayloadProvider()));
eps.add(Endpoint.publish(address + "/MProvider", new MessageProvider()));
+ eps.add(Endpoint.publish(address + "/SoapPortMethodValidate", new ValidatingSchemaValidationMethodImpl()));
}
public void tearDown() throws Exception {
@@ -76,6 +78,18 @@ public class ValidationServer extends AbstractBusTestServerBase {
}
+ @WebService(serviceName = "SchemaValidationService",
+ portName = "SoapPort",
+ endpointInterface = "org.apache.schema_validation.SchemaValidation",
+ targetNamespace = "http://apache.org/schema_validation",
+ wsdlLocation = "classpath:/wsdl/schema_validation.wsdl")
+ static class ValidatingSchemaValidationMethodImpl extends SchemaValidationImpl {
+ @SchemaValidation
+ public boolean setComplexStruct(ComplexStruct in) {
+ return true;
+ }
+ }
+
private static String getResponse(String v) {
if ("9999999999".equals(v)) {
return "<soap:Fault xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"