Search in sources :

Example 1 with SchemaValidationPolicy

use of org.talend.esb.policy.schemavalidate.SchemaValidationPolicy in project tesb-rt-se by Talend.

the class WSDLSchemaPolicyTest method testWSLDConsumerResponseNotValid.

@Test(expected = SOAPFaultException.class)
public void testWSLDConsumerResponseNotValid() throws Exception {
    SchemaValidationPolicy policy = new SchemaValidationPolicy();
    policy.setAppliesToType(SchemaValidationPolicy.AppliesToType.valueOf("consumer"));
    policy.setMessageType(SchemaValidationPolicy.MessageType.valueOf("response"));
    policy.setValidationType(ValidationType.valueOf("WSDLSchema"));
    customPolicyTest(policy, NOT_VALID_CUSTOMER_NAME);
}
Also used : SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) Test(org.junit.Test)

Example 2 with SchemaValidationPolicy

use of org.talend.esb.policy.schemavalidate.SchemaValidationPolicy in project tesb-rt-se by Talend.

the class AbstractPolicyTest method customPolicyTest.

public void customPolicyTest(SchemaValidationPolicy assertion, String customerName) throws Exception {
    clientCtxt = new ClassPathXmlApplicationContext("classpath:spring/client/policy/client-defaultApplicationContext.xml");
    ClientProxyFactoryBean clientFactory = (ClientProxyFactoryBean) clientCtxt.getBean(ClientProxyFactoryBean.class);
    Policy policy = new Policy();
    policy.addAssertion(assertion);
    clientFactory.getProperties().put(PolicyConstants.POLICY_OVERRIDE, policy);
    CustomerServiceTester tester = new CustomerServiceTester();
    tester.setCustomerService(clientFactory.create(CustomerService.class));
    tester.testCustomerService(customerName);
    clientCtxt.close();
}
Also used : SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) Policy(org.apache.neethi.Policy) CustomerService(com.example.customerservice.CustomerService) CustomerServiceTester(org.talend.esb.policy.schemavalidate.testservice.client.CustomerServiceTester) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClientProxyFactoryBean(org.apache.cxf.frontend.ClientProxyFactoryBean)

Example 3 with SchemaValidationPolicy

use of org.talend.esb.policy.schemavalidate.SchemaValidationPolicy in project tesb-rt-se by Talend.

the class CustomSchemaPolicyTest method testLocalCustomSchemaNotExists.

@Test(expected = SOAPFaultException.class)
public void testLocalCustomSchemaNotExists() throws Exception {
    SchemaValidationPolicy policy = new SchemaValidationPolicy();
    policy.setAppliesToType(SchemaValidationPolicy.AppliesToType.valueOf("consumer"));
    policy.setMessageType(SchemaValidationPolicy.MessageType.valueOf("response"));
    policy.setValidationType(ValidationType.valueOf("CustomSchema"));
    policy.setCustomSchemaPath("schema/DoesNotExist.xsd");
    customPolicyTest(policy, VALID_CUSTOMER_NAME);
}
Also used : SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) Test(org.junit.Test)

Example 4 with SchemaValidationPolicy

use of org.talend.esb.policy.schemavalidate.SchemaValidationPolicy in project tesb-rt-se by Talend.

the class WSDLSchemaPolicyTest method testWSLDConsumerResponseValid.

@Test
public void testWSLDConsumerResponseValid() throws Exception {
    SchemaValidationPolicy policy = new SchemaValidationPolicy();
    policy.setAppliesToType(SchemaValidationPolicy.AppliesToType.valueOf("consumer"));
    policy.setMessageType(SchemaValidationPolicy.MessageType.valueOf("response"));
    policy.setValidationType(ValidationType.valueOf("WSDLSchema"));
    customPolicyTest(policy, VALID_CUSTOMER_NAME);
}
Also used : SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) Test(org.junit.Test)

Example 5 with SchemaValidationPolicy

use of org.talend.esb.policy.schemavalidate.SchemaValidationPolicy in project tesb-rt-se by Talend.

the class SchemaValidationPolicyAbstractInterceptor method handleMessageWithAssertionInfo.

protected void handleMessageWithAssertionInfo(Message message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    Collection<AssertionInfo> ais = aim.get(SchemaValidationPolicyBuilder.SCHEMA_VALIDATION);
    if (null == ais) {
        return;
    }
    for (AssertionInfo ai : ais) {
        if (ai.getAssertion() instanceof SchemaValidationPolicy) {
            SchemaValidationPolicy vPolicy = (SchemaValidationPolicy) ai.getAssertion();
            ValidationType vldType = vPolicy.getValidationType();
            AppliesToType appliesToType = vPolicy.getApplyToType();
            MessageType msgType = vPolicy.getMessageType();
            String customSchemaPath = vPolicy.getCustomSchemaPath();
            if (vldType != ValidationType.WSDLSchema) {
                ai.setAsserted(true);
            }
            if (shouldSchemaValidate(message, msgType, appliesToType)) {
                if (vldType == ValidationType.CustomSchema) {
                    // load custom schema from external source
                    try {
                        loadCustomSchema(message, customSchemaPath, this.getClass());
                    } catch (IOException ex) {
                        throw new RuntimeException("Can not load custom schema", ex);
                    }
                }
                // do schema validation by setting value to
                // "schema-validation-enabled" property
                validateBySettingProperty(message);
            }
            ai.setAsserted(true);
        }
        ai.setAsserted(true);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) SchemaValidationPolicy(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy) AppliesToType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.AppliesToType) ValidationType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.ValidationType) IOException(java.io.IOException) MessageType(org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.MessageType) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Aggregations

SchemaValidationPolicy (org.talend.esb.policy.schemavalidate.SchemaValidationPolicy)7 Test (org.junit.Test)5 CustomerService (com.example.customerservice.CustomerService)1 IOException (java.io.IOException)1 ClientProxyFactoryBean (org.apache.cxf.frontend.ClientProxyFactoryBean)1 AssertionInfo (org.apache.cxf.ws.policy.AssertionInfo)1 AssertionInfoMap (org.apache.cxf.ws.policy.AssertionInfoMap)1 Policy (org.apache.neethi.Policy)1 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)1 AppliesToType (org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.AppliesToType)1 MessageType (org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.MessageType)1 ValidationType (org.talend.esb.policy.schemavalidate.SchemaValidationPolicy.ValidationType)1 CustomerServiceTester (org.talend.esb.policy.schemavalidate.testservice.client.CustomerServiceTester)1