Solved

Java Array string

Posted on 2009-07-03
15
812 Views
Last Modified: 2012-06-22
I am connecting to a WCF service and it's expecting me to send an

Array of Array of string

I am creating a multi dimensional array in java and assigning it to that value but the WCF sees it as null.

on the WCF the function it is expecting an mutidimentional array

String [10][10]

any suggestions

0
Comment
Question by:JonMny
  • 8
  • 7
15 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24773933
>>I am creating a multi dimensional array in java and assigning it to that value

How? Please post code
0
 
LVL 9

Author Comment

by:JonMny
ID: 24774677
Java code
                 merge = new Merge();
                String[] fieldNames = new String[4];
                String[][] fieldValues = new String[1][4];
                String[] values = new String[4];
                fieldNames[0] = "Header1";
                fieldNames[1] = "Header2";
                fieldNames[2] = "Header3";
                fieldNames[3] = "Header4";
               
                values[0] = "Row1Value1";
                values[1]= "Row1Value2";
                values[2]= "Row1Value3";
                values[3]= "Row1Value4";
             
                fieldValues[0][0]=values[0];
                fieldValues[0][1]=values[1];
                fieldValues[0][2]=values[2];
                fieldValues[0][3]=values[3];
 
                mergeData.setFieldNames(fieldNames);
           mergeData.setFieldValues(fieldValues);
           merge.setMergeData(mergeData);
         po.setMerge(merge);
   
  //Create Job    
  Job job = new Job();

 
 
WSDL (Section)
 

<xs:element minOccurs="0" name="MergeData" nillable="true" type="tns:MergeData" />
<xs:element minOccurs="0" name="MergeFile" nillable="true" type="tns:MergeFile" />
</xs:sequence>
</xs:complexType>
<xs:element name="Merge" nillable="true" type="tns:Merge" />
+ <xs:complexType name="MergeData">
- <xs:sequence>
<xs:element minOccurs="0" name="FieldNames" nillable="true" type="q1:ArrayOfstring" xmlns:q1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />
<xs:element minOccurs="0" name="FieldValues" nillable="true" type="q2:ArrayOfArrayOfstring" xmlns:q2="http://schemas.microsoft.com/2003/10/Serialization/Arrays" />  
 
 
When submitted the Field Names "go through" the Merge Data is empty
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24774742
>>mergeData

is not shown in your code - where do you initialize it?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 86

Expert Comment

by:CEHJ
ID: 24774760
>>values[0] = "Row1Value1";

In the above, btw, 'values' is redundant. You can do


fieldValues[0][0] = "Row1Value1"; //etc

Open in new window

0
 
LVL 9

Author Comment

by:JonMny
ID: 24774805
Merge merge = new Merge();
     MergeData mergeData = new MergeData();
 
Below is the auto generated Java code
 

/**
 * MergeData.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
 */
package org.datacontract.schemas._2004._07.Rimage_Web_Service;
public class MergeData  implements java.io.Serializable {
    private java.lang.String[] fieldNames;
    private java.lang.String[][] fieldValues;
    public MergeData() {
    }
    public MergeData(
           java.lang.String[] fieldNames,
           java.lang.String[][] fieldValues) {
           this.fieldNames = fieldNames;
           this.fieldValues = fieldValues;
    }

    /**
     * Gets the fieldNames value for this MergeData.
     *
     * @return fieldNames
     */
    public java.lang.String[] getFieldNames() {
        return fieldNames;
    }

    /**
     * Sets the fieldNames value for this MergeData.
     *
     * @param fieldNames
     */
    public void setFieldNames(java.lang.String[] fieldNames) {
        this.fieldNames = fieldNames;
    }

    /**
     * Gets the fieldValues value for this MergeData.
     *
     * @return fieldValues
     */
    public java.lang.String[][] getFieldValues() {
        return fieldValues;
    }

    /**
     * Sets the fieldValues value for this MergeData.
     *
     * @param fieldValues
     */
    public void setFieldValues(java.lang.String[][] fieldValues) {
        this.fieldValues = fieldValues;
    }
    private java.lang.Object __equalsCalc = null;
    public synchronized boolean equals(java.lang.Object obj) {
        if (!(obj instanceof MergeData)) return false;
        MergeData other = (MergeData) obj;
        if (obj == null) return false;
        if (this == obj) return true;
        if (__equalsCalc != null) {
            return (__equalsCalc == obj);
        }
        __equalsCalc = obj;
        boolean _equals;
        _equals = true && 
            ((this.fieldNames==null && other.getFieldNames()==null) ||
             (this.fieldNames!=null &&
              java.util.Arrays.equals(this.fieldNames, other.getFieldNames()))) &&
            ((this.fieldValues==null && other.getFieldValues()==null) ||
             (this.fieldValues!=null &&
              java.util.Arrays.equals(this.fieldValues, other.getFieldValues())));
        __equalsCalc = null;
        return _equals;
    }
    private boolean __hashCodeCalc = false;
    public synchronized int hashCode() {
        if (__hashCodeCalc) {
            return 0;
        }
        __hashCodeCalc = true;
        int _hashCode = 1;
        if (getFieldNames() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getFieldNames());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getFieldNames(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        if (getFieldValues() != null) {
            for (int i=0;
                 i<java.lang.reflect.Array.getLength(getFieldValues());
                 i++) {
                java.lang.Object obj = java.lang.reflect.Array.get(getFieldValues(), i);
                if (obj != null &&
                    !obj.getClass().isArray()) {
                    _hashCode += obj.hashCode();
                }
            }
        }
        __hashCodeCalc = false;
        return _hashCode;
    }
    // Type metadata
    private static org.apache.axis.description.TypeDesc typeDesc =
        new org.apache.axis.description.TypeDesc(MergeData.class, true);
    static {
        typeDesc.setXmlType(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "MergeData"));
        org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("fieldNames");
        elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "FieldNames"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"));
        typeDesc.addFieldDesc(elemField);
        elemField = new org.apache.axis.description.ElementDesc();
        elemField.setFieldName("fieldValues");
        elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/Rimage.Web.Service", "FieldValues"));
        elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
        elemField.setMinOccurs(0);
        elemField.setNillable(true);
        elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
        typeDesc.addFieldDesc(elemField);
    }
    /**
     * Return type metadata object
     */
    public static org.apache.axis.description.TypeDesc getTypeDesc() {
        return typeDesc;
    }
    /**
     * Get Custom Serializer
     */
    public static org.apache.axis.encoding.Serializer getSerializer(
           java.lang.String mechType,
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.BeanSerializer(
            _javaType, _xmlType, typeDesc);
    }
    /**
     * Get Custom Deserializer
     */
    public static org.apache.axis.encoding.Deserializer getDeserializer(
           java.lang.String mechType,
           java.lang.Class _javaType,  
           javax.xml.namespace.QName _xmlType) {
        return
          new  org.apache.axis.encoding.ser.BeanDeserializer(
            _javaType, _xmlType, typeDesc);
    }
}
 
 
 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24774817
You may find, as is most the case where serialization is  involved, only the no-arg ctor gets called
0
 
LVL 9

Author Comment

by:JonMny
ID: 24775018
I am calling the no arg constructors.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24776129
Can you post the actual error message you're getting?
0
 
LVL 9

Author Comment

by:JonMny
ID: 24785134
there is not an error generated, the problem is the resulting soap message has a "" instead of the values from the array
0
 
LVL 9

Author Comment

by:JonMny
ID: 24785789
Ok,
I have more information attached is a trace dump one from .net that works and the java that does not.
 
 
Java:

<ns1:FieldNames>
<ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header1</ns2:string>
<ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header2</ns3:string>
<ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header3</ns4:string>
<ns5:string xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header4</ns5:string>
</ns1:FieldNames>
<ns1:FieldValues>
<ns6:ArrayOfstring xmlns:ns6="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<ns6:ArrayOfstring>Row1Value1</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value2</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value3</ns6:ArrayOfstring>
<ns6:ArrayOfstring>Row1Value4</ns6:ArrayOfstring>
</ns6:ArrayOfstring>
 
 
.net

<a:MergeData>
<a:FieldNames xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:string>Header1</b:string>
<b:string>Header2</b:string>
<b:string>Header3</b:string>
<b:string>Header4</b:string>
</a:FieldNames>
<a:FieldValues xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<b:ArrayOfstring>
<b:string>Row1Value1</b:string>
<b:string>Row1Value2</b:string>
<b:string>Row1Value3</b:string>
<b:string>Row1Value4</b:string>
</b:ArrayOfstring>
</a:FieldValues>
</a:MergeData>
 
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24785873
MergeData has not been deserialized properly. Probably for the reasons i already gave you
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24785894
Sorry - ignore that last comment
0
 
LVL 9

Author Comment

by:JonMny
ID: 24786324
Soap end point class

qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfArrayOfstring");
cachedSerQNames.add(qName);
cls = java.lang.String[][].class;
cachedSerClasses.add(cls);
qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
qName2 = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));
cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
qName = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring");
cachedSerQNames.add(qName);
cls = java.lang.String[].class;
cachedSerClasses.add(cls);
qName = new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string");
qName2 = new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string");
cachedSerFactories.add(new org.apache.axis.encoding.ser.ArraySerializerFactory(qName, qName2));
cachedDeserFactories.add(new org.apache.axis.encoding.ser.ArrayDeserializerFactory());
 
Mergedata class

typeDesc.setXmlType(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "MergeData"));
org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("fieldNames");
elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "FieldNames"));
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elemField.setMinOccurs(0);
elemField.setNillable(true);
elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string"));
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("fieldValues");
elemField.setXmlName(new javax.xml.namespace.QName("http://schemas.datacontract.org/2004/07/test.Web.Service", "FieldValues"));
elemField.setXmlType(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "string")); --Chaged this
elemField.setMinOccurs(0);
elemField.setNillable(true);
elemField.setItemQName(new javax.xml.namespace.QName("http://schemas.microsoft.com/2003/10/Serialization/Arrays", "ArrayOfstring"));
typeDesc.addFieldDesc(elemField);
}
 

I modified the serilizer above and got the following

<ns1:MergeData>
<ns1:FieldNames>
<ns2:string xmlns:ns2="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header1</ns2:string>
<ns3:string xmlns:ns3="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header2</ns3:string>
<ns4:string xmlns:ns4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header3</ns4:string>
<ns5:string xmlns:ns5="http://schemas.microsoft.com/2003/10/Serialization/Arrays">Header4</ns5:string>
</ns1:FieldNames>
<ns1:FieldValues xsi:type="ns6:ArrayOfArrayOfstring" xmlns:ns6="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<ns6:ArrayOfstring xsi:type="ns6:ArrayOfstring">
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value1</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value2</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value3</ns6:ArrayOfstring>
<ns6:ArrayOfstring xsi:type="xsd:string">Row1Value4</ns6:ArrayOfstring>
</ns6:ArrayOfstring>
</ns1:FieldValues>
</ns1:MergeData>
</ns1:Merge>
</ns1:ProductionOptions>
<ns1:Type>ImageAndRecord</ns1:Type>
</ns1:Job>
</request>
</SubmitJob>
</soapenv:Body>
 
 
0
 
LVL 9

Author Comment

by:JonMny
ID: 24840027
Ok I have done some more research, the problem is apache axis does not support multi-dimensional arrays which explains why it is not serializing properly. Does anyone know of a sample custom serializer for multidimesional arrays.
0
 
LVL 9

Accepted Solution

by:
JonMny earned 0 total points
ID: 24981668
The answer is that axis2 still does not support multi-dimensional arrays.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
diffSum example 4 50
use lov values 2 61
iterator/ListIterator approach 17 39
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to implement Singleton Design Pattern in Java.

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question