Castor Unmarshalling Problem
Hi,
am using Castor to unmarshall XML to java objects.
Am facing a problem here. Say my XML to be unmarshalled is:
<Main>
<Students Name="Science">
<Student>
<Name>Tom</Name>
<Roll>1</Roll>
<Hobby>music</Music>
</Student>
<Student>
<Name>Dick</Name>
<Roll>2</Roll>
<Hobby>sports</Hobby>
</Student>
<Student>
<Name>Stella</Name>
<Roll>3</Roll>
</Student>
</Students>
</Main>
Please notice, in the above XML, <Hobby> subelement is missing in the 3rd as it is marked aptional in the XML DTD.
After unmarshalling this XML document using the below mentioned mapping ...i am getting this <Hobby> element's content as that of the immediate prceeding <Student> element's <Hobby> element, i.e "Sports"..whereas i want it to be blank.
Please mention whether i need to make any modification in this mapping XML or not.
<?xml version="1.0"?>
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Object Mapping DTD Version 1.0//EN" "http://castor.exolab.org/mapping.dtd">
<mapping>
<description>mapping file</description>
<class name="Student">
<map-to xml="Student"/>
<field name="Name" type="string" />
<field name="Roll" type="string" />
<field name="Hobby" type="string" />
</class>
<class name="Students">
<map-to xml="Students"/>
<field name="Name" type="string" >
<bind-xml name="Name" node="attribute" />
</field>
<field name="Student" get-method="getStudentList" set-method="setStudentList" type="Student" collection="collection" />
</class>
<class name="Main">
<map-to xml="Main"/>
<field name="Students" get-method="getStudentsList" set-method="setStudentsList" type="Students" collection="collection"/>
</class>
</mapping>
Ehem.. perhaps I should try InputSource before discarding it as useless. The problem solved itself :-)
Similar Messages
-
Unmarshalling problem with special characters (Trademark, French
I'm using a DefaultHandler class to create a StringBuffer which contains a single (though very complex) element from an XML file. I am unmarshalling this StringBuffer object to a JAXBContext like this:
u.unmarshal( new StreamSource( new StringReader( sb.toString() ) )
My special characters are going way out of whack (please read (TM) as the Trademark symbol)
T-Force(TM) Ring(TM) Bonded iron construction for durability and longer life
becomes
T-Force���Ring ��� Bonded iron construction for durability and longer life
Before I put anything else into the StringBuffer I put this in:
sb.append("<?xml version=\"1.0\" encoding=\"iso-8859-15\"?>");
But I've tried:
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
and
sb.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
with different, but wrong, results.
It's true that I'm viewing these results on a web page, so it's possible that the problem is occurring on the back end once I persist the data, but it looks like my database is set for UTF-8 (that's what I put for this new installation of Oracle 9i R2).
Is there something basic I am missing. Like, perhaps, I need to do some sort of XML entity coding?
Thank you very much for any help you can offer.Actually I had forgotten one additional thing. I have
tried testing one thing at a time, and I have sent the
special characters to the log file with logger.debug
statements (log4j). The characters are screwed up in
the log files, which is what makes me think I need to
do some sort of entity encoding. (?)I don't think that log4j provides any way to declare the encoding it uses for your files. My guess is that it's using the default encoding for your system, which could be a problem for things like the trademark character. So log4j really gives you just another thing to test, rather than acting as a testing tool.
I was thinking of a more low-level test, where you take your trademark character, which is 2022 or some such number (check the Unicode charts) and you write it to the database and read it back. Do you get the same character back? That sort of testing. -
Hi
I have a problem with unmarshalling.
when my XML document is valide ,there is no probem but when the document is not valid(for exemple i put a String value in an element of type xs:decimal) i get a strange result:I thought that i will get a java.lang.NumberFormatException when i set the java attribute mapped with that element or i get the error value but this attribute get null as value and there is no NumberFormatException.riadhhwajdii wrote:
Is there any way to modify this default behavior for jaxb to make it show the error value or get a java exceptionyes, see [this post|http://forums.sun.com/thread.jspa?messageID=11031834#11031834]
Edited by: jtahlborn on Aug 8, 2010 10:01 AM -
Castor unmarshalling and encoding
Usually I would post this at the Castor - forums, but they do not exist anymore. I always found Mailing lists suspect and cumbersome, so instead I will give it a shot here:
My goal is to read an xml file with the proper encoding as defined in the XML PI, using castor. The org.jdom.input.SAXBuilder uses the Encoding defined in the PI to read the XML file with the proper encoding. The Unmarshaller in Castor does not.
The Unmarshaller methods use 3 different XML sources, either java.io.Reader, org.xml.sax.InputSource or org.w3c.dom.Node. When using a Reader I must know beforehand what Encoding it should use. I thought of using a pre-parser which reads the PI before creating a Reader with the proper encoding. Does this sound like a fair solution, or have I missed something? Is there already any existing tools/libraries/classes which can read the PI of an XML file without much overhead?Ehem.. perhaps I should try InputSource before discarding it as useless. The problem solved itself :-)
-
I have been having a serious problem implementing an RPC web service which needs
to return
arrays of Java Beans nested three layers deep. In order to simplify the problem,
I constructed these
simple Java Beans (abbreviated here):
Class A
B[] bArray;
Class B
C[] cArray;
Class C
String value;
Then I wrote a client similar to this:
C c = new C();
c.setValue("Dave");
C[] cArray = new C[2];
cArray[0] = c;
cArray[1] = c;
B b = new B();
b.setCArray(c);
B[] bArray = new B[2];
bArray[0] = b;
bArray[1] = b;
A a = new A();
a.setBArray(b);
C c1 = service.getC(c):
B b1 = service.getB(b);
A a1 = service.getA(a);
In my web service, I have three methods:
C getC(C);
B getB(B);
A getA(A);
All these do is return the objects they are sent.
When getC is called, it works fine. In the verbose mode, you can see that the
XML sent
and received is the same. getB also works fine.
But getA does not work. The response is abbreviated and contains nulls. It appears
that
the data is not being unmarshalled/unserialized correctly on the server side.
This is a serious problem that has my project in jeopardy. Please advise,
Dave Mrozekplease use spaces instead of tabs :
why did you convert a date, which is formatted in your DD-MON-RR - format, back to date with the format DD-MM-RR ?
try this: I reformatted it, so that you can better read it :
CURSOR cur_first IS
SELECT a.item_code,
b.item_description,
a.lot_no,
d.name model,
c.vendname,
date_of_purchase,
warrenty_upto,
quentaty,
rate,
pc_type,
decode (warrenty_flag_yn, 'W', TO_DATE (warrenty_upto, 'DD-MON-RR'),
'A', TO_DATE ('31-MAR-' || v_year, 'DD-MON-RR'),
'X', TO_DATE ('31-MAR-' || v_year, 'DD-MON-RR')
) AS amc_date
FROM pc_item_procurement_history a,
pc_item_master b,
pc_vendor_master c,
pc_model_master d
WHERE ...and I think you have a problem in the where clause. Are you sure, that the string warrenty_upto has the format DD-MM-RR. Or has it the format DD-MON-RR ?
(TO_DATE(a.warrenty_upto,'DD-MM-RR') -
JAXB unmarshall problem - beginner
Hi Im having real pain trying to get unmarshall to work with JAXB with a very simple set up..
My DTD looks like
<!ELEMENT CXMLRESULT (MESSAGE)>
<!ELEMENT MESSAGE (#PCDATA)>
and xjs like
<xml-java-binding-schema version="1.0ea">
<element name="CXMLRESULT" type="class" root="true">
</xml-java-binding-schema>
I create an object marshall it and output to a file.. All looks good. This results in the following in the file..
<CXMLRESULT>
<MESSAGE>hello</MESSAGE></CXMLRESULT>
However when I try to read in that file and unmarshall it I run into problems.. Although I receive NO error during the unmarshall, when I do a toString() afterwards then it does not display the MESSAGE element, and similarly trying to validate the object says that MESSAGE hasn't been detected.. I cannot figure out why this is.. The file was written out by JAXB so how come it cant read it back in.. For my unmarshall I do ...
CXMLRESULT cxmlresult=new CXMLRESULT();
try{
try{
input=new File("/in.xml");
fileInputStream=new FileInputStream(input);
} catch (IOException e)
{ System.out.println("error with file"); }
cxmlresult.unmarshal(fileInputStream);
} catch(UnmarshalException e) {
e.printStackTrace();
System.out.println(cxmlresult.toString());
Doing this just shows a CXMLRESULT and not the MESSAGE element..
Any ideas ?
MarkTry this:
CXMLRESULT cxmlresult = CXMLRESULT.unmarshal(fileInputStream);Dave -
Using SOAP-JMS binding for business process
Hi all,
We are currently designing one business process which consume MQ messages. The MQ message body is SOAP XML. SOAP Headers carry business specific important data section, so we don't want to loose these headers at any cost. The message consumer is the Websphere process choreographer business process, reading message as a JMS message. When we develop the business process, we are planning to use SOAP-JMS binding. But problem with SOAP-JMS binding is: when the MDB reads the message off the message queue, it strips off all the SOAP headers and delivers only the SOAP body. Is there a way to make this behaviour change to keep the SOAP headers? You may suggest to use JMS bindings, but JMS binding will send the message body as WSIF message (as a serialized java object). I'm not sure of how easy it is to marshalling/unmarshalling of this serialised object. My main concern is around, how to identify the "type" of the message while marshalling. Would writing our own MDB solve the problem? Again MDB's sends messages as WSIF messages to the business process EJB's, which I guess I get stumble across the same marshal/unmarshall problem. Hope I made myself clear of what i'm going trying to do. Any advice is highly appreciated.
Regards,
PrasadHello Markus,
I just paste my answer form the other forum entry Re: Business process management strategy in SAP?
in a nutshell BPM Netweaver is focussing on so called edge-processes (usually
SOA-based and often workflow related). These edge-processes a thought to enhance exisitng core business processes and should provide the fast competitive edge versus competitors. Examples would be also xApps. For this Netweaver provides process modelling tools, where you can get exectuable code through the integration between CE and PI. The monitoring part for these processes is mainly targeting business end-users and business manager.
Business Process Monitoring with Solution Manager focusses on core business processes which are realized with the "conventional", "old" SAP Architecture, e.g. Order-to-Cash or Procure-to-Pay. You get a combination of technical monitors (average response times of transactions, background job runtimes, monitors for IDOC or qRFC processing) and application related monitors (you get more than 200 pre-configured application monitors out-of-the-box like number of overdue customer orders or outbound deliveries or number of deliveries with goods issue posted but no invoice). The target group here is the support organization of the customer, from Basis-Support over application support on IT side to process owner on business department side.
Overview presentations can be found under
https://service.sap.com/bpm --> Media Library --> Customer Information -->
"Business Process Monitoring - Part 1 & 2".
Or look under https://www.sdn.sap.com/irj/sdn/nw-processmonitoring
In the end BPM Netweaver and BPMon SolMan are complementary for different purposes and different target groups.
Best Regards
Volker -
Unmarshalling with Castor problem
Hello everyone, i have run into a small problem with unmarshalling. Lets say my xml is something like this:
<Client>
<Name>a</Name>
<Something>b</Something>
</Client>Then everything works, i unmarshal it into a Client Object.
public class Client{
//getters and setters
}Also i have a mapping, but now if my XML is something like this:
<Book>
<Page1>
<Client>
<Name>a</Name>
<Something>b</Something>
</Client>
</Page1>
</Book>Then what would the mapping be and how do i get the Client object out of it. I tried creating a class for every element.
like
public class Book{
getBook(){
//return the book object
}Then
public class Page{
getPage(){
//return the page
}So to get the client object i first unmarshalled the Book object, then i did Book.getPage().getClient().getName(); And then i got Nullpointer exception. How do i parse documents like that?
Thankshere is the weird thing though...in my debugconsole,
I can see the value of source, cuz the content of my
XML file is in the source, but the
parser.parse(source) is called, the content of my
source is NULL...and I think that is why I amgetting
null on my service result every time...I'm not sure what you mean here. You are saying that
you can see the source in a variable (???) and then in
another variable it's null or what?sorry...My bad....no...
parser.parse(InputSource source)...does that sound more clear???
You know how you can see the stack in debug console, what i saw before the Parser.parse(InputSource source) called is
source->characterStream:java.io.reader->str: <xml version='1.2'><name>moe</name><last name>zoe</lasname>...
HOwever, after the Parser.parse(InputSource source) is called, i inspected the stack again, i got
source->characterStream:java.io.reader->str: NULL
that is why i suspect that i got a null serviceResult on my return...
any ideas?? how that happened?? many thanks... -
Problem with castor xml mapping
Hi,
we have following problem with castor xml mapping.
How to use references in the collections(Hashmap or vector)?
WE have a method called getAttribute map which will return a hashmap consist different type of objects. We want to keep only the
references of objects if that object occurs more than once,instead of keeping the whole object
Following is the the xml mapping file.
<mapping>
<class name="com.opvista.ndtool.core.mos.ManagedObject" identity="Id" auto-complete="false" verify-constructable="false">
<map-to xml="ManagedObject"/>
<field name="Id" get-method="getId" set-method="setId" type="string">
<bind-xml name="Id" node="attribute"/>
</field>
<field name="AttributeMap" type="org.exolab.castor.mapping.MapItem" collection="map" get-method="getAttributeMap">
<bind-xml name="AttributeMap" node="element">
<class name="org.exolab.castor.mapping.MapItem">
<field name="key" type="java.lang.Object">
<bind-xml name="key" node="attribute"/>
</field>
<field name="value" type="java.lang.Object">
<bind-xml name="value" node="element" reference="true"/>
</field>
</class>
</bind-xml>
</field>
</class>
</mapping>
we are using reference=true for the values. But it will throw below exception.
Unable to resolve ID for instance of class 'java.lang.String' due to the following error: Unable to resolve ClassDescriptor.
at org.exolab.castor.xml.Marshaller.getObjectID(Marshaller.java:1988)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1628)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1831)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1814)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:1825)
at org.exolab.castor.xml.Marshaller.marshal(Marshaller.java:821)
Please help us to overcome from this problem?
Thanks,
Dileepfor your ref here is what i think the basic mapping file would look like
<class name="Person">
<map-to xml="person"/>
<field name="name" type="string">
<bind-xml name="name" node="attribute" />
</field>
<field name="age" type="string">
<bind-xml name="age" node="attribute" />
</field>
</class>
<class name="MetaPerson">
<map-to xml="person"/>
<field name="dependents" type="string">
<bind-xml name="dependents" node="attribute" />
</field>
<field name="presentAdd" type="string">
<bind-xml name="present_add " node="attribute" />
</field>
<field name="permanentAdd" type="string">
<bind-xml name="permanent_add " node="attribute" />
</field>
</class>
however i am still not clear as to how i can use the metaperson object in the person class as well as in the mapping file.
hope this gives a better idea abt my problem statement.
Please help me out -
XML binding(maping) "Castor" problem ...
Hello Dear Sirs !
I am using the the "Castor" project for XML Binding purposes .
It was really good idea to create this stuff .
I tried to use it in my programs and just surprised how your project really tailored to XML programmers needs .
But a some time ago I have encountered with some Parsing problem ....
May be my quastion is to stooped , but i still can not find an answer .
I have to parse From Java Class to XML and Vice Versa next kind of XML :
************************ First Question *****************************************
<Inputs>
< Line LineNumber = '0'
Selected 'yes'
Attribute='Value of Attribute'
IDFormat='Format to Apply'
<Value Name ='Rate'>4.89</Value>
<Value Name ='Subscribtion'>yes</Value>
<Value Name ='EnrolmentDate'>12.12.2002</Value>
<Value Name ='ProviderName'>Somebody</Value>
</Line>
< Line LineNumber = '1'
Selected 'no'
Attribute='Value of Attribute'
IDFormat='Format to Apply'
<Value Name ='Queue'>2Q</Value>
<Value Name ='IVR'>yes</Value>
<Value Name ='EnrolmentDate'>31.12.2002</Value>
</Line>
< Line LineNumber = '3'
Selected 'yes'
Attribute='Value of Attribute'
IDFormat='Format to Apply'
<Value Name ='CustomerName'>NA</Value>
<Value Name ='Vacancy'>yes</Value>
</Line>
</Inputs>
************************ End of First Question ***************************
*********************** Second Question ***************************
<Inputs>
Value< ItemAttribute = 'CurentItemAttribute' ItemProperty =' ItemProperty' >
Value<ItemAttribute = 'CurentItemAttribute' >
Value<ItemProperty =' ItemProperty' >
Value< ItemAttribute = 'CurentItemAttribute' ItemProperty =' ItemProperty' >
Value<ItemAttribute = 'CurentItemAttribute' >
Value< ItemAttribute = 'CurentItemAttribute' ItemProperty =' ItemProperty' >
Value< ItemAttribute = 'CurentItemAttribute' ItemProperty =' ItemProperty' >
</Inputs>
*********************** End of Second Question ***************************
And I dont know How I can MAP these XML formats to Java Classes and vice versa .........
(to my pitty It is not my idea to assemble it in this manner and this is not given to some improvement change .... )
In your examples all things look so simple and understandable ... but I have no idea about my case .....
Please , help me with this ....
Are these kinds of XML can be really somehow binded and work together with "Castor" ?
It it really possible to do these things ?
I will really appreciate your attempt to help me .
Thank you ,
MaratTo create class file for binding in castor, your first step is to create an XML Schema or .xsd file. Then assuming it is installed correctly type: java org.exolab.castor.builder.SourceGenerator -i whatever.xsd -package com.xyz.myxml.castor
This would create the java class file in the package com.zyx.myxml.castor that corresponds to your XML schema -
[Castor] Problem with the namespace
Hello,
I'm using Castor for generate XML file with Java Object(generate with Castor with XSD).
I have a problem with the syntax and particulary with the reference of the namespace.
I obtain this :
<?xml version="1.0" encoding="UTF-8"?>
<TEST ID="">
<ns1:PERSON xmlns:ns1="http://www.w3.org/a/">
<ns1:CALCUL>
<ns1:SOURCE>RED</ns1:SOURCE>
<ns1:TIMESTAMP>2004-10-27-11.38.25.237113</ns1:TIMESTAMP>
</ns1:CALCUL>
<SIREN>666</SIREN>
<ns1:DOSSIER>
<ns1:TYPE>DN</ns1:TYPE>
<ns1:IDENTIFIANT>333</ns1:IDENTIFIANT>
</ns1:DOSSIER>
</ns1:PERSON>
<ENTITY>
<COMMON>
<ns2:ENTITY_ID xmlns:ns2="http://www.w3.org/a/">602449226</ns2:ENTITY_ID>
<ns3:RATING xmlns:ns3="http://www.w3.org/a/">NDE</ns3:RATING>
</COMMON>
<SPECIFICS_DATA>
<ns4:RATING_FC xmlns:ns4="http://www.w3.org/a/">2-</ns4:RATING_FC>
</SPECIFICS_DATA>
</ENTITY>
</TEST>
but I'd like to obtain :
<TEST ID="">
<PERSON >
<CALCUL>
<nSOURCE>RED</SOURCE>
<TIMESTAMP>2004-10-27-11.38.25.237113</TIMESTAMP>
</CALCUL>
<SIREN>666</SIREN>
<nDOSSIER>
<TYPE>DN</TYPE>
<IDENTIFIANT>333</IDENTIFIANT>
</DOSSIER>
</PERSON>
<ENTITY>
<COMMON>
<ENTITY_ID >602449226</ENTITY_ID>
<RATING>NDE</RATING>
</COMMON>
<SPECIFICS_DATA>
<RATING_FC >2-</RATING_FC>
</SPECIFICS_DATA>
</ENTITY>
</TEST>
"http://www.w3.org/a/" is the namespace reference in the xsd, here the begin of the xsd:
<xs:schema xmlns:FIN_Referential="http://www.w3.org/c/" xmlns:Rating_Referential="http://www.w3.org/f/" xmlns:Global_Referential="http://www.w3.org/a/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
To marshall I use this code :
StringWriter fluxXmlSw = new StringWriter() ;
Marshaller mar = new Marshaller(fluxXmlSw);
mar.marshal(Test(),fluxXmlSw);
//Test() is the root element of the file xml
I hope somebody could help me, it's urgent I solve this problem.
Thanks for all responsesjust a thought..... did u try removing xmlns:p1="http://ofcom.co.uk/unify/CustomerMaster" from your WSDL file ?
Try to remove that and proceed in your development. -
Problem unmarshalling xml using JAXB
I am using JAXB for processing xml, which comes from an external source. Most often, the xml gets changed from external source which causes the error during unmarshalling as the xsd has not changed. Is there a way to process the xml in same way even if xsd hasn't changed, like converting new xml to one as per xsd etc. Someone has mentioned using xslt, but I would like to get more ideas on any other technologies or third party tools to overcome this issue so that I do not have to reply upon changing xsd everytime. Thanks
Most often, the xml gets changed from external source which causes the error during unmarshalling as the xsd has not changed.So, you've got garbage input. Your goal should be to stop that from happening rather than trying to make it work.
so that I do not have to reply upon changing xsd everytimeIf you have to keep changing the schema then perhaps JAXB wasn't a suitable technology choice here. Or maybe the design wasn't done properly. Or maybe (see earlier comment) the input files aren't being produced properly. At any rate you need to fix the underlying problem before writing code. -
I used xjc to generate a set of elements from the schema shown below:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.doc.state.nc.us/doccodes" xmlns="http://www.doc.state.nc.us/doccodes" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
<xsd:element name="codeTable" type="CodeTable"/>
<xsd:element name="codeRequest" type="CodeRequest"/>
<xsd:complexType name="CodeTable">
<xsd:sequence>
<xsd:element name="codename" type="xsd:string"/>
<xsd:element name="codes" type="Codes"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Codes">
<xsd:sequence>
<xsd:element name="code" type="Code" minOccurs="1" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="Code">
<xsd:sequence>
<xsd:element name="identifier" type="xsd:string"/>
<xsd:element name="description" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="CodeRequest">
<xsd:sequence>
<xsd:element name="application" type="xsd:string"/>
<xsd:element name="token" type="xsd:string"/>
<xsd:element name="codename" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I have successfully been able to marshall an xml file using the following code:
jc = JAXBContext.newInstance( "nc.doc.nexus.code.jaxb.model");
CodeTable codeTable = new CodeTable();
Codes facilityCodes = new Codes();
List<Code> codeList = facilityCodes.getCode();
codeList.addAll(persistables); // where persistables is an ArrayList of Code objects
codeTable.setCodes(facilityCodes);
codeTable.setCodename("facilityCode");
JAXBElement<CodeTable> codeTableElement = (new ObjectFactory()).createCodeTable(codeTable);
Marshaller m = jc.createMarshaller();
m.setProperty( Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE );
m.marshal(codeTableElement, System.out);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db;
try {
db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
m.marshal(codeTableElement, doc);
return doc;
catch (ParserConfigurationException e) {
The marshalling works just fine, and results in the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<ns1:codeTable xmlns="http://www.doc.state.nc.us/doccodes" xmlns:ns1="http://www.doc.state.nc.us/doccodes">
<ns1:codename>
facilityCode </ns1:codename>
<ns1:codes>
<ns1:code>
<ns1:identifier>
X001 </ns1:identifier>
<ns1:description>
DHO DISTRICT 1 </ns1:description>
</ns1:code>
<ns1:code>
<ns1:identifier>
X002 </ns1:identifier>
<ns1:description>
DHO DISTRICT 2 </ns1:description>
</ns1:code>
<ns1:code>
<ns1:identifier>
X003 </ns1:identifier>
<ns1:description>
DHO DISTRICT 3 </ns1:description>
</ns1:code>
</ns1:codes>
</ns1:codeTable>
My code to unmarshall this xml document is as follows:
JAXBContext jc;
try {
jc = JAXBContext.newInstance( "nc.doc.nexus.code.jaxb.model");
Unmarshaller unmarshaller = jc.createUnmarshaller();
JAXBElement<CodeTable> codeTableElement =
(JAXBElement<CodeTable>)unmarshaller.unmarshal(aDocument);
catch (JAXBException e) {
throw new DeserializerException(e);
Now the problem. When I attempt to unmarshall this xml, I get the following UnmarshalException:
unexpected element (uri:"", local:"ns1:codeTable"). Expected elements are <{http://www.doc.state.nc.us/doccodes}codeRequest>,<{http://www.doc.state.nc.us/doccodes}codeTable>
I've made countless attempts to alter the unmarshal code in an attempt to determine if I had just coded it wrong, or whether jaxb is not able to interpret namespaces or schemas correctly. I have to assume the latter at this point. Can anybody shed any light on this?
By the way, below is the xjc generated class CodeTable:
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.0-b26-ea3
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2007.08.22 at 10:42:51 AM EDT
package nc.doc.nexus.code.jaxb.model;
import javax.xml.bind.annotation.AccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import nc.doc.nexus.code.jaxb.model.CodeTable;
import nc.doc.nexus.code.jaxb.model.Codes;
* <p>Java class for CodeTable complex type.
* <p>The following schema fragment specifies the expected content contained within this class.
* <pre>
* <complexType name="CodeTable">
* <complexContent>
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
* <sequence>
* <element name="codename" type="{http://www.w3.org/2001/XMLSchema}string"/>
* <element name="codes" type="{http://www.doc.state.nc.us/doccodes}Codes"/>
* </sequence>
* </restriction>
* </complexContent>
* </complexType>
* </pre>
@XmlAccessorType(AccessType.FIELD)
@XmlType(name = "CodeTable", propOrder = {
"codename",
"codes"
public class CodeTable {
@XmlElement(namespace = "http://www.doc.state.nc.us/doccodes")
protected String codename;
@XmlElement(namespace = "http://www.doc.state.nc.us/doccodes")
protected Codes codes;
* Gets the value of the codename property.
* @return
* possible object is
* {@link String }
public String getCodename() {
return codename;
* Sets the value of the codename property.
* @param value
* allowed object is
* {@link String }
public void setCodename(String value) {
this.codename = value;
* Gets the value of the codes property.
* @return
* possible object is
* {@link Codes }
public Codes getCodes() {
return codes;
* Sets the value of the codes property.
* @param value
* allowed object is
* {@link Codes }
public void setCodes(Codes value) {
this.codes = value;
}UPDATE: I changed the unmarshal code to unmarshal a File instead of a DOM Document, and it works. This is the revelation I was hoping not to come to. I really don't want to have to serialize my Document to a file and then unmarshal that file from disk. This would not be an acceptable solution for a large J2EE application with many web services servicing 10000 clients. Does anybody know why the unmarshal method that accepts a DOM Document does not work?
-
New problem from unmarshalling
I have been encountering problem with unmarshalling when trying to run my RMI server. After reading many of the similar problem threads, I've changed the way running "rmiregistry". Now, I unset CLASSPATH before running rmiregistry before running my Server.
I still get the usual unmarshalling exception
C:\java\projects\rmi_ex2>myRMIServer
C:\java\projects\rmi_ex2>java -Djava.security.policy=wideopen.policy -Djava.rmi.
server.codebase=file:/c:/java/projects/rmi_ex2/ myRMIServer
Exception occurred: java.rmi.ServerException: Server RemoteException; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested excep
tion is: java.lang.ClassNotFoundException: myRMIImpl_Stub
But I also get this from the rmiregistry window
C:\java\projects\rmi_ex2>rmiregistry
security properties not found. using defaults.
Default cache directory c:\j2sdk1.4.1\jcache not found. JAR caching disabled.
MimeTable.load: file = c:\j2sdk1.4.1\lib\content-types.properties, java.io.FileN
otFoundException: c:\j2sdk1.4.1\lib\content-types.properties
java.io.FileNotFoundException: c:\j2sdk1.4.1\lib\content-types.properties
at java.io.FileInputStream.<init>(FileInputStream.java:56)
at java.io.FileInputStream.<init>(FileInputStream.java:75)
at sun.net.www.MimeTable.load(MimeTable.java:212)
at sun.net.www.MimeTable.<init>(MimeTable.java:43)
at sun.net.www.MimeTable.getDefaultTable(MimeTable.java:52)
at sun.net.www.protocol.file.FileURLConnection.connect(Compiled Code)
at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLCon
nection.java:162)
at sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedire
cts(Compiled Code)
at sun.applet.AppletClassLoader.loadClass(Compiled Code)
at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:630)
at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:226)
at sun.rmi.server.RMIClassLoader.loadClass(RMIClassLoader.java:152)
at sun.rmi.server.MarshalInputStream.resolveClass(MarshalInputStream.jav
a:90)
at java.io.ObjectInputStream.inputClassDescriptor(ObjectInputStream.java
:711)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:328)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:225)
at java.io.ObjectInputStream.inputObject(Compiled Code)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:344)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:225)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(RegistryImpl_Skel.java:98
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:164)
at sun.rmi.transport.Transport.serviceCall(Transport.java:154)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Compiled Code)
at sun.rmi.transport.tcp.TCPTransport.run(Compiled Code)
at java.lang.Thread.run(Thread.java:466)
Any tips, ideas would be greatly appreciated as I have spend days on this problem!
KuHi,
you should try to use:
1) Server
java -Djava.security.policy=wideopen.policy
-Djava.rmi.server.codebase=file:c:\java\projects\rmi_ex2\
myRMIServer
2) Client
java -Djava.security.policy=wideopen.policy
-Djava.rmi.server.codebase=file:c:\java\project\rmi_ex2\
RMIClient
Bye
Filippo -
Unmarshalling arguments Problem
I'm new to RMI. I opened the rmi registry on windows , tried to run my server , but every time I run this server I get the exception:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmi.MyRemoteServer
at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
.........Here is the code of my Remote Interface:
package rmi;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface MyRemoteServer extends Remote{
String sayHi() throws RemoteException;
}and here is the code of my simple Server:
package rmi;
import java.rmi.RemoteException;
public class Server implements MyRemoteServer{
public String sayHi() {
return "Hi , I'm the fuckin' server.";
public Server() throws RemoteException{
super();
}I searched for the answer and I noticed there is something called code base, Is this my problem ,If any one has an idea please let me know.Thanks I used c , and it worked , but when I tried to run the client I got an exception:
java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:5000 connect,resolve)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at java.lang.SecurityManager.checkConnect(SecurityManager.java:1034)and here is the code of the client:
package rmiclient;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
public class Client {
public static void main(String[] args) {
if(System.getSecurityManager()==null){
System.setSecurityManager(new SecurityManager());
try{
Registry reg = LocateRegistry.getRegistry(5000);
MyRemoteServer server = (MyRemoteServer) reg.lookup("HelloServer");
System.out.println(server);
}catch(Exception e){
e.printStackTrace();
}do you know what should I do?
Maybe you are looking for
-
Anamorphic in a 16:9 Timeline?
I have a short 16:9 720p project in which I'm dropping in a few standard def 16:9 Anamorphic components. What's the best procedure to unsqueeze the Anamorphic pieces?
-
Hello users, Can somebody tell me, 1. what is the difference between workflow and a webflow. 2. When do we use a workflow and when do we go for a webflow ? 3. which one is the latest technology. For ex, Smartforms are more recent than SAP scripts. T
-
Good news! I'm happy to announce that we've launched our shiny new Billing and Payment pages. You can view them now, here: http://ee.co.uk/help/accounts-billing-and-topping-up/billing-and-payment A few things to keep an eye on include: Separated con
-
Quicktime 7.4.1 / 7.4.5 file type association
Hello, I have upgraded quickime 7.1.3 to 7.4.5. Since then, I've got a problem with the file type associations. I can add new ones without problem, but I can't remove them. when I choose the default associations, click apply, click ok. And open the p
-
I've been bitten by the "Missing MSVCR.dll file" problem when downloading the latest iTunes update, 11.4.62 (on a PC w/ Win-7 & Outlook-2007#. 'Have followed Apple's instructions of un-installing all Apple software, and re-installing it (Ugh). First