You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by di...@apache.org on 2004/12/15 13:15:52 UTC
cvs commit: ws-axis/java/src/org/apache/axis/encoding TypeMappingImpl.java
dims 2004/12/15 04:15:52
Modified: java/test/functional build.xml FunctionalTests.java
java/src/org/apache/axis/wsdl/fromJava Namespaces.java
java/src/org/apache/axis/encoding TypeMappingImpl.java
Added: java/test/functional auto-deploy.wsdd auto-undeploy.wsdd
AutoTypesTest.jws IAutoTypes.java NestedBean.java
SimpleBean.java TestAutoTypes.java
Log:
Fix for AXIS-1664 - Allow doAutoTypes to be configured through AxisProperties
Reworked patch and test cases from Patrick Martin (patrick.martin@aquilauk.co.uk)
Revision Changes Path
1.22 +1 -0 ws-axis/java/test/functional/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/ws-axis/java/test/functional/build.xml,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- build.xml 2 Jun 2004 17:05:16 -0000 1.21
+++ build.xml 15 Dec 2004 12:15:52 -0000 1.22
@@ -61,6 +61,7 @@
<copy file="${axis.home}/test/functional/AltStockQuoteService.jws" todir="${axis.home}/build/jws" />
<copy file="${axis.home}/test/functional/GlobalTypeTest.jws" todir="${axis.home}/build/jws"/>
<copy file="${axis.home}/test/functional/FaultTest.jws" todir="${axis.home}/build/jws"/>
+ <copy file="${axis.home}/test/functional/AutoTypesTest.jws" todir="${axis.home}/build/jws" />
<copy file="${axis.home}/webapps/axis/EchoHeaders.jws" todir="${axis.home}/build/jws" />
</target>
1.29 +3 -1 ws-axis/java/test/functional/FunctionalTests.java
Index: FunctionalTests.java
===================================================================
RCS file: /home/cvs/ws-axis/java/test/functional/FunctionalTests.java,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -r1.28 -r1.29
--- FunctionalTests.java 14 Mar 2004 16:58:41 -0000 1.28
+++ FunctionalTests.java 15 Dec 2004 12:15:52 -0000 1.29
@@ -66,7 +66,7 @@
suite.addTestSuite(TestFaultsSample.class);
suite.addTestSuite(TestEncoding.class);
-
+
// Attachments service test.
try{
if( null != ClassUtils.forName("javax.activation.DataHandler") &&
@@ -79,6 +79,8 @@
// BROKEN - COMMENTED OUT FOR NOW --gdaniels
//suite.addTestSuite(TestMimeHeaders.class);
+ suite.addTestSuite(TestAutoTypes.class);
+
return suite;
}
}
1.1 ws-axis/java/test/functional/auto-deploy.wsdd
Index: auto-deploy.wsdd
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="axis.doAutoTypes" value="true"/>
<parameter name="disablePrettyXML" value="true"/>
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session"/>
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request"/>
<parameter name="extension" value=".jwr"/>
</handler>
</requestFlow>
</globalConfiguration>
</deployment>
1.1 ws-axis/java/test/functional/auto-undeploy.wsdd
Index: auto-undeploy.wsdd
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<deployment name="defaultClientConfig"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="axis.doAutoTypes" value="false"/>
<parameter name="disablePrettyXML" value="true"/>
<requestFlow>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="session"/>
</handler>
<handler type="java:org.apache.axis.handlers.JWSHandler">
<parameter name="scope" value="request"/>
<parameter name="extension" value=".jwr"/>
</handler>
</requestFlow>
</globalConfiguration>
</deployment>
1.1 ws-axis/java/test/functional/AutoTypesTest.jws
Index: AutoTypesTest.jws
===================================================================
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Date;
import test.functional.SimpleBean;
import test.functional.NestedBean;
/* based upon GlobalTypesTest.jws */
public class AutoTypesTest {
public String ping() {
return "Pong";
}
public SimpleBean getBean() throws RemoteException {
return new SimpleBean();
}
public void setBean(SimpleBean bean) throws RemoteException {
// deliberately blank
}
public SimpleBean echoBean(SimpleBean bean) throws RemoteException {
return bean;
}
public SimpleBean[] getBeanArray(int count) throws RemoteException {
SimpleBean[] result = new SimpleBean[count];
for (int i = 0; i < count; i++) {
result[i] = new SimpleBean();
result[i].setIntValue(i);
}
return result;
}
public void setBeanArray(SimpleBean[] beans) throws RemoteException {
// deliberately blank
}
public SimpleBean[] echoBeanArray(SimpleBean[] beans) throws RemoteException {
return beans;
}
public ArrayList getBeanArrayList(int count) throws RemoteException {
ArrayList result = new ArrayList();
for (int i = 0; i < count; i++) {
SimpleBean bean = new SimpleBean();
bean.setIntValue(i);
result.add(bean);
}
return result;
}
public int setBeanArrayList(ArrayList beansArr) throws RemoteException {
return beansArr.size();
}
public NestedBean getNestedBean() throws RemoteException {
NestedBean result = new NestedBean();
result.setStartDate(new Date());
result.setTestString("some test string " + result.getStartDate()); //$NON-NLS-1$
SimpleBean[] sba = new SimpleBean[3];
sba[0] = new SimpleBean();
sba[1] = new SimpleBean();
sba[2] = new SimpleBean();
sba[0].setIntValue(1);
sba[1].setIntValue(2);
sba[2].setIntValue(3);
result.setSimpleBeanList(sba);
return result;
}
public void setNestedBean(NestedBean value) throws RemoteException {
// deliberately left blank
}
public NestedBean echoNestedBean(NestedBean value) throws RemoteException {
return value;
}
}
1.1 ws-axis/java/test/functional/IAutoTypes.java
Index: IAutoTypes.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed 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 test.functional;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
/**
* Interface which will be used as the client side proxy
* view of the Web Service.
*
* @author Patrick Martin
*/
public interface IAutoTypes extends Remote {
String ping() throws RemoteException;
SimpleBean getBean() throws RemoteException;
void setBean(SimpleBean bean) throws RemoteException;
SimpleBean echoBean(SimpleBean bean) throws RemoteException;
SimpleBean[] getBeanArray(int count) throws RemoteException;
void setBeanArray(SimpleBean[] beans) throws RemoteException;
SimpleBean[] echoBeanArray(SimpleBean[] beans) throws RemoteException;
ArrayList getBeanArrayList(int count) throws RemoteException;
int setBeanArrayList(ArrayList beansArr) throws RemoteException;
NestedBean getNestedBean() throws RemoteException;
void setNestedBean(NestedBean value) throws RemoteException;
NestedBean echoNestedBean(NestedBean value) throws RemoteException;
}
1.1 ws-axis/java/test/functional/NestedBean.java
Index: NestedBean.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed 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 test.functional;
import java.util.Date;
/**
* More Complex JavaBean used in serialisation tests.
*
* @author Patrick Martin
*/
public class NestedBean {
private Date _startDate;
private String _testString;
private SimpleBean _simpleBean;
private SimpleBean[] _simpleBeanList;
public SimpleBean getSimpleBean() {
return _simpleBean;
}
public void setSimpleBean(SimpleBean simpleBean) {
this._simpleBean = simpleBean;
}
public SimpleBean[] getSimpleBeanList() {
return _simpleBeanList;
}
public void setSimpleBeanList(SimpleBean[] simpleBeanList) {
this._simpleBeanList = simpleBeanList;
}
public Date getStartDate() {
return _startDate;
}
public void setStartDate(Date startDate) {
this._startDate = startDate;
}
public String getTestString() {
return _testString;
}
public void setTestString(String testString) {
this._testString = testString;
}
}
1.1 ws-axis/java/test/functional/SimpleBean.java
Index: SimpleBean.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed 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 test.functional;
/**
* Very Simple JavaBean for Very Simple serialisation tests.
*
* @author Patrick Martin
*/
public class SimpleBean {
private int intValue;
public int getIntValue() {
return intValue;
}
public void setIntValue(int intValue) {
this.intValue = intValue;
}
}
1.1 ws-axis/java/test/functional/TestAutoTypes.java
Index: TestAutoTypes.java
===================================================================
/*
* Copyright 2002,2004 The Apache Software Foundation.
*
* Licensed 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 test.functional;
import junit.framework.TestCase;
import org.apache.axis.AxisProperties;
import org.apache.axis.client.AdminClient;
import org.apache.axis.utils.NetworkUtils;
import javax.xml.namespace.QName;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Stub;
import java.net.URL;
import java.util.Date;
public class TestAutoTypes extends TestCase {
protected void setUp() throws java.lang.Exception {
AxisProperties.setProperty("axis.doAutoTypes", "true");
String[] args = {"test/functional/auto-deploy.wsdd"};
AdminClient.main(args);
}
protected void tearDown() throws java.lang.Exception {
AxisProperties.setProperty("axis.doAutoTypes", "false");
String[] args = {"test/functional/auto-undeploy.wsdd"};
AdminClient.main(args);
}
private IAutoTypes getSimpleProxy() throws Exception {
String thisHost = NetworkUtils.getLocalHostname();
String thisPort = System.getProperty("test.functional.ServicePort",
"8080");
//location of wsdl file
String wsdlLocation = "http://" + thisHost + ":" + thisPort +
"/jws/AutoTypesTest.jws?wsdl";
URL urlWsdl = new URL(wsdlLocation);
String nameSpaceUri = "http://" + thisHost + ":" + thisPort +
"/jws/AutoTypesTest.jws";
String serviceName = "AutoTypesTestService";
String portName = "AutoTypesTest";
ServiceFactory serviceFactory = ServiceFactory.newInstance();
Service service = serviceFactory.createService(urlWsdl, new
QName(nameSpaceUri, serviceName));
Stub stub = (Stub) service.getPort(new
QName(nameSpaceUri, portName), IAutoTypes.class);
IAutoTypes myProxy = (IAutoTypes) stub;
return myProxy;
}
public static void main(String[] args) throws Exception {
junit.textui.TestRunner.run(TestAutoTypes.class);
}
public void testPing() throws Exception {
IAutoTypes test = getSimpleProxy();
String ret = test.ping();
assertEquals("echoed string incorrect IntValue", "Pong", ret);
}
public void testGetBean() throws Exception {
getSimpleProxy().getBean();
}
public void testSetBean() throws Exception {
getSimpleProxy().setBean(new SimpleBean());
}
public void testEchoBean() throws Exception {
SimpleBean in = new SimpleBean();
in.setIntValue(42);
SimpleBean out = getSimpleProxy().echoBean(in);
assertEquals("echoed bean incorrect IntValue", 42, out.getIntValue());
}
public void testEchoBeanArray() throws Exception {
SimpleBean[] beans = (SimpleBean[]) getSimpleProxy().echoBeanArray(new SimpleBean[]{
new SimpleBean(), new SimpleBean(),
new SimpleBean(), new SimpleBean(), new SimpleBean(),
new SimpleBean()});
assertEquals("expected array of SimpleBean", SimpleBean[].class, beans
.getClass());
assertEquals("expected array of SimpleBean of length 6", 6,
beans.length);
}
public void testGetBeanArray() throws Exception {
SimpleBean[] beans = (SimpleBean[]) getSimpleProxy().getBeanArray(6);
assertEquals("expected array of SimpleBean", SimpleBean[].class, beans
.getClass());
assertEquals("expected array of SimpleBean of length 6", 6,
beans.length);
}
public void testSetBeanArray() throws Exception {
SimpleBean[] beans = new SimpleBean[]{new SimpleBean(),
new SimpleBean(),
new SimpleBean(),
new SimpleBean(),
new SimpleBean(),
new SimpleBean()};
getSimpleProxy().setBeanArray(beans);
}
public void testGetNestedBean() throws Throwable {
NestedBean result = getSimpleProxy().getNestedBean();
assertNotNull("StartDate is not null ", result.getStartDate());
assertEquals("Test String is correct",
"some test string " + result.getStartDate(),
result.getTestString()); //$NON-NLS-1$
assertEquals("Result Array Correct length ", 3,
result.getSimpleBeanList().length); //$NON-NLS-1$
assertEquals("Result Array[0] Correct", 1,
result.getSimpleBeanList()[0].getIntValue()); //$NON-NLS-1$
assertEquals("Result Array[1] Correct", 2,
result.getSimpleBeanList()[1].getIntValue()); //$NON-NLS-1$
assertEquals("Result Array[2] Correct", 3,
result.getSimpleBeanList()[2].getIntValue()); //$NON-NLS-1$
}
public void testSetNestedBean() throws Throwable {
NestedBean result = new NestedBean();
result.setStartDate(new Date());
result.setTestString("some test string " + result.getStartDate()); //$NON-NLS-1$
SimpleBean[] sba = new SimpleBean[3];
sba[0] = new SimpleBean();
sba[1] = new SimpleBean();
sba[2] = new SimpleBean();
sba[0].setIntValue(1);
sba[1].setIntValue(2);
sba[2].setIntValue(3);
result.setSimpleBeanList(sba);
getSimpleProxy().setNestedBean(result);
}
public void testEchoNestedBean() throws Throwable {
NestedBean result = new NestedBean();
result.setStartDate(new Date());
result.setTestString("some test string " + result.getStartDate()); //$NON-NLS-1$
SimpleBean[] sba = new SimpleBean[3];
sba[0] = new SimpleBean();
sba[1] = new SimpleBean();
sba[2] = new SimpleBean();
sba[0].setIntValue(1);
sba[1].setIntValue(2);
sba[2].setIntValue(3);
result.setSimpleBeanList(sba);
getSimpleProxy().echoNestedBean(result);
}
}
1.13 +34 -0 ws-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java
Index: Namespaces.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/wsdl/fromJava/Namespaces.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- Namespaces.java 18 Nov 2004 15:31:20 -0000 1.12
+++ Namespaces.java 15 Dec 2004 12:15:52 -0000 1.13
@@ -19,6 +19,8 @@
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
+import java.net.URL;
+import java.net.MalformedURLException;
/**
* <p>Description: A HashMap of packageNames and namespaces with some helper methods </p>
@@ -199,6 +201,38 @@
return makeNamespaceFromPackageName(packageName, protocol);
}
+ /**
+ * Reverse the process. Get the package name from the namespace.
+ * @param namespace
+ * @return
+ */
+ public static String getPackage(String namespace) {
+ try {
+ URL url = new URL(namespace);
+ StringTokenizer st = new StringTokenizer(url.getHost(), ".");
+ String[] words = new String[st.countTokens()];
+ for (int i = 0; i < words.length; ++i) {
+ words[i] = st.nextToken();
+ }
+ StringBuffer sb = new StringBuffer(80);
+ for (int i = words.length - 1; i >= 0; --i) {
+ String word = words[i];
+ // seperate with dot
+ if (i != words.length - 1) {
+ sb.append('.');
+ }
+ sb.append(word);
+ }
+ String pkg = sb.toString();
+ if (pkg.equals("DefaultNamespace")) {
+ return "";
+ }
+ return pkg;
+ } catch (MalformedURLException e) {
+ }
+ return null;
+ }
+
/**
* Method makeNamespaceFromPackageName
*
1.53 +45 -4 ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java
Index: TypeMappingImpl.java
===================================================================
RCS file: /home/cvs/ws-axis/java/src/org/apache/axis/encoding/TypeMappingImpl.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- TypeMappingImpl.java 22 Nov 2004 21:39:53 -0000 1.52
+++ TypeMappingImpl.java 15 Dec 2004 12:15:52 -0000 1.53
@@ -17,12 +17,16 @@
package org.apache.axis.encoding;
import org.apache.axis.Constants;
+import org.apache.axis.AxisProperties;
+import org.apache.axis.MessageContext;
import org.apache.axis.components.logger.LogFactory;
import org.apache.axis.encoding.ser.ArrayDeserializerFactory;
import org.apache.axis.encoding.ser.ArraySerializerFactory;
import org.apache.axis.encoding.ser.BeanDeserializerFactory;
import org.apache.axis.encoding.ser.BeanSerializerFactory;
import org.apache.axis.utils.Messages;
+import org.apache.axis.utils.ClassUtils;
+import org.apache.axis.utils.JavaUtils;
import org.apache.axis.wsdl.fromJava.Namespaces;
import org.apache.axis.wsdl.fromJava.Types;
import org.apache.commons.logging.Log;
@@ -105,7 +109,7 @@
protected TypeMapping delegate; // Pointer to delegate or null
private ArrayList namespaces; // Supported namespaces
- protected boolean doAutoTypes = false;
+ protected Boolean doAutoTypes = null;
/**
* Construct TypeMapping
@@ -560,7 +564,7 @@
* register it's javaType and xmlType. List classes and derivitives
* can't be used because they should be serialized as an anyType array.
*/
- if ( doAutoTypes &&
+ if ( shouldDoAutoTypes() &&
javaType != List.class &&
!List.class.isAssignableFrom(javaType) &&
xmlType != null &&
@@ -594,7 +598,7 @@
/* If the class isn't an array or List and auto-typing is turned on,
* register the class and it's type as beans.
*/
- if (xmlType == null && doAutoTypes)
+ if (xmlType == null && shouldDoAutoTypes())
{
xmlType = new QName(
Namespaces.makeNamespace( javaType.getName() ),
@@ -637,6 +641,23 @@
}
//log.debug("getClassForQName javaType =" + javaType);
+ if(javaType == null && shouldDoAutoTypes()) {
+ String pkg = Namespaces.getPackage(xmlType.getNamespaceURI());
+ if (pkg != null) {
+ String className = xmlType.getLocalPart();
+ if (pkg.length() > 0) {
+ className = pkg + "." + className;
+ }
+ try {
+ javaType = ClassUtils.forName(className);
+ register(javaType,
+ xmlType,
+ new BeanSerializerFactory(javaType, xmlType),
+ new BeanDeserializerFactory(javaType, xmlType));
+ } catch (ClassNotFoundException e) {
+ }
+ }
+ }
return javaType;
}
@@ -678,7 +699,27 @@
}
public void setDoAutoTypes(boolean doAutoTypes) {
- this.doAutoTypes = doAutoTypes;
+ this.doAutoTypes = doAutoTypes ? Boolean.TRUE : Boolean.FALSE;
+ }
+
+ public boolean shouldDoAutoTypes() {
+ if(doAutoTypes != null) {
+ return doAutoTypes.booleanValue();
+ }
+ MessageContext msgContext = MessageContext.getCurrentContext();
+ if(msgContext != null) {
+ if (msgContext.isPropertyTrue("axis.doAutoTypes") ||
+ JavaUtils.isTrue(msgContext.getAxisEngine().getOption("axis.doAutoTypes"))) {
+ doAutoTypes = Boolean.TRUE;
+ }
+ }
+ if(doAutoTypes == null){
+ doAutoTypes = AxisProperties.getProperty("axis.doAutoTypes",
+ "false")
+ .equals("true") ?
+ Boolean.TRUE : Boolean.FALSE;
+ }
+ return doAutoTypes.booleanValue();
}
/**