You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ga...@apache.org on 2008/04/12 05:57:09 UTC
svn commit: r647371 - in /webservices/axis2/trunk/java/modules:
jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/
jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/
jaxws-integration/test/org/apache/axis2/jaxws/samp...
Author: gawor
Date: Fri Apr 11 20:57:09 2008
New Revision: 647371
URL: http://svn.apache.org/viewvc?rev=647371&view=rev
Log:
improved array serialization and xsd:list handling (AXIS2-3734)
Added:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java (with props)
Modified:
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/RPCLitStringArrayTests.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/StringListTests.java
webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/stringlist/StringListPortTypeImpl.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaParamToPDCConverter.java
webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
Added: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java?rev=647371&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java Fri Apr 11 20:57:09 2008
@@ -0,0 +1,44 @@
+/*
+ * 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.jaxws.rpclit.stringarray;
+
+import javax.jws.WebMethod;
+import javax.jws.WebService;
+import javax.jws.soap.SOAPBinding;
+import javax.jws.soap.SOAPBinding.Style;
+
+@WebService(name = "EchoNoSEI", serviceName="RPCLitStringArrayService", targetNamespace = "http://sei.stringarray.rpclit.jaxws.axis2.apache.org")
+@SOAPBinding(style = Style.RPC)
+public class EchoImplNoSEI {
+
+ @WebMethod
+ public String echoString(String arg0) {
+ return arg0;
+ }
+
+ @WebMethod
+ public String[] echoStringArray(String [] args) {
+ for (int i = 0; i < args.length; i++) {
+ args[i] = args[i] + "return";
+ }
+ return args;
+ }
+
+}
Propchange: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/EchoImplNoSEI.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/RPCLitStringArrayTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/RPCLitStringArrayTests.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/RPCLitStringArrayTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/rpclit/stringarray/tests/RPCLitStringArrayTests.java Fri Apr 11 20:57:09 2008
@@ -31,31 +31,53 @@
public class RPCLitStringArrayTests extends AbstractTestCase {
- String axisEndpoint = "http://localhost:6060/axis2/services/RPCLitStringArrayService.EchoImplPort";
-
- public static Test suite() {
+ public static Test suite() {
return getTestSetup(new TestSuite(RPCLitStringArrayTests.class));
}
- public void testStringArrayType() {
+ public void testStringArrayType() throws Exception {
+ System.out.println("------------------------------");
+ System.out.println("Test : " + getName());
+
+ RPCLitStringArrayService service = new RPCLitStringArrayService();
+ Echo portType = service.getEchoPort();
+ BindingProvider p = (BindingProvider) portType;
+ p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+ "http://localhost:6060/axis2/services/RPCLitStringArrayService.EchoImplPort");
+
+ String[] strArray= {"str1", "str2", "str3", "str4 5"};
+ StringArray array = new StringArray();
+ array.getItem().addAll(Arrays.asList(strArray));
+ StringArray result = portType.echoStringArray(array);
+
+ assertEquals(array.getItem().size(), result.getItem().size());
+ for (int i = 0; i < array.getItem().size(); i++) {
+ assertEquals(array.getItem().get(i), result.getItem().get(i));
+ }
+
+ System.out.print("---------------------------------");
+ }
+
+ public void testStringArrayTypeNoSEI() throws Exception {
System.out.println("------------------------------");
System.out.println("Test : " + getName());
- try {
- RPCLitStringArrayService service = new RPCLitStringArrayService();
- Echo portType = service.getEchoPort();
- BindingProvider p = (BindingProvider) portType;
- p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint);
-
- String[] strArray= {"str1", "str2", "str3"};
- StringArray array = new StringArray();
- array.getItem().addAll(Arrays.asList(strArray));
- portType.echoStringArray(array);
+ RPCLitStringArrayService service = new RPCLitStringArrayService();
+ Echo portType = service.getEchoPort();
+ BindingProvider p = (BindingProvider) portType;
+ p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
+ "http://localhost:6060/axis2/services/RPCLitStringArrayService.EchoNoSEIPort");
+
+ String[] strArray= {"str1", "str2", "str3", "str4 5"};
+ StringArray array = new StringArray();
+ array.getItem().addAll(Arrays.asList(strArray));
+ StringArray result = portType.echoStringArray(array);
- System.out.print("---------------------------------");
- } catch (Exception e) {
- e.printStackTrace();
- fail();
+ assertEquals(array.getItem().size(), result.getItem().size());
+ for (int i = 0; i < array.getItem().size(); i++) {
+ assertEquals(array.getItem().get(i) + "return", result.getItem().get(i));
}
+
+ System.out.print("---------------------------------");
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/StringListTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/StringListTests.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/StringListTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/StringListTests.java Fri Apr 11 20:57:09 2008
@@ -43,8 +43,15 @@
StringListPortType portType =sls.getStringListPort();
BindingProvider p = (BindingProvider)portType;
p.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, axisEndpoint);
- String[] retString = portType.stringList(new String[]{"String1","String2","String3"});
+ String[] send = new String[]{"String1","String2","String3","String Space"};
+ // since the array is serilized as xsd:list the string with space will be converted
+ // to a new array element. so we send array.length of 3 but get back array.length of 5
+ String[] expected = new String[]{"String1","String2","String3","String","Space"};
+ String[] retString = portType.stringList(send);
assertNotNull(retString);
- assertTrue(retString.length == 3);
+ assertEquals(expected.length, retString.length);
+ for (int i = 0; i < expected.length; i++) {
+ assertEquals(expected[i], retString[i]);
+ }
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/stringlist/StringListPortTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/stringlist/StringListPortTypeImpl.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/stringlist/StringListPortTypeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/sample/stringlist/StringListPortTypeImpl.java Fri Apr 11 20:57:09 2008
@@ -31,7 +31,7 @@
*/
public String[] stringList(String[] parameters) {
// TODO Auto-generated method stub
- return new String[]{"str1", "str2", "str3"};
+ return parameters;
}
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/JAXBDSContext.java Fri Apr 11 20:57:09 2008
@@ -395,49 +395,29 @@
// Unfortunately RPC is type based. Thus a
// declared type must be used to unmarshal the xml.
Object jaxb;
-
+
if (!isList) {
// case: We are not unmarshalling an xsd:list but an Array.
if (type.isArray()) {
// If the context is created using package
// we will not have common arrays or type array in the context
- // so let use a differet way to unmarshal this type
+ // but there is not much we can do about it so seralize it as
+ // usual
if (ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CONTEXT_PATH) {
- jaxb = unmarshalAsListOrArray(reader, u, type);
+ jaxb = u.unmarshal(reader, type);
}
// list on client array on server, Can happen only in start from java
// case.
else if ((ctype == JAXBUtils.CONSTRUCTION_TYPE.BY_CLASS_ARRAY)) {
- jaxb = unmarshalAsListOrArray(reader, u, type);
- /*
- * Commenting out code...
- *
+
// The type could be any Object or primitive
// I will first unmarshall the xmldata to a String[]
// Then use the unmarshalled jaxbElement to create
// proper type Object Array.
- jaxb = u.unmarshal(reader, String[].class);
-
+ jaxb = unmarshalArray(reader, u, type);
- Object typeObj = getTypeEnabledObject(jaxb);
-
- // Now convert String Array in to the required Type Array.
- if (getTypeEnabledObject(typeObj) instanceof String[]) {
- String[] strArray = (String[]) typeObj;
- String strTokens = new String();
- for (String str : strArray) {
- strTokens = strTokens + " " + str;
- }
-
- QName qName =
- XMLRootElementUtil.
- getXmlRootElementQNameFromObject(jaxb);
- Object obj = XSDListUtils.fromXSDListString(strTokens, type);
- jaxb = new JAXBElement(qName, type, obj);
- }
- */
} else {
jaxb = u.unmarshal(reader, type);
@@ -502,6 +482,26 @@
});
}
+ private static Object unmarshalArray(XMLStreamReader reader, Unmarshaller u,
+ Class type)
+ throws Exception {
+
+ Object jaxb = u.unmarshal(reader, String[].class);
+
+ Object typeObj = getTypeEnabledObject(jaxb);
+
+ // Now convert String Array in to the required Type Array.
+ if (typeObj instanceof String[]) {
+ String[] strArray = (String[]) typeObj;
+ Object obj = XSDListUtils.fromStringArray(strArray, type);
+ QName qName =
+ XMLRootElementUtil.getXmlRootElementQNameFromObject(jaxb);
+ jaxb = new JAXBElement(qName, type, obj);
+ }
+
+ return jaxb;
+ }
+
/**
* convert the String into a list or array
* @param <T>
@@ -593,7 +593,7 @@
// String instead. Then we get the correct wire format:
// <foo>1 2 3</foo>
Object jbo = b;
- if (isList || (type != null && type.isArray())) {
+ if (isList) {
if (DEBUG_ENABLED) {
log.debug("marshalling type which is a List or Array");
}
Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/datasource/jaxb/XSDListUtils.java Fri Apr 11 20:57:09 2008
@@ -150,6 +150,53 @@
}
}
+ public static Object fromStringArray(String[] items, Class type) throws Exception {
+ if (type.isArray()) {
+ Class componentType = type.getComponentType();
+ List list = new ArrayList();
+
+ for (String item : items) {
+ Object componentObject = getFromText(item, componentType);
+ list.add(componentObject);
+ }
+
+ Class arrayType = componentType;
+ if (componentType.isPrimitive()) {
+ Class boxedType = getBoxedType(componentType);
+ if (boxedType != null) {
+ arrayType = boxedType;
+ }
+ }
+
+ Object array = Array.newInstance(arrayType, list.size());
+ return list.toArray((Object[])array);
+ } else {
+ throw new IllegalArgumentException(type.toString());
+ }
+ }
+
+ public static String[] toStringArraay(Object container) throws Exception {
+ if (container != null && container.getClass().isArray()) {
+ int size = Array.getLength(container);
+ String [] strArray = new String[size];
+ for (int i = 0; i < size; i++) {
+ Object component = Array.get(container, i);
+ strArray[i] = getAsText(component);
+ }
+ return strArray;
+ } else if(container != null && List.class.isAssignableFrom(container.getClass())){
+ List containerAsList = (List)container;
+ int size = containerAsList.size();
+ String [] strArray = new String[size];
+ for (int i = 0; i < size; i++) {
+ strArray[i] = getAsText(containerAsList.get(i));
+ }
+ return strArray;
+ } else {
+ throw new IllegalArgumentException(container.getClass().toString());
+ }
+ }
+
/**
* @param obj
* @return xml text for this object
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaParamToPDCConverter.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaParamToPDCConverter.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaParamToPDCConverter.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/builder/converter/JavaParamToPDCConverter.java Fri Apr 11 20:57:09 2008
@@ -49,7 +49,8 @@
pdc.setParameterType(fullType);
pdc.setListOrder(i);
attachWebParamAnnotation(pdc, i);
- pdcList.add(pdc);
+ pdc.setIsListType(ConverterUtils.hasXmlListAnnotation(paramAnnotations[i]));
+ pdcList.add(pdc);
}
return pdcList;
}
Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java?rev=647371&r1=647370&r2=647371&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java Fri Apr 11 20:57:09 2008
@@ -204,7 +204,7 @@
parentEndpointInterfaceDescription = parent;
partAttachmentMap = new HashMap<String, AttachmentDescription>();
setSEIMethod(method);
- isListType = ConverterUtils.hasXmlListAnnotation(method.getAnnotations());
+
// The operationQName is intentionally unqualified to be consistent with the remaining parts of the system.
// Using a qualified name will cause breakage.
// Don't do --> this.operationQName = new QName(parent.getTargetNamespace(), getOperationName());
@@ -589,6 +589,7 @@
getAnnotation(seiMethod, WebMethod.class);
parameterDescriptions = createParameterDescriptions();
faultDescriptions = createFaultDescriptions();
+ isListType = ConverterUtils.hasXmlListAnnotation(seiMethod.getAnnotations());
}
// Register understood headers on axisOperation
registerMustUnderstandHeaders();
---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org