Title: Message
Ahh ... the story continues.
 
The Schema you are using, references another Schema <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext"> which in turn imports other name spaces.
i.e.

<xsd:schema targetNamespace="http://schemas.xmlsoap.org/ws/2002/04/secext" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://schemas.xmlsoap.org/ws/2002/04/secext" xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" elementFormDefault="qualified" attributeFormDefault="unqualified" version="0.2">
 <xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>
 <xsd:import namespace="http://www.w3.org/2000/09/xmldsig#" schemaLocation="http://www.w3.org/TR/xmldsig-core/xmldsig-core-schema.xsd"/>

This is a bit of a grey area for me so here's my best guess. :-)
You need to generate the code for each of these namespaces separately and in the castorbuilder.properties file setup the relationship between the namespace and the code base - see example below
 
Perhaps  someone else who *uses* imports will help with the tutorial here ... :-)

# XML namespace mapping to Java packages
#
#org.exolab.castor.builder.nspackages=\
  http://www.xyz.com/schemas/project=com.xyz.schemas.project,\
  http://www.xyz.com/schemas/person=com.xyz.schemas.person

HTH

john

-----Original Message-----
From: simmi sharma [mailto:[EMAIL PROTECTED]
Sent: Monday, March 17, 2003 2:47 AM
To: [EMAIL PROTECTED]
Subject: Re: [castor-dev] Problem Unmarshalling Soap-envelope using Castor

Thanks John.

I could overcome that error. I generated java files from WS-Security schema and Soap schema and my code was working fine. Then I generated java file using XML digital Signature schema and I started getting error given below.

Any help is appriciated. Thanks in advance.

org.xml.sax.SAXException: unable to find FieldDescriptor for 'DigestMethod' in C
lassDescriptor of Reference
        at org.exolab.castor.xml.UnmarshalHandler.startElement(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.startElement(Unknown Sour
ce)
        at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unkn
own Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
t(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(Unknown Source)
        at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
known Source)
        at org.apache.xer! ces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
        at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
        at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
        at org.exolab.castor.xml.Unmarshaller.unmarshal(Unknown Source)
        at edu.sjsu.simmi.project.test.Authorizews.unmarshallMethod(Authorizews.

My XML file is like this:

<?xml version="1.0" encoding="utf-8"?>
  <S:Envelope xmlns:S="http://www.w3.org/2001/12/soap-envelope"
            xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
   <S:Header>
      <m:path xmlns:m="http://schemas.xmlsoap.org/rp/">
       <m:action>http://fabrikam123.com/getQuote</m:action>
        <m:to>http://fabrikam123.com/stocks</m:to>
        <m:id>uuid:84b9f5d0-33fb-4a81-b02b-5b760641c1d6</m:id>
      </m:path>
       <wsse:Security
       &nbs! p;     xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/04/secext">
         <wsse:UsernameToken Id="MyID">
            <wsse:Username>Zoe</wsse:Username>
        </wsse:UsernameToken>
        <ds:Signature>
           <ds:SignedInfo>
              <ds:CanonicalizationMethod
                   Algorithm=
                          "http://www.w3.org/2001/10/xml-exc-c14n#"/>
              <ds:SignatureMethod
                        Algorithm=
                        "http://www.w3.org/2000/09/xmldsig#hmac-sha1"/>
              <ds:Reference URI="#MsgBody">
                  <ds:DigestMethod
                        !   Algorithm=
                        "http://www.w3.org/2000/09/xmldsig#sha1"/>
                <ds:DigestValue>LyLsF0Pi4wPU...</ds:DigestValue>
              </ds:Reference>
            </ds:SignedInfo>
          <ds:SignatureValue>DJbchm5gK...</ds:SignatureValue>
           <ds:KeyInfo>
               <wsse:SecurityTokenReference>
       &n! bsp;       <wsse:Reference URI="#MyID"/>
               </wsse:SecurityTokenReference>
           </ds:KeyInfo>
        </ds:Signature>
      </wsse:Security>
   </S:Header>
   <S:Body Id="MsgBody">
   <tru:StockSymbol xmlns:tru="http://fabrikam123.com/payloads">
              QQQ
          </tru:StockSymbol>
  </S:Body>
 </S:Envelope>
 
 My Java file is like this:

package edu.sjsu.simmi.project.test;

import edu.sjsu.simmi.project.schema.wsse.*;
import org.exolab.castor.xml.*;
import org.exolab.castor.mapping.*;
import java.io.*;
import java.util.Enumeration;

public class Authorizews
{
    public static void main(String[] args)
    {
 try
     {
  // Create the unmarshaller and use default mapping file
  Unmarshaller unmarshaller = new Unmarshaller(Envelope.class);
  Envelope envelope = (Envelope) unmarshaller.unmarshal
  (new FileReader("C:\\sharma_simmi\\Final Project\\Project\\classes\\edu\\sjsu\\simmi\\project\\test\\wssecurity1.xml"));

  Authorizews authorize = new Authorizews();
  authorize.processHeader(envelope.getHeader());
     processBody(envelope.getBody());

     }
 catch(Exception ex)
     {
  ex.printStackTrace();
     }
    }

    public void processHeader(Header header)
    {
  int count = header.getAnyObjectCount();
  System.out.println("Inside Header. Headercount: " + count);
  java.lang.Object obj;
  for(int i=0;i< count;i++)
  {
   obj = header.getAnyObject(i);
   System.out.println("Obj is " + obj);
   if(obj instanceof Security)
   {
    System.out.println("Obj is security");
    processSecurity((Security) obj);
   }
  }
 }
/*processSecurity Method */
 void processSecurity(Security security)
 {
  int count = security.getAnyObjectCount();
  System.out.println("Inside Security. Securitycount: " + count);
  java.lang.Object obj;
  /*for(int i=0;i< count;i++)
&nb! sp; {
   obj = security.getAnyObject(i);
   if(obj instanceof UsernameToken)
   {
    System.out.println("Obj is UsernameToken");
    processUsernameToken((UsernameToken) obj);
   }
   if(obj instanceof Signature)
   {
    System.out.println("Obj is Signature");
    processSignature((Signature) obj);
   }
  }*/
 }


/*processUsernameToken Method */
 void processUsernameToken(UsernameToken usernameToken)
 {
  System.out.println("UsernameToken");
 }

/*processSignature Method */
 /*void processSignature(Signature signature)
 {
  System.out.println("Signature");
 }*/

}

 John Weir <[EMAIL PROTECTED]> wrote:

Sharma,
 
I think your4 problem relates to the fact that the Elements and Types both resolve to the same class file. (Check this by cleaning the output running the generator without the -f flag) .
 
You can solve this quite easily by using the binding file to add a suffix to the names of the complex types. You need to pass a binding file similar to the one below to make this work ( add -binding-file to the source generator command line)
 
This will mean that the Element 'Header' will map to Header.java and ComplexType 'Header' will map to HeaderType.java
 
HTH
 
John
 

<?xml version="1.0" encoding="UTF-8"?>
<!--Sample XML file generated by XML Spy v4.4 U (http://www.xmlspy.com)-->
<binding xmlns="http://www.castor.org/SourceGenerator/Binding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.castor.org/SourceGenerator/Binding c:\castor\src\main\org\exolab\castor\builder\binding\binding.xsd">
 <namingXML>
  <complexTypeName>
   <suffix>Type</suffix>
  </complexTypeName>
 </namingXML>
</binding>

-----Original Message-----
From: simmi sharma [mailto:[EMAIL PROTECTED]
Sent: 16 March 2003 09:12
To: [EMAIL PROTECTED]
Subject: [castor-dev] Problem Unmarshalling Soap-envelope using Castor

Hi,

I am not able to compile the Java files, which I get after unmarshalling Soap-envelope xsd file using Castor.I am using this soap-envelope schema:

http://schemas.xmlsoap.org/soap/envelope/

When I create java files, these files have problem that the header, envelope and body file have circular referencing. It is like "Header extends Header". To solve this I tried removing type="tns:Envelope" from 

 <xs:element name="Envelope" type="tns:Envelope"/>

The number of compilation errors reduced but still it does not work. Another thing I noticed that the java files created do not have marshalling/unmarshalling methods.

Am I using the wrong file? I could do Marshalling/unmarshalling with a lot of other files, but i don't know why this is not working.

Any help is appriciated.

-Simmi.

 

Reply via email to