cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e..@apache.org
Subject cxf git commit: CXF-6877:Have @SchemaValidation working on service endpoint implementation class method
Date Fri, 22 Apr 2016 03:30:36 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 9dfa5cf3b -> 671666f51


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/671666f5
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/671666f5
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/671666f5

Branch: refs/heads/3.1.x-fixes
Commit: 671666f51ccf084c7915134846183a188b274a6c
Parents: 9dfa5cf
Author: Jim Ma <ema@apache.org>
Authored: Fri Apr 22 11:28:33 2016 +0800
Committer: Jim Ma <ema@apache.org>
Committed: Fri Apr 22 11:30:09 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/671666f5/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/671666f5/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/671666f5/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/\">"


Mime
View raw message