Axis 에서 Map사용하기







 Axis에서는 배열형태나 Vector형태는 기본적으로 전송을 지원하지만 Map같은 Collection형태는 지원해주지 않는다.


wsdl2java를 이용하면 Map에 대응하는 java파일을 얻을수 있다.


– service.wsdl –


..


<complexType name=”mapItem”>
    <sequence>
     <element name=”key” nillable=”true” type=”xsd:anyType”/>
     <element name=”value” nillable=”true” type=”xsd:anyType”/>
    </sequence>
   </complexType>
   <complexType name=”Map”>
    <sequence>
     <element maxOccurs=”unbounded” minOccurs=”0″ name=”item” type=”apachesoap:mapItem”/>
    </sequence>
   </complexType>



– wsdl2java 로 얻어진 MapItem.java –


/**
 * MapItem.java
 *
 * This file was auto-generated from WSDL
 * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
 */


package org.apache.xml.xml_soap;


public class MapItem  implements java.io.Serializable {
    private java.lang.Object key;


    private java.lang.Object value;


    public MapItem() {
    }


    public MapItem(
           java.lang.Object key,
           java.lang.Object value) {
           this.key = key;
           this.value = value;
    }



    /**
     * Gets the key value for this MapItem.
     *
     * @return key
     */
    public java.lang.Object getKey() {
        return key;
    }



    /**
     * Sets the key value for this MapItem.
     *
     * @param key
     */
    public void setKey(java.lang.Object key) {
        this.key = key;
    }



    /**
     * Gets the value value for this MapItem.
     *
     * @return value
     */
    public java.lang.Object getValue() {
        return value;
    }



    /**
     * Sets the value value for this MapItem.
     *
     * @param value
     */
    public void setValue(java.lang.Object value) {
        this.value = value;
    }



}


– deploy.wsdl에 추가된 beanMapping –


<beanMapping
        xmlns:ns=”http://xml.apache.org/xml-soap
        qname=”ns:mapItem”
        languageSpecificType=”java:org.apache.xml.xml_soap.MapItem” 
       ENCODINGStyle=”http://schemas.xmlsoap.org/soap/ENCODING/
      />


– wsdl에서 Map의 참조방법 –


<element name=”customFields” nillable=”true” type=”apachesoap:Map”/>

Vector는 Object의 배열로 처리할수 있는것처럼 Map은 key와 value의 Pair인 MapItem배열을 통해 전송할 수있다.