Skip to content

Commit

Permalink
CXF-6877:Have @SchemaValidation working on service endpoint implement…
Browse files Browse the repository at this point in the history
…ation class method
  • Loading branch information
jimma committed Apr 22, 2016
1 parent 9dfa5cf commit 671666f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
Expand Up @@ -123,7 +123,22 @@ public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object...
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: {
Expand Down Expand Up @@ -156,7 +171,6 @@ public void handleEvent(Event ev, AbstractServiceFactoryBean factory, Object...
if (col != null) {
addDocumentation(inf, WSDLDocumentation.Placement.PORT_TYPE_OPERATION, col.value());
}

SchemaValidation methodValidation = m.getAnnotation(SchemaValidation.class);
if (methodValidation != null) {
addSchemaValidationSupport(inf, methodValidation);
Expand Down
Expand Up @@ -98,6 +98,31 @@ public void testSchemaValidationServer() throws Exception {
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");
Expand Down
Expand Up @@ -42,6 +42,7 @@
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);
Expand All @@ -58,6 +59,7 @@ protected void run() {
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 {
Expand All @@ -76,6 +78,18 @@ static class ValidatingSchemaValidationImpl extends SchemaValidationImpl {

}

@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/\">"
Expand Down

0 comments on commit 671666f

Please sign in to comment.