Author: veithen
Date: Sun Sep 21 09:14:10 2014
New Revision: 1626544
URL: http://svn.apache.org/r1626544
Log:
AXIS2-5659: Added the unit tests missing in r1622565.
Added:
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml
(with props)
axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/identity.wsdl
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java
(with props)
Added:
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml?rev=1626544&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml
(added)
+++
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml
Sun Sep 21 09:14:10 2014
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<service name="Echo">
+ <parameter
name="ServiceClass">org.apache.axis2.sample.echo.EchoImpl</parameter>
+
+ <!-- Configure SPN using addressingIdentity extensibility element -->
+ <parameter name="addressingIdentity">
+ <Identity
xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
+ <Upn>[email protected]</Upn>
+ </Identity>
+ </parameter>
+
+</service>
Propchange:
axis/axis2/java/core/trunk/modules/kernel/test-resources/deployment/AddressingIdentityServiceTest/service.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/identity.wsdl
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/identity.wsdl?rev=1626544&view=auto
==============================================================================
--- axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/identity.wsdl
(added)
+++ axis/axis2/java/core/trunk/modules/kernel/test-resources/wsdl/identity.wsdl
Sun Sep 21 09:14:10 2014
@@ -0,0 +1,165 @@
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
+ xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
+ xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:ns1="http://org.apache.axis2/xsd"
+ xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl"
xmlns:ns="http://echo.sample.axis2.apache.org"
+ xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+ targetNamespace="http://echo.sample.axis2.apache.org">
+ <wsdl:documentation>Echo</wsdl:documentation>
+ <wsdl:types>
+ <xs:schema attributeFormDefault="qualified"
+ elementFormDefault="qualified"
targetNamespace="http://echo.sample.axis2.apache.org">
+ <xs:element name="echoStringArray">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0"
name="in"
+ nillable="true" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="echoStringArrayResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element maxOccurs="unbounded" minOccurs="0"
name="return"
+ nillable="true" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="echoString">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="in" nillable="true"
+ type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name="echoStringResponse">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="return" nillable="true"
+ type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+ <wsdl:message name="echoStringArrayRequest">
+ <wsdl:part name="parameters" element="ns:echoStringArray" />
+ </wsdl:message>
+ <wsdl:message name="echoStringArrayResponse">
+ <wsdl:part name="parameters" element="ns:echoStringArrayResponse" />
+ </wsdl:message>
+ <wsdl:message name="echoStringRequest">
+ <wsdl:part name="parameters" element="ns:echoString" />
+ </wsdl:message>
+ <wsdl:message name="echoStringResponse">
+ <wsdl:part name="parameters" element="ns:echoStringResponse" />
+ </wsdl:message>
+ <wsdl:portType name="EchoPortType">
+ <wsdl:operation name="echoStringArray">
+ <wsdl:input message="ns:echoStringArrayRequest"
+ wsaw:Action="urn:echoStringArray" />
+ <wsdl:output message="ns:echoStringArrayResponse"
+ wsaw:Action="urn:echoStringArrayResponse" />
+ </wsdl:operation>
+ <wsdl:operation name="echoString">
+ <wsdl:input message="ns:echoStringRequest"
wsaw:Action="urn:echoString" />
+ <wsdl:output message="ns:echoStringResponse"
wsaw:Action="urn:echoStringResponse" />
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="EchoSoap11Binding" type="ns:EchoPortType">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http"
+ style="document" />
+ <wsdl:operation name="echoStringArray">
+ <soap:operation soapAction="urn:echoStringArray"
+ style="document" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="echoString">
+ <soap:operation soapAction="urn:echoString" style="document" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="EchoSoap12Binding" type="ns:EchoPortType">
+ <soap12:binding transport="http://schemas.xmlsoap.org/soap/http"
+ style="document" />
+ <wsdl:operation name="echoStringArray">
+ <soap12:operation soapAction="urn:echoStringArray"
+ style="document" />
+ <wsdl:input>
+ <soap12:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap12:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="echoString">
+ <soap12:operation soapAction="urn:echoString" style="document" />
+ <wsdl:input>
+ <soap12:body use="literal" />
+ </wsdl:input>
+ <wsdl:output>
+ <soap12:body use="literal" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="EchoHttpBinding" type="ns:EchoPortType">
+ <http:binding verb="POST" />
+ <wsdl:operation name="echoStringArray">
+ <http:operation location="echoStringArray" />
+ <wsdl:input>
+ <mime:content type="application/xml" part="parameters" />
+ </wsdl:input>
+ <wsdl:output>
+ <mime:content type="application/xml" part="parameters" />
+ </wsdl:output>
+ </wsdl:operation>
+ <wsdl:operation name="echoString">
+ <http:operation location="echoString" />
+ <wsdl:input>
+ <mime:content type="application/xml" part="parameters" />
+ </wsdl:input>
+ <wsdl:output>
+ <mime:content type="application/xml" part="parameters" />
+ </wsdl:output>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="Echo">
+ <wsdl:port name="EchoHttpSoap11Endpoint"
binding="ns:EchoSoap11Binding">
+ <soap:address
location="http://localhost:8080/axis2/services/Echo.EchoHttpSoap11Endpoint" />
+ <wsa:EndpointReference
xmlns:wsa="http://www.w3.org/2005/08/addressing">
+
<wsa:Address>http://localhost:8080/axis2/services/Echo.EchoHttpSoap12Endpoint</wsa:Address>
+ <Identity
xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
+ <Spn>http/server.example.com</Spn>
+ </Identity>
+ </wsa:EndpointReference>
+ </wsdl:port>
+ <wsdl:port name="EchoHttpSoap12Endpoint"
binding="ns:EchoSoap12Binding">
+ <soap12:address
location="http://localhost:8080/axis2/services/Echo.EchoHttpSoap12Endpoint" />
+ <wsa:EndpointReference
xmlns:wsa="http://www.w3.org/2005/08/addressing">
+
<wsa:Address>http://localhost:8080/axis2/services/Echo.EchoHttpSoap12Endpoint</wsa:Address>
+ <Identity
xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
+ <Spn>http/server.example.com</Spn>
+ </Identity>
+ </wsa:EndpointReference>
+ </wsdl:port>
+ <wsdl:port name="EchoHttpEndpoint" binding="ns:EchoHttpBinding">
+ <http:address
location="http://localhost:8080/axis2/services/Echo.EchoHttpEndpoint" />
+ <wsa:EndpointReference
xmlns:wsa="http://www.w3.org/2005/08/addressing">
+
<wsa:Address>http://localhost:8080/axis2/services/Echo.EchoHttpEndpoint</wsa:Address>
+ <Identity
xmlns="http://schemas.xmlsoap.org/ws/2006/02/addressingidentity">
+ <Spn>http/server.example.com</Spn>
+ </Identity>
+ </wsa:EndpointReference>
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file
Added:
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java
URL:
http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java?rev=1626544&view=auto
==============================================================================
---
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java
(added)
+++
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java
Sun Sep 21 09:14:10 2014
@@ -0,0 +1,236 @@
+/*
+ * 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.axis2.deployment;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.description.AxisEndpoint;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisService2WSDL11;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.TransportInDescription;
+import org.apache.axis2.description.WSDL11ToAxisServiceBuilder;
+import org.apache.axis2.description.java2wsdl.Java2WSDLConstants;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.wsdl.WSDLConstants;
+
+public class AddressingIdentityServiceTest extends TestCase {
+ private static final String HTTP_ENDPOINT_NAME = "EchoHttpEndpoint";
+
+ private static final String EXPECTED_SPN = "http/server.example.com";
+ private static final String EXPECTED_UPN = "[email protected]";
+
+ private static final String IDENTITY_SERVICE_XML =
"test-resources/deployment/AddressingIdentityServiceTest/service.xml";
+ private static final String IDENTITY_SERVICE_WSDL =
"test-resources/wsdl/identity.wsdl";
+
+ private AxisConfiguration axisConfig;
+ private ConfigurationContext configContext;
+
+
+ protected void setUp() throws Exception {
+ this.configContext =
ConfigurationContextFactory.createEmptyConfigurationContext();
+ this.axisConfig = configContext.getAxisConfiguration();
+ TransportInDescription httpReceiver = new
TransportInDescription("http");
+ httpReceiver.setReceiver(new DummyTransportListener());
+ this.axisConfig.addTransportIn(httpReceiver);
+ }
+
+ /**
+ * Tests AxisService construction from a services.xml containing a
+ * {@link AddressingConstants#ADDRESSING_IDENTITY_PARAMETER
ADDRESSING_IDENTITY_PARAMETER} parameter
+ * containing a <wsa:EndpointReference> element with an UPN identity.
+ * The test will then generate the wsdl using {@link AxisService2WSDL11}
API and verify that the port
+ * contains the <wsa:EndpointReference> extensibility element with
the same UPN identity.
+ *
+ * @throws Exception
+ */
+ public void testEndpointReferenceWithUPNIdentityService() throws Exception
{
+ InputStream in = null;
+ try {
+ assertNotNull(axisConfig);
+
+ AxisService service = new AxisService();
+
+ in = new FileInputStream(IDENTITY_SERVICE_XML);
+ ServiceBuilder serviceBuilder = new ServiceBuilder(in,
configContext, service);
+ service = serviceBuilder.populateService(serviceBuilder.buildOM());
+
+ axisConfig.addService(service);
+
+ AxisService2WSDL11 wsdlGenerator = new AxisService2WSDL11(service);
+ wsdlGenerator.setCheckIfEndPointActive(false);
+ OMElement wsdl = wsdlGenerator.generateOM();
+
+ Map<String, AxisEndpoint> endpoints = service.getEndpoints();
+ assertEquals(String.format("Expected to find %d endpoints for
service %s, but found: %d", 3, service.getName(), endpoints.size()), 3,
endpoints.size());
+
+ for (Iterator<String> it = endpoints.keySet().iterator();
it.hasNext(); ) {
+ AxisEndpoint endpoint = service.getEndpoint(it.next());
+ if (HTTP_ENDPOINT_NAME.equals(endpoint.getName())) {
+ //Axis2 does not attach EPRs to http endpoint, therefore
we skip it
+ continue;
+ }
+ OMElement identityElement =
checkWsdlContainsIdentityElement(wsdl, service, endpoint);
+
+ OMElement upnElement =
identityElement.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_UPN);
+ assertNotNull(String.format("Could not find any '%s' claim in
Identity element of endpoint '%s': %s",
+ AddressingConstants.QNAME_IDENTITY_UPN,
endpoint.getName(), identityElement.toString()), upnElement);
+
+ String upn = upnElement.getText();
+ assertTrue(String.format("Expected to find UPN of '%s' but
got: %s", EXPECTED_UPN, upn),
+ EXPECTED_UPN.equals(upn));
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ /**
+ * Tests AxisService construction from a WSDL containing an
<wsa:EndpointReference> port
+ * extensibility element with an SPN identity.
+ * Validates that the AxisEndpoint of the created service contains an
+ * {@link AddressingConstants#ADDRESSING_IDENTITY_PARAMETER
ADDRESSING_IDENTITY_PARAMETER} parameter with
+ * an <wsid:Identity> OMElement with the same SPN as in the original
wsdl.
+ * The test will then re-generate the wsdl using {@link
AxisService2WSDL11} API and verify that the port
+ * contains the <wsa:EndpointReference> extensibility element with
the same SPN identity.
+ *
+ * @throws Exception
+ */
+ public void testEndpointReferenceWithSPNIdentityWSDL() throws Exception {
+ InputStream in = null;
+ try {
+ File wsdlFile = new File(IDENTITY_SERVICE_WSDL);
+ in = new FileInputStream(wsdlFile);
+ AxisService service = new
WSDL11ToAxisServiceBuilder(in).populateService();
+ assertNotNull("Could not load AxisService from wsdl: " +
wsdlFile.getAbsolutePath(), service);
+
+ Map<String, AxisEndpoint> endpoints = service.getEndpoints();
+ assertFalse(String.format("No endpoints found for service %s",
service.getName()), endpoints.isEmpty());
+
+ for (Iterator<String> it = endpoints.keySet().iterator();
it.hasNext(); ) {
+ AxisEndpoint endpoint = service.getEndpoint(it.next());
+
+ assertNotNull(String.format("Could not find any '%s' endpoint
in wsdl: %s", endpoint.getName(),
+ wsdlFile.getAbsolutePath()), endpoint);
+
+ Parameter wsIdentityParameter =
endpoint.getParameter(AddressingConstants.ADDRESSING_IDENTITY_PARAMETER);
+ assertNotNull(String.format("Could not find any '%s' parameter
on '%s' endpoint.",
+ AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
endpoint.getName()), wsIdentityParameter);
+
+ assertNotNull(String.format("Parameter '%s' parameter on '%s'
endpoint has null value.",
+ AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
endpoint.getName()), wsIdentityParameter.getValue());
+
+ assertTrue(String.format("Value of parameter '%s' on '%s'
endpoint is not an instance of %s but is: %s",
+ AddressingConstants.ADDRESSING_IDENTITY_PARAMETER,
endpoint.getName(), OMElement.class,
wsIdentityParameter.getValue().getClass().getName()),
+ wsIdentityParameter.getValue() instanceof OMElement);
+
+ OMElement identityElement = (OMElement)
wsIdentityParameter.getValue();
+ OMElement spnElement =
identityElement.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_SPN);
+
+ assertNotNull(String.format("Could not find any '%s' child
element in Identity element of endpoint '%s': %s",
+ AddressingConstants.QNAME_IDENTITY_SPN,
endpoint.getName(), identityElement.toString()), spnElement);
+
+ String spn = spnElement.getText();
+
+ assertTrue(String.format("Expected to find SPN of '%s' but
got: %s", EXPECTED_SPN, spn),
+ EXPECTED_SPN.equals(spn));
+ }
+
+ axisConfig.addService(service);
+
+ AxisService2WSDL11 wsdlGenerator = new AxisService2WSDL11(service);
+ OMElement wsdl = wsdlGenerator.generateOM();
+
+ endpoints = service.getEndpoints();
+ assertFalse(String.format("No endpoints found for service %s",
service.getName()), endpoints.isEmpty());
+
+ for (Iterator<String> it = endpoints.keySet().iterator();
it.hasNext(); ) {
+ AxisEndpoint endpoint = service.getEndpoint(it.next());
+ if (HTTP_ENDPOINT_NAME.equals(endpoint.getName())) {
+ //Axis2 does not attach EPRs to http endpoint, therefore
we skip it
+ continue;
+ }
+ OMElement identityElement =
checkWsdlContainsIdentityElement(wsdl, service, endpoint);
+
+ OMElement spnElement =
identityElement.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY_SPN);
+ assertNotNull(String.format("Could not find any '%s' element
in Identity element of endpoint '%s': %s",
+ AddressingConstants.QNAME_IDENTITY_SPN,
endpoint.getName(), identityElement.toString()), spnElement);
+
+ String spn = spnElement.getText();
+ assertTrue(String.format("Expected to find SPN of '%s' but
got: %s", EXPECTED_SPN, spn),
+ EXPECTED_SPN.equals(spn));
+ }
+ } finally {
+ if (in != null) {
+ in.close();
+ }
+ }
+ }
+
+ private OMElement checkWsdlContainsIdentityElement(OMElement wsdl,
AxisService service, AxisEndpoint endpoint) {
+ QName nameAtt = new QName("", Java2WSDLConstants.ATTRIBUTE_NAME);
+ QName serviceQName = new QName(WSDLConstants.WSDL1_1_NAMESPACE,
Java2WSDLConstants.SERVICE_LOCAL_NAME);
+
+ OMElement serviceElement = wsdl.getFirstChildWithName(serviceQName);
+ assertNotNull(String.format("Could not find any '%s' service element
in wsdl: \n%s", serviceQName, wsdl.toString()), serviceElement);
+ assertEquals("Expected to find a single service with name: " +
service.getName(), service.getName(),
serviceElement.getAttributeValue(nameAtt));
+
+ OMElement portElement = findPort(serviceElement, endpoint.getName());
+ assertNotNull(String.format("Could not find any port element with name
'%s' in service element: \n%s",
+ endpoint.getName(), serviceElement.toString()), portElement);
+
+ OMElement eprElement =
portElement.getFirstChildWithName(AddressingConstants.Final.WSA_ENDPOINT_REFERENCE);
+ assertNotNull(String.format("Could not find any '%s' element in port
element: \n%s",
+ AddressingConstants.Final.WSA_ENDPOINT_REFERENCE,
portElement.toString()), eprElement);
+
+ OMElement identityElement =
eprElement.getFirstChildWithName(AddressingConstants.QNAME_IDENTITY);
+ assertNotNull(String.format("Could not find any '%s' element in EPR
element: \n%s",
+ AddressingConstants.QNAME_IDENTITY, eprElement.toString(),
identityElement));
+
+ return identityElement;
+ }
+
+ private OMElement findPort(OMElement serviceElement, String portName) {
+ QName portQName = new QName(WSDLConstants.WSDL1_1_NAMESPACE,
Java2WSDLConstants.PORT);
+
+ for (@SuppressWarnings("rawtypes")Iterator portIter =
serviceElement.getChildrenWithName(portQName); portIter.hasNext(); ) {
+ OMElement portElement = (OMElement) portIter.next();
+ if (portName.equals(portElement.getAttributeValue(new QName("",
Java2WSDLConstants.ATTRIBUTE_NAME)))) {
+ return portElement;
+ }
+ }
+
+ return null;
+ }
+}
Propchange:
axis/axis2/java/core/trunk/modules/kernel/test/org/apache/axis2/deployment/AddressingIdentityServiceTest.java
------------------------------------------------------------------------------
svn:eol-style = native