Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B0B11F453 for ; Fri, 25 Apr 2014 17:30:00 +0000 (UTC) Received: (qmail 5359 invoked by uid 500); 25 Apr 2014 17:29:55 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 5278 invoked by uid 500); 25 Apr 2014 17:29:55 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 4978 invoked by uid 99); 25 Apr 2014 17:29:54 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 Apr 2014 17:29:54 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0DBA4951D39; Fri, 25 Apr 2014 17:29:54 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: ashakirin@apache.org To: commits@cxf.apache.org Message-Id: <6670134b99034dcbb56e6e14a28dee05@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Added CXF-5685: Extended support for wsdl11external WS-PolicyAttachments references Date: Fri, 25 Apr 2014 17:29:54 +0000 (UTC) Repository: cxf Updated Branches: refs/heads/2.7.x-fixes 6c60b1631 -> e24fef563 Added CXF-5685: Extended support for wsdl11external WS-PolicyAttachments references Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/e24fef56 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/e24fef56 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/e24fef56 Branch: refs/heads/2.7.x-fixes Commit: e24fef56395195f75eff1e2076a0e5131f088cc9 Parents: 6c60b16 Author: Andrei Shakirin Authored: Fri Apr 25 18:55:51 2014 +0200 Committer: Andrei Shakirin Committed: Fri Apr 25 18:59:54 2014 +0200 ---------------------------------------------------------------------- .../external/URIDomainExpression.java | 385 +++++++++++++++++++ .../external/URIDomainExpressionBuilder.java | 46 +++ .../external/URIDomainExpressionTest.java | 263 +++++++++++++ ...ssingPolicyExternalAttachmentWsdl11Test.java | 159 ++++++++ .../systest/ws/policy/addr-external-wsdl11.xml | 35 ++ .../cxf/systest/ws/policy/addr-wsdl11.xml | 31 ++ .../resources/META-INF/cxf/bus-extensions.txt | 1 + 7 files changed, 920 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpression.java ---------------------------------------------------------------------- diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpression.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpression.java new file mode 100644 index 0000000..1c2a412 --- /dev/null +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpression.java @@ -0,0 +1,385 @@ +/** + * 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.ws.policy.attachment.external; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.apache.cxf.service.model.BindingFaultInfo; +import org.apache.cxf.service.model.BindingMessageInfo; +import org.apache.cxf.service.model.BindingOperationInfo; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.service.model.InterfaceInfo; +import org.apache.cxf.service.model.MessageInfo.Type; +import org.apache.cxf.service.model.ServiceInfo; + +public class URIDomainExpression implements DomainExpression { + + private final Wsdl11XPointer wsdl11XPointer; + + public URIDomainExpression(final String uriContext) { + wsdl11XPointer = new Wsdl11XPointer(uriContext); + } + + @Override + public boolean appliesTo(ServiceInfo si) { + if (si == null) { + return false; + } + if (wsdl11XPointer.matchesWsdl(si.getTargetNamespace())) { + return true; + } + if ((si.getName() != null) + && wsdl11XPointer.matchesService(si.getTargetNamespace(), si.getName().getLocalPart())) { + return true; + } + if ((si.getInterface() != null) && (si.getInterface().getName() != null) + && wsdl11XPointer.matchesPortType(si.getTargetNamespace(), + si.getInterface().getName().getLocalPart())) { + return true; + } + return false; + } + + @Override + public boolean appliesTo(EndpointInfo ei) { + if (ei == null) { + return false; + } + if ((ei.getService() != null) && (ei.getService().getName() != null) && (ei.getName() != null) + && wsdl11XPointer.matchesPort(ei.getService().getTargetNamespace(), + ei.getService().getName().getLocalPart(), + ei.getName().getLocalPart())) { + return true; + } + return false; + } + + @Override + public boolean appliesTo(BindingOperationInfo boi) { + if (boi == null) { + return false; + } + if ((boi.getBinding() != null) && (boi.getBinding().getName() != null) + && wsdl11XPointer.matchesBinding( + boi.getBinding().getName().getNamespaceURI(), + boi.getBinding().getName().getLocalPart())) { + return true; + } + if ((boi.getName() != null) && (boi.getBinding() != null) && (boi.getBinding().getName() != null) + && wsdl11XPointer.matchesBindingOperation( + boi.getBinding().getName().getNamespaceURI(), + boi.getBinding().getName().getLocalPart(), + boi.getName().getLocalPart())) { + return true; + } + if ((boi.getOperationInfo() != null) && (boi.getOperationInfo().getInterface() != null) + && (boi.getOperationInfo().getInterface().getName() != null) && (boi.getOperationInfo().getName() != null) + && wsdl11XPointer.matchesPortTypeOperation( + boi.getOperationInfo().getInterface().getName().getNamespaceURI(), + boi.getOperationInfo().getInterface().getName().getLocalPart(), + boi.getOperationInfo().getName().getLocalPart())) { + return true; + } + return false; + } + + @Override + public boolean appliesTo(BindingMessageInfo bmi) { + if (bmi == null) { + return false; + } + if ((bmi.getMessageInfo() != null) && (bmi.getMessageInfo().getName() != null) + && wsdl11XPointer.matchesMessage( + bmi.getMessageInfo().getName().getNamespaceURI(), + bmi.getMessageInfo().getName().getLocalPart())) { + return true; + } + + if (checkBindingOperationInOut(bmi)) { + return true; + } + + if (checkPortTypeOperationInOut(bmi)) { + return true; + } + return false; + } + + + @Override + public boolean appliesTo(BindingFaultInfo bfi) { + if ((bfi == null) || (bfi.getFaultInfo() == null) || (bfi.getBindingOperation() == null)) { + return false; + } + + if (checkBindingOperationFault(bfi)) { + return true; + } + + if (checkPortTypeOperationFault(bfi)) { + return true; + } + return false; + } + + private boolean checkBindingOperationInOut(BindingMessageInfo bmi) { + if ((bmi.getMessageInfo() != null) && (bmi.getMessageInfo().getName() != null) + && (bmi.getBindingOperation() != null) && (bmi.getBindingOperation().getName() != null) + && (bmi.getBindingOperation().getBinding() != null) + && (bmi.getBindingOperation().getBinding().getName() != null)) { + if ((Type.INPUT == bmi.getMessageInfo().getType()) + && wsdl11XPointer.matchesBindingOperationInput( + bmi.getMessageInfo().getName().getNamespaceURI(), + bmi.getBindingOperation().getBinding().getName().getLocalPart(), + bmi.getBindingOperation().getName().getLocalPart())) { + return true; + } + if ((Type.OUTPUT == bmi.getMessageInfo().getType()) + && wsdl11XPointer.matchesBindingOperationOutput( + bmi.getMessageInfo().getName().getNamespaceURI(), + bmi.getBindingOperation().getBinding().getName().getLocalPart(), + bmi.getBindingOperation().getName().getLocalPart())) { + return true; + } + } + return false; + } + + private boolean checkPortTypeOperationInOut(BindingMessageInfo bmi) { + InterfaceInfo ini = null; + if ((bmi.getBindingOperation() != null) && (bmi.getBindingOperation().getOperationInfo() != null)) { + ini = bmi.getBindingOperation().getOperationInfo().getInterface(); + } + + if ((ini != null) && (ini.getName() != null) + && (bmi.getMessageInfo() != null) + && (bmi.getBindingOperation() != null) && (bmi.getBindingOperation().getName() != null)) { + if ((Type.INPUT == bmi.getMessageInfo().getType()) + && wsdl11XPointer.matchesPortTypeOperationInput( + ini.getName().getNamespaceURI(), + ini.getName().getLocalPart(), + bmi.getBindingOperation().getName().getLocalPart())) { + return true; + } + if ((Type.OUTPUT == bmi.getMessageInfo().getType()) + && wsdl11XPointer.matchesPortTypeOperationOutput( + ini.getName().getNamespaceURI(), + ini.getName().getLocalPart(), + bmi.getBindingOperation().getName().getLocalPart())) { + return true; + } + } + return false; + } + + private boolean checkPortTypeOperationFault(BindingFaultInfo bfi) { + InterfaceInfo ini = null; + if ((bfi.getBindingOperation() != null) && (bfi.getBindingOperation().getOperationInfo() != null)) { + ini = bfi.getBindingOperation().getOperationInfo().getInterface(); + } + + if ((ini != null) && (ini.getName() != null) + && (bfi.getBindingOperation().getName() != null) + && (bfi.getFaultInfo().getFaultName() != null) + && wsdl11XPointer.matchesPortTypeOperationFault( + ini.getName().getNamespaceURI(), + ini.getName().getLocalPart(), + bfi.getBindingOperation().getName().getLocalPart(), + bfi.getFaultInfo().getFaultName().getLocalPart())) { + return true; + } + return false; + } + + private boolean checkBindingOperationFault(BindingFaultInfo bfi) { + if ((bfi.getFaultInfo() != null) && (bfi.getFaultInfo().getFaultName() != null) + && (bfi.getBindingOperation().getName() != null) + && (bfi.getBindingOperation().getBinding() != null) + && (bfi.getBindingOperation().getBinding().getName() != null) + && wsdl11XPointer.matchesBindingOperationFault( + bfi.getFaultInfo().getFaultName().getNamespaceURI(), + bfi.getBindingOperation().getBinding().getName().getLocalPart(), + bfi.getBindingOperation().getName().getLocalPart(), + bfi.getFaultInfo().getFaultName().getLocalPart())) { + return true; + } + return false; + } + + public static class Wsdl11XPointer { + private static final String SINGLE_PATH = "\\(([^\\)]*)\\)$"; + private static final String DOUBLE_PATH = "\\(([^/]*)/([^\\)]*)\\)$"; + private static final String TRIPPLE_PATH = "\\(([^/]*)/([^/]*)/([^\\)]*)\\)$"; + + private static final Pattern PATTERN_DEFINITIONS + = Pattern.compile("^wsdl11.definitions\\(\\)$"); + + private static final Pattern PATTERN_PORT_TYPE + = Pattern.compile("^wsdl11.portType" + SINGLE_PATH); + + private static final Pattern PATTERN_PORT_TYPE_OPERATION + = Pattern.compile("^wsdl11.portTypeOperation" + DOUBLE_PATH); + + private static final Pattern PATTERN_PORT_TYPE_OPERATION_INPUT + = Pattern.compile("^wsdl11.portTypeOperation.input" + DOUBLE_PATH); + + private static final Pattern PATTERN_PORT_TYPE_OPERATION_OUTPUT + = Pattern.compile("^wsdl11.portTypeOperation.output" + DOUBLE_PATH); + + private static final Pattern PATTERN_PORT_TYPE_OPERATION_FAULT + = Pattern.compile("^wsdl11.portTypeOperation.fault" + TRIPPLE_PATH); + + private static final Pattern PATTERN_MESSAGE + = Pattern.compile("^wsdl11.message" + SINGLE_PATH); + + private static final Pattern PATTERN_MESSAGE_PART + = Pattern.compile("^wsdl11.messagePart" + DOUBLE_PATH); + + private static final Pattern PATTERN_SERVICE + = Pattern.compile("^wsdl11.service" + SINGLE_PATH); + + private static final Pattern PATTERN_PORT + = Pattern.compile("^wsdl11.port" + DOUBLE_PATH); + + private static final Pattern PATTERN_BINDING + = Pattern.compile("^wsdl11.binding" + SINGLE_PATH); + + private static final Pattern PATTERN_BINDING_OPERATION = + Pattern.compile("^wsdl11.bindingOperation" + DOUBLE_PATH); + + private static final Pattern PATTERN_BINDING_OPERATION_INPUT = + Pattern.compile("^wsdl11.bindingOperation.input" + DOUBLE_PATH); + + private static final Pattern PATTERN_BINDING_OPERATION_OUTPUT = + Pattern.compile("^wsdl11.bindingOperation.output" + DOUBLE_PATH); + + private static final Pattern PATTERN_BINDING_OPERATION_FAULT = + Pattern.compile("^wsdl11.bindingOperation.fault" + TRIPPLE_PATH); + + private final String targetNamespace; + private final String wsdl11Pointer; + + public Wsdl11XPointer(final String uriContext) { + if ((uriContext == null) || uriContext.isEmpty()) { + throw new IllegalArgumentException( + "External policy attachment URI element cannot be empty"); + } + int pos = uriContext.indexOf('#'); + if (pos != -1) { + targetNamespace = uriContext.substring(0, pos); + wsdl11Pointer = uriContext.substring(pos + 1); + } else { + targetNamespace = ""; + wsdl11Pointer = uriContext; + } + } + + boolean matchesWsdl(String wsdlTargetNamespace) { + Matcher matcher = PATTERN_DEFINITIONS.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher); + } + + boolean matchesPortType(String wsdlTargetNamespace, String portType) { + Matcher matcher = PATTERN_PORT_TYPE.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, portType); + } + + boolean matchesPortTypeOperation(String wsdlTargetNamespace, String portType, String operation) { + Matcher matcher = PATTERN_PORT_TYPE_OPERATION.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, portType, operation); + } + + boolean matchesPortTypeOperationInput(String wsdlTargetNamespace, String portType, String operation) { + Matcher matcher = PATTERN_PORT_TYPE_OPERATION_INPUT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, portType, operation); + } + + boolean matchesPortTypeOperationOutput(String wsdlTargetNamespace, String portType, String operation) { + Matcher matcher = PATTERN_PORT_TYPE_OPERATION_OUTPUT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, portType, operation); + } + + boolean matchesPortTypeOperationFault(String wsdlTargetNamespace, String portType, + String operation, String fault) { + Matcher matcher = PATTERN_PORT_TYPE_OPERATION_FAULT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, portType, operation, fault); + } + + boolean matchesMessage(String wsdlTargetNamespace, String message) { + Matcher matcher = PATTERN_MESSAGE.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, message); + } + + boolean matchesMessagePart(String wsdlTargetNamespace, String message, String part) { + Matcher matcher = PATTERN_MESSAGE_PART.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, message, part); + } + + boolean matchesService(String wsdlTargetNamespace, String service) { + Matcher matcher = PATTERN_SERVICE.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, service); + } + + boolean matchesPort(String wsdlTargetNamespace, String service, String port) { + Matcher matcher = PATTERN_PORT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, service, port); + } + + boolean matchesBinding(String wsdlTargetNamespace, String binding) { + Matcher matcher = PATTERN_BINDING.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, binding); + } + + boolean matchesBindingOperation(String wsdlTargetNamespace, String binding, String operation) { + Matcher matcher = PATTERN_BINDING_OPERATION.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, binding, operation); + } + + boolean matchesBindingOperationInput(String wsdlTargetNamespace, String binding, String operation) { + Matcher matcher = PATTERN_BINDING_OPERATION_INPUT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, binding, operation); + } + + boolean matchesBindingOperationOutput(String wsdlTargetNamespace, String binding, String operation) { + Matcher matcher = PATTERN_BINDING_OPERATION_OUTPUT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, binding, operation); + } + + boolean matchesBindingOperationFault(String wsdlTargetNamespace, String binding, + String operation, String fault) { + Matcher matcher = PATTERN_BINDING_OPERATION_FAULT.matcher(wsdl11Pointer); + return matches(wsdlTargetNamespace, matcher, binding, operation, fault); + } + + private boolean matches(String wsdlTargetNamespace, Matcher matcher, String... args) { + if (!targetNamespace.equals(wsdlTargetNamespace) || !matcher.matches()) { + return false; + } + for (int i = 0; i < args.length; i++) { + String matcherGroup = matcher.group(i + 1); + if ((matcherGroup == null) || (!matcherGroup.equals(args[i]))) { + return false; + } + } + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionBuilder.java ---------------------------------------------------------------------- diff --git a/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionBuilder.java b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionBuilder.java new file mode 100644 index 0000000..6bc5156 --- /dev/null +++ b/rt/ws/policy/src/main/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionBuilder.java @@ -0,0 +1,46 @@ +/** + * 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.ws.policy.attachment.external; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Element; + +public class URIDomainExpressionBuilder implements DomainExpressionBuilder { + private static final Collection SUPPORTED_TYPES = Collections.unmodifiableList( + Arrays.asList(new QName[] { + new QName("http://www.w3.org/ns/ws-policy", "URI"), + new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "URI") + })); + + @Override + public DomainExpression build(Element paramElement) { + return new URIDomainExpression(paramElement.getTextContent()); + } + + @Override + public Collection getDomainExpressionTypes() { + return SUPPORTED_TYPES; + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java ---------------------------------------------------------------------- diff --git a/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java new file mode 100644 index 0000000..5395de3 --- /dev/null +++ b/rt/ws/policy/src/test/java/org/apache/cxf/ws/policy/attachment/external/URIDomainExpressionTest.java @@ -0,0 +1,263 @@ +/** + * 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.ws.policy.attachment.external; + +import javax.xml.namespace.QName; + +import org.apache.cxf.service.model.BindingFaultInfo; +import org.apache.cxf.service.model.BindingInfo; +import org.apache.cxf.service.model.BindingMessageInfo; +import org.apache.cxf.service.model.BindingOperationInfo; +import org.apache.cxf.service.model.EndpointInfo; +import org.apache.cxf.service.model.FaultInfo; +import org.apache.cxf.service.model.InterfaceInfo; +import org.apache.cxf.service.model.MessageInfo; +import org.apache.cxf.service.model.MessageInfo.Type; +import org.apache.cxf.service.model.OperationInfo; +import org.apache.cxf.service.model.ServiceInfo; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class URIDomainExpressionTest { + + private static final String TARGET_NAMESPACE = "http://org.apache.cxf/targetNamespace"; + private static final String SERVICE_NAME = "testService"; + private static final QName SERVICE_QNAME = new QName(TARGET_NAMESPACE, SERVICE_NAME); + + private static final String INTERFACE_NAME = "testPortType"; + private static final QName INTERFACE_QNAME = new QName(TARGET_NAMESPACE, INTERFACE_NAME); + + private static final String PORT_NAME = "testPort"; + private static final QName PORT_QNAME = new QName(TARGET_NAMESPACE, PORT_NAME); + + private static final String OPERATION_NAME = "testOperation"; + private static final QName OPERATION_QNAME = new QName(TARGET_NAMESPACE, OPERATION_NAME); + + private static final String BINDING_NAME = "testBinding"; + private static final QName BINDING_QNAME = new QName(TARGET_NAMESPACE, BINDING_NAME); + + private static final String MESSAGE_NAME = "testBinding"; + private static final QName MESSAGE_QNAME = new QName(TARGET_NAMESPACE, MESSAGE_NAME); + + private static final String FAULT_NAME = "testFault"; + private static final QName FAULT_QNAME = new QName(TARGET_NAMESPACE, FAULT_NAME); + + private IMocksControl control; + + private ServiceInfo si; + private EndpointInfo ei; + private BindingOperationInfo boi; + private BindingMessageInfo bmi; + private BindingFaultInfo bfi; + private MessageInfo mi; + + @Before + public void setUp() { + control = EasyMock.createNiceControl(); + } + + @Test + public void testServiceInfo() { + mockInfoObjects(); + + control.replay(); + + String expression = TARGET_NAMESPACE + "#wsdl11.definitions()"; + URIDomainExpression ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(si)); + + expression = TARGET_NAMESPACE + "#wsdl11.service(" + SERVICE_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(si)); + + expression = TARGET_NAMESPACE + "#wsdl11.portType(" + INTERFACE_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(si)); + + expression = TARGET_NAMESPACE + "#wsdl11.portType(" + INTERFACE_NAME + "wrong" + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(si)); + + expression = TARGET_NAMESPACE + "wrong" + "#wsdl11.portType(" + INTERFACE_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(si)); + + control.reset(); + } + + @Test + public void testEndpointInfo() { + mockInfoObjects(); + + control.replay(); + + String expression = TARGET_NAMESPACE + "#wsdl11.port(" + SERVICE_NAME + "/" + PORT_NAME + ")"; + URIDomainExpression ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(ei)); + + expression = TARGET_NAMESPACE + "#wsdl11.port(" + SERVICE_NAME + "/" + PORT_NAME + "wrong" + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(boi)); + + control.reset(); + } + + @Test + public void testBindingOperationInfo() { + mockInfoObjects(); + + control.replay(); + + String expression = TARGET_NAMESPACE + "#wsdl11.binding(" + BINDING_NAME + ")"; + URIDomainExpression ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(boi)); + + expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation(" + BINDING_NAME + "/" + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(boi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation(" + INTERFACE_NAME + "/" + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(boi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation(" + INTERFACE_NAME + "/" + + OPERATION_NAME + "wrong" + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(boi)); + + control.reset(); + } + + @Test + public void testBindingMessageInfo() { + mockInfoObjects(); + + control.replay(); + + String expression = TARGET_NAMESPACE + "#wsdl11.message(" + MESSAGE_NAME + ")"; + URIDomainExpression ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); + + expression = TARGET_NAMESPACE + "#wsdl11.message(" + MESSAGE_NAME + "wrong" + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(bmi)); + + control.reset(); + + mockInfoObjects(); + EasyMock.expect(mi.getType()).andReturn(Type.INPUT).anyTimes(); + control.replay(); + + expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.input(" + BINDING_NAME + "/" + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation.input(" + INTERFACE_NAME + "/" + + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); + + control.reset(); + + mockInfoObjects(); + EasyMock.expect(mi.getType()).andReturn(Type.OUTPUT).anyTimes(); + control.replay(); + + expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.output(" + BINDING_NAME + "/" + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation.output(" + INTERFACE_NAME + "/" + + OPERATION_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bmi)); + + control.reset(); + } + + @Test + public void testBindingOperationFault() { + mockInfoObjects(); + + control.replay(); + + String expression = TARGET_NAMESPACE + "#wsdl11.bindingOperation.fault(" + BINDING_NAME + + "/" + OPERATION_NAME + "/" + FAULT_NAME + ")"; + URIDomainExpression ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bfi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation.fault(" + INTERFACE_NAME + + "/" + OPERATION_NAME + "/" + FAULT_NAME + ")"; + ude = new URIDomainExpression(expression); + Assert.assertTrue("Expected true for expression: " + expression, ude.appliesTo(bfi)); + + expression = TARGET_NAMESPACE + "#wsdl11.portTypeOperation.fault(" + INTERFACE_NAME + + "/" + OPERATION_NAME + "/" + FAULT_NAME + "wrong" + ")"; + ude = new URIDomainExpression(expression); + Assert.assertFalse("Expected false for expression: " + expression, ude.appliesTo(bfi)); + + control.reset(); + } + + private void mockInfoObjects() { + si = control.createMock(ServiceInfo.class); + ei = control.createMock(EndpointInfo.class); + boi = control.createMock(BindingOperationInfo.class); + bmi = control.createMock(BindingMessageInfo.class); + bfi = control.createMock(BindingFaultInfo.class); + + InterfaceInfo ii = control.createMock(InterfaceInfo.class); + + EasyMock.expect(si.getTargetNamespace()).andReturn(TARGET_NAMESPACE).anyTimes(); + EasyMock.expect(si.getName()).andReturn(SERVICE_QNAME).anyTimes(); + EasyMock.expect(si.getInterface()).andReturn(ii).anyTimes(); + EasyMock.expect(ii.getName()).andReturn(INTERFACE_QNAME).anyTimes(); + + EasyMock.expect(ei.getName()).andReturn(PORT_QNAME).anyTimes(); + EasyMock.expect(ei.getService()).andReturn(si).anyTimes(); + + BindingInfo bi = control.createMock(BindingInfo.class); + OperationInfo oi = control.createMock(OperationInfo.class); + + EasyMock.expect(boi.getName()).andReturn(OPERATION_QNAME).anyTimes(); + EasyMock.expect(boi.getBinding()).andReturn(bi).anyTimes(); + EasyMock.expect(bi.getName()).andReturn(BINDING_QNAME).anyTimes(); + EasyMock.expect(boi.getOperationInfo()).andReturn(oi).anyTimes(); + EasyMock.expect(oi.getInterface()).andReturn(ii).anyTimes(); + EasyMock.expect(oi.getName()).andReturn(OPERATION_QNAME).anyTimes(); + + mi = control.createMock(MessageInfo.class); + + EasyMock.expect(bmi.getMessageInfo()).andReturn(mi).anyTimes(); + EasyMock.expect(mi.getName()).andReturn(MESSAGE_QNAME).anyTimes(); + EasyMock.expect(bmi.getBindingOperation()).andReturn(boi).anyTimes(); + + FaultInfo fi = control.createMock(FaultInfo.class); + + bfi = control.createMock(BindingFaultInfo.class); + EasyMock.expect(bfi.getBindingOperation()).andReturn(boi).anyTimes(); + EasyMock.expect(bfi.getFaultInfo()).andReturn(fi).anyTimes(); + EasyMock.expect(fi.getFaultName()).andReturn(FAULT_QNAME).anyTimes(); + + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyExternalAttachmentWsdl11Test.java ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyExternalAttachmentWsdl11Test.java b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyExternalAttachmentWsdl11Test.java new file mode 100644 index 0000000..b813f28 --- /dev/null +++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/AddressingPolicyExternalAttachmentWsdl11Test.java @@ -0,0 +1,159 @@ +/** + * 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.systest.ws.policy; + +import java.io.Closeable; +import java.util.logging.Logger; + +import javax.xml.ws.Endpoint; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.bus.spring.SpringBusFactory; +import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.greeter_control.BasicGreeterService; +import org.apache.cxf.greeter_control.Greeter; +import org.apache.cxf.greeter_control.PingMeFault; +import org.apache.cxf.helpers.FileUtils; +import org.apache.cxf.interceptor.LoggingInInterceptor; +import org.apache.cxf.interceptor.LoggingOutInterceptor; +import org.apache.cxf.systest.ws.util.ConnectionHelper; +import org.apache.cxf.testutil.common.AbstractBusClientServerTestBase; +import org.apache.cxf.testutil.common.AbstractBusTestServerBase; +import org.apache.cxf.testutil.common.TestUtil; + +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * Tests the use of the WS-Policy Framework to automatically engage WS-Addressing and + * WS-RM in response to Policies defined for the endpoint via an external policy attachment. + */ +public class AddressingPolicyExternalAttachmentWsdl11Test extends AbstractBusClientServerTestBase { + public static final String PORT = allocatePort(Server.class); + public static final String TEMPDIR = FileUtils.getDefaultTempDir().toURI().toString(); + + private static final Logger LOG = LogUtils.getLogger(AddressingPolicyExternalAttachmentWsdl11Test.class); + + public static class Server extends AbstractBusTestServerBase { + String tmpDir = TEMPDIR; + Endpoint ep; + public Server() { + } + public Server(String dir) { + tmpDir = dir; + } + public Server(String[] args) { + tmpDir = args[0]; + } + protected void run() { + + System.setProperty("temp.location", tmpDir); + SpringBusFactory bf = new SpringBusFactory(); + Bus bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-wsdl11.xml"); + BusFactory.setDefaultBus(bus); + setBus(bus); + LoggingInInterceptor in = new LoggingInInterceptor(); + bus.getInInterceptors().add(in); + bus.getInFaultInterceptors().add(in); + LoggingOutInterceptor out = new LoggingOutInterceptor(); + bus.getOutInterceptors().add(out); + bus.getOutFaultInterceptors().add(out); + + GreeterImpl implementor = new GreeterImpl(); + String address = "http://localhost:" + PORT + "/SoapContext/GreeterPort"; + ep = Endpoint.publish(address, implementor); + LOG.info("Published greeter endpoint."); + } + public void tearDown() { + ep.stop(); + ep = null; + } + + + public static void main(String[] args) { + try { + Server s = new Server(args[0]); + s.start(); + } catch (Exception ex) { + ex.printStackTrace(); + System.exit(-1); + } finally { + System.out.println("done!"); + } + } + } + + @BeforeClass + public static void startServers() throws Exception { + TestUtil.getNewPortNumber("decoupled"); + PolicyTestHelper.updatePolicyRef("addr-external-wsdl11.xml", ":9020", ":" + PORT); + System.setProperty("temp.location", TEMPDIR); + + assertTrue("server did not launch correctly", launchServer(Server.class, null, + new String[] {TEMPDIR}, true)); + } + + @Test + public void testUsingAddressing() throws Exception { + SpringBusFactory bf = new SpringBusFactory(); + bus = bf.createBus("org/apache/cxf/systest/ws/policy/addr-wsdl11.xml"); + BusFactory.setDefaultBus(bus); + LoggingInInterceptor in = new LoggingInInterceptor(); + bus.getInInterceptors().add(in); + bus.getInFaultInterceptors().add(in); + LoggingOutInterceptor out = new LoggingOutInterceptor(); + bus.getOutInterceptors().add(out); + bus.getOutFaultInterceptors().add(out); + + BasicGreeterService gs = new BasicGreeterService(); + final Greeter greeter = gs.getGreeterPort(); + updateAddressPort(greeter, PORT); + LOG.fine("Created greeter client."); + ConnectionHelper.setKeepAliveConnection(greeter, true); + + // oneway + + //greeter.greetMeOneWay("CXF"); + + // two-way + + assertEquals("CXF", greeter.greetMe("cxf")); + + // exception + + try { + greeter.pingMe(); + } catch (PingMeFault ex) { + fail("First invocation should have succeeded."); + } + + try { + greeter.pingMe(); + fail("Expected PingMeFault not thrown."); + } catch (PingMeFault ex) { + assertEquals(2, ex.getFaultInfo().getMajor()); + assertEquals(1, ex.getFaultInfo().getMinor()); + } + ((Closeable)greeter).close(); + + } +} http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-external-wsdl11.xml ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-external-wsdl11.xml b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-external-wsdl11.xml new file mode 100644 index 0000000..afadf59 --- /dev/null +++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-external-wsdl11.xml @@ -0,0 +1,35 @@ + + + + + + http://cxf.apache.org/greeter_control/types#wsdl11.service(ReliableGreeterService) + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-wsdl11.xml ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-wsdl11.xml b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-wsdl11.xml new file mode 100644 index 0000000..8017ebd --- /dev/null +++ b/systests/ws-specs/src/test/java/org/apache/cxf/systest/ws/policy/addr-wsdl11.xml @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + http://git-wip-us.apache.org/repos/asf/cxf/blob/e24fef56/systests/ws-specs/src/test/resources/META-INF/cxf/bus-extensions.txt ---------------------------------------------------------------------- diff --git a/systests/ws-specs/src/test/resources/META-INF/cxf/bus-extensions.txt b/systests/ws-specs/src/test/resources/META-INF/cxf/bus-extensions.txt new file mode 100644 index 0000000..d61606c --- /dev/null +++ b/systests/ws-specs/src/test/resources/META-INF/cxf/bus-extensions.txt @@ -0,0 +1 @@ +org.apache.cxf.ws.policy.attachment.external.URIDomainExpressionBuilder::true \ No newline at end of file