Announcement Announcement Module
Collapse
No announcement yet.
Spring oxm castor unmarshalling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring oxm castor unmarshalling

    Hi i am new to spring oxm. We are working on a project where i need to replace the castor marshalling logic to spring oxm castor marshalling logic. I have done a sample poc on spring oxm using castormarshaller. I have configured the castor marshaller using spring oxm. I have a mapping file defined and i have a java class. Now in my application there are two classes with the same name and both are defined in the mapping file for unmarshalling respectively. When i am trying to unmarshall the xml string i am getting the classcast exception. pls see the below mapping file. when i am trying to unmarshall the string to com.ameriprise.finaccounts.shr.beans.value.data.ac count.SecIdVO it is taking the first occured class from mapping file and giving the class cast exception.

    In spring oxm how to identify the different context paths. In castor marshaller working fine but castor marshaller using spring oxm i am getting the problem of taking the context paths. If i am not using the <map-to xml="SECID"/> then also i am getting root class not found issue in spring oxm. How to resove the issue. please let me know if u need any other information

    <SECID><UNIQUEID>hello</UNIQUEID><UNIQUEIDTYPE>test</UNIQUEIDTYPE></SECID>

    mapping file


    <mapping>
    <class name="com.ameriprise.finaccounts.shr.beans.value.d ata.temp.SecIdVO" >
    <map-to xml="SECID"/>
    <field name="uniqueId" type="string" required="false" direct="false" transient="false">
    <bind-xml name="UNIQUEID" node="element"/>
    </field>
    <field name="uniqueIdType" type="string" get-method="retrieveUniqueIdType" set-method="setUniqueIdType">
    <bind-xml name="UNIQUEIDTYPE" node="element"/>
    </field>
    </class>

    <class name="com.ameriprise.finaccounts.shr.beans.value.d ata.account.SecIdVO" >
    <map-to xml="SECID"/>
    <field name="uniqueId" type="string" required="false" direct="false" transient="false">
    <bind-xml name="UNIQUEID" node="element"/>
    </field>
    <field name="uniqueIdType" type="string" get-method="retrieveUniqueIdType" set-method="setUniqueIdType">
    <bind-xml name="UNIQUEIDTYPE" node="element"/>
    </field>
    </class>
    </mapping>



    import org.springframework.oxm.Marshaller;
    import org.springframework.oxm.Unmarshaller;
    import org.springframework.oxm.castor.CastorMarshaller;
    import org.springframework.oxm.ValidationFailureException ;

    import com.ameriprise.finaccounts.shr.beans.value.data.ac count.SecIdVO;

    public class Application {
    private static final String FILE_NAME = "secid1.xml";
    private SecIdVO secIdVO = new SecIdVO();
    private Marshaller marshaller;
    private Unmarshaller unmarshaller;

    public void setMarshaller(Marshaller marshaller) {
    this.marshaller = marshaller;
    }

    public void setUnmarshaller(Unmarshaller unmarshaller) {
    this.unmarshaller = unmarshaller;
    }

    public void saveSecIdVO() throws IOException {
    FileOutputStream os = null;
    try {
    os = new FileOutputStream(FILE_NAME);
    this.marshaller.marshal(secIdVO, new StreamResult(os));

    } finally {
    if (os != null) {
    os.close();
    }
    }
    }

    public void loadSecIdVO() throws IOException {
    FileInputStream is = null;
    SecIdVO sec;
    try {
    is = new FileInputStream(FILE_NAME);
    sec = (SecIdVO) this.unmarshaller.unmarshal(new StreamSource(is));
    System.out.println("*******sec>>>>" + sec.generateXML());
    } catch (Exception ex) {
    System.out.println("******ex>>>>>>>>>");
    ex.printStackTrace();
    } finally {
    if (is != null) {
    is.close();
    }
    }
    // System.out.println("*******secID*****" + this.secIdVO.generateXML());
    }


    /*public Mapping loadMapping() {
    String appBasePath = "C:\\Documents and Settings\\efc6287\\Desktop\\SpringOXM\\src\\resour ces\\xml\\mappingoutput.xml";
    Mapping mapping = new Mapping();
    try {
    mapping.loadMapping(appBasePath);

    } catch (Exception ex) {
    System.out
    .println("******mapping exception*****" + ex.getMessage());
    }
    return mapping;
    }*/

    public static void main(String[] args) throws IOException {
    ApplicationContext appContext = new ClassPathXmlApplicationContext(
    "applicationContext.xml");

    CastorMarshaller castorMarsh = (CastorMarshaller)appContext.getBean("castorMarsha ller");

    //castorMarsh.setMappingLocation(new File(FILE_NAME));

    Application application = (Application) appContext
    .getBean("application");
    ///System.out.println(application.isValid());
    application.saveSecIdVO();
    application.loadSecIdVO();
    }
    }

  • #2
    Seems also not related to tooling, so moving this to the webservices forum as well. If I am wrong here, please let me know.

    -Martin

    Comment

    Working...
    X