Solved

Java Array string

Posted on 2009-07-03
15
805 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is a "java.lang.System Property"   ? 20 57
github account with ecipse 1 42
tomcat not starting 6 31
expectj telnet failing 5 26
These instructions are based on installing Owncloud on your new raspberry pi connected with a usb HDD. What do you need Part A? A Raspberry Pi, model B. A boot SD card for the Raspberry Pi. A usb HDD An Ethernet cable to connect to the lo…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

920 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now