java - Jersey REST date @XmlAttribute causing an illegal argument exception -
i have jersey rest web service takes in posted xml string. have entities each element of xml split them objects. when pass date parameter e.g. inspectiondate="12/02/2012" following error.
severe: servlet.service() servlet [jersey rest service] in context path [] threw exception java.lang.illegalargumentexception: 12/02/2012 @ com.sun.org.apache.xerces.internal.jaxp.datatype.xmlgregoriancalendarimpl$parser.parseandsetyear(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.datatype.xmlgregoriancalendarimpl$parser.parse(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.datatype.xmlgregoriancalendarimpl.<init>(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.datatype.datatypefactoryimpl.newxmlgregoriancalendar(unknown source) @ com.sun.xml.bind.datatypeconverterimpl._parsedatetime(datatypeconverterimpl.java:400) @ com.sun.xml.bind.v2.model.impl.runtimebuiltinleafinfoimpl$5.parse(runtimebuiltinleafinfoimpl.java:271) @ com.sun.xml.bind.v2.model.impl.runtimebuiltinleafinfoimpl$5.parse(runtimebuiltinleafinfoimpl.java:273) @ com.sun.xml.bind.v2.runtime.reflect.transducedaccessor$compositetransducedaccessorimpl.parse(transducedaccessor.java:241) @ com.sun.xml.bind.v2.runtime.unmarshaller.structureloader.startelement(structureloader.java:201) @ com.sun.xml.bind.v2.runtime.unmarshaller.unmarshallingcontext._startelement(unmarshallingcontext.java:481) @ com.sun.xml.bind.v2.runtime.unmarshaller.unmarshallingcontext.startelement(unmarshallingcontext.java:459) @ com.sun.xml.bind.v2.runtime.unmarshaller.saxconnector.startelement(saxconnector.java:148) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.startelement(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.scanstartelement(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl$fragmentcontentdriver.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentscannerimpl.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmlnsdocumentscannerimpl.next(unknown source) @ com.sun.org.apache.xerces.internal.impl.xmldocumentfragmentscannerimpl.scandocument(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xml11configuration.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.xmlparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.parsers.abstractsaxparser.parse(unknown source) @ com.sun.org.apache.xerces.internal.jaxp.saxparserimpl$jaxpsaxparser.parse(unknown source) @ com.sun.xml.bind.v2.runtime.unmarshaller.unmarshallerimpl.unmarshal0(unmarshallerimpl.java:211) @ com.sun.xml.bind.v2.runtime.unmarshaller.unmarshallerimpl.unmarshal(unmarshallerimpl.java:184) @ javax.xml.bind.helpers.abstractunmarshallerimpl.unmarshal(unknown source) @ javax.xml.bind.helpers.abstractunmarshallerimpl.unmarshal(unknown source) @ com.sun.jersey.core.provider.jaxb.abstractrootelementprovider.readfrom(abstractrootelementprovider.java:124) @ com.sun.jersey.core.provider.jaxb.abstractrootelementprovider.readfrom(abstractrootelementprovider.java:97) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequest.java:393) @ com.sun.jersey.server.impl.model.method.dispatch.entityparamdispatchprovider$entityinjectable.getvalue(entityparamdispatchprovider.java:139) @ com.sun.jersey.server.impl.inject.injectablevaluesprovider.getinjectablevalues(injectablevaluesprovider.java:43) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemethoddispatchprovider$entityparamininvoker.getparams(abstractresourcemethoddispatchprovider.java:126) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemethoddispatchprovider$responseoutinvoker._dispatch(abstractresourcemethoddispatchprovider.java:173) @ com.sun.jersey.server.impl.model.method.dispatch.resourcejavamethoddispatcher.dispatch(resourcejavamethoddispatcher.java:67) @ com.sun.jersey.server.impl.uri.rules.httpmethodrule.accept(httpmethodrule.java:163) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:111) @ com.sun.jersey.server.impl.uri.rules.resourceclassrule.accept(resourceclassrule.java:71) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:111) @ com.sun.jersey.server.impl.uri.rules.rootresourceclassesrule.accept(rootresourceclassesrule.java:63) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:654) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:612) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:603) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:309) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:425) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:590) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:98) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1040) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:607) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:313) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source)
here xml string:
<?xml version='1.0' encoding='utf-8' standalone='yes' ?> <user username="test.test" userid="43"> <client> <site> <building> <location> <asset assetid="293"> <inspection assetid="293" inspectiondate="12/02/2012" inspectionref="inspection_ref_89158"> <comments>test</comments> <assessedby>natasha allsopp</assessedby> <assessed>false</assessed> <notassessedreason>access hatch padlocked<notassessedreason> <acceptable>true</acceptable> <remedialactionrequired>false</remedialactionrequired> <remedialactionid>0</remedialactionid> <flowtemperature>0.0</flowtemperature> <returntemperature>0.0</returntemperature> <temperature1minhot>0.0</temperature1minhot> <temperature2mincold>0.0</temperature2mincold> <showerheadspresent>4</showerheadspresent> <showerheadscleaned>0</showerheadscleaned> <showersnotcleanedreason></showersnotcleanedreason> <storedwatertemperature>0.0</storedwatertemperature> <incomingmainstemperature>0.0</incomingmainstemperature> <anyleaks>false</anyleaks> <sludgepresent>none</sludgepresent> <corrosionpresent>none</corrosionpresent> <flotsampresent>none</flotsampresent> <turnovercheck>good</turnovercheck> <conditionoftank>good</conditionoftank> <goodfittinglidpresent>false</goodfittinglidpresent> <lidvented>false</lidvented> <ventscreened>false</ventscreened> <overflowpresent>false</overflowpresent> <insectscreen>false</insectscreen> </inspection> </asset> </location> </building> </site> </client> </user>
and here snippet of entity class:
@xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = {"inspectiondate"}) public class inspection { @xmlattribute protected date inspectiondate; @xmlattribute protected string inspectionref; public date getinspectiondate() { return inspectiondate; } public void setinspectiondate(date inspectiondate) { this.inspectiondate = inspectiondate; } }
if use following xmljavaadapter:
public class dateadapter extends xmladapter<string, date> { private simpledateformat dateformat = new simpledateformat("dd/mm/yyyy"); @override public string marshal(date v) throws exception { return dateformat.format(v); } @override public date unmarshal(string v) throws exception { return dateformat.parse(v); } }
i following error:
severe: servlet.service() servlet [jersey rest service] in context path [] threw exception [com.sun.jersey.api.container.mappablecontainerexception: java.io.ioexception: error unmarshalling jaxb object of type "class dao.jpa.user".] root cause com.sun.xml.bind.v2.runtime.illegalannotationsexception: 2 counts of illegalannotationexceptions there 2 properties named "inspectiondate" problem related following location: @ public java.util.date dao.jpa.inspection.getinspectiondate() @ dao.jpa.inspection @ protected dao.jpa.inspection dao.jpa.asset.inspection @ dao.jpa.asset @ protected dao.jpa.asset dao.jpa.location.asset @ dao.jpa.location @ protected dao.jpa.location dao.jpa.building.location @ dao.jpa.building @ protected dao.jpa.building dao.jpa.site.building @ dao.jpa.site @ protected dao.jpa.site dao.jpa.client.site @ dao.jpa.client @ protected dao.jpa.client dao.jpa.user.client @ dao.jpa.user problem related following location: @ protected java.util.date dao.jpa.inspection.inspectiondate @ dao.jpa.inspection @ protected dao.jpa.inspection dao.jpa.asset.inspection @ dao.jpa.asset @ protected dao.jpa.asset dao.jpa.location.asset @ dao.jpa.location @ protected dao.jpa.location dao.jpa.building.location @ dao.jpa.building @ protected dao.jpa.building dao.jpa.site.building @ dao.jpa.site @ protected dao.jpa.site dao.jpa.client.site @ dao.jpa.client @ protected dao.jpa.client dao.jpa.user.client @ dao.jpa.user class has 2 properties of same name "inspectiondate" problem related following location: @ public java.util.date dao.jpa.inspection.getinspectiondate() @ dao.jpa.inspection @ protected dao.jpa.inspection dao.jpa.asset.inspection @ dao.jpa.asset @ protected dao.jpa.asset dao.jpa.location.asset @ dao.jpa.location @ protected dao.jpa.location dao.jpa.building.location @ dao.jpa.building @ protected dao.jpa.building dao.jpa.site.building @ dao.jpa.site @ protected dao.jpa.site dao.jpa.client.site @ dao.jpa.client @ protected dao.jpa.client dao.jpa.user.client @ dao.jpa.user problem related following location: @ protected java.util.date dao.jpa.inspection.inspectiondate @ dao.jpa.inspection @ protected dao.jpa.inspection dao.jpa.asset.inspection @ dao.jpa.asset @ protected dao.jpa.asset dao.jpa.location.asset @ dao.jpa.location @ protected dao.jpa.location dao.jpa.building.location @ dao.jpa.building @ protected dao.jpa.building dao.jpa.site.building @ dao.jpa.site @ protected dao.jpa.site dao.jpa.client.site @ dao.jpa.client @ protected dao.jpa.client dao.jpa.user.client @ dao.jpa.user @ com.sun.xml.bind.v2.runtime.illegalannotationsexception$builder.check(illegalannotationsexception.java:102) @ com.sun.xml.bind.v2.runtime.jaxbcontextimpl.gettypeinfoset(jaxbcontextimpl.java:472) @ com.sun.xml.bind.v2.runtime.jaxbcontextimpl.<init>(jaxbcontextimpl.java:302) @ com.sun.xml.bind.v2.runtime.jaxbcontextimpl$jaxbcontextbuilder.build(jaxbcontextimpl.java:1140) @ com.sun.xml.bind.v2.contextfactory.createcontext(contextfactory.java:154) @ com.sun.xml.bind.v2.contextfactory.createcontext(contextfactory.java:121) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ javax.xml.bind.contextfinder.newinstance(unknown source) @ javax.xml.bind.contextfinder.newinstance(unknown source) @ javax.xml.bind.contextfinder.find(unknown source) @ javax.xml.bind.jaxbcontext.newinstance(unknown source) @ javax.xml.bind.jaxbcontext.newinstance(unknown source) @ com.sun.jersey.core.provider.jaxb.abstractjaxbprovider.getstoredjaxbcontext(abstractjaxbprovider.java:199) @ com.sun.jersey.core.provider.jaxb.abstractjaxbprovider.getjaxbcontext(abstractjaxbprovider.java:177) @ com.sun.jersey.core.provider.jaxb.abstractjaxbprovider.getunmarshaller(abstractjaxbprovider.java:131) @ com.sun.jersey.core.provider.jaxb.abstractjaxbprovider.getunmarshaller(abstractjaxbprovider.java:104) @ com.sun.jersey.core.provider.jaxb.abstractrootelementprovider.readfrom(abstractrootelementprovider.java:97) @ com.sun.jersey.spi.container.containerrequest.getentity(containerrequest.java:393) @ com.sun.jersey.server.impl.model.method.dispatch.entityparamdispatchprovider$entityinjectable.getvalue(entityparamdispatchprovider.java:139) @ com.sun.jersey.server.impl.inject.injectablevaluesprovider.getinjectablevalues(injectablevaluesprovider.java:43) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemethoddispatchprovider$entityparamininvoker.getparams(abstractresourcemethoddispatchprovider.java:126) @ com.sun.jersey.server.impl.model.method.dispatch.abstractresourcemethoddispatchprovider$responseoutinvoker._dispatch(abstractresourcemethoddispatchprovider.java:173) @ com.sun.jersey.server.impl.model.method.dispatch.resourcejavamethoddispatcher.dispatch(resourcejavamethoddispatcher.java:67) @ com.sun.jersey.server.impl.uri.rules.httpmethodrule.accept(httpmethodrule.java:163) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:111) @ com.sun.jersey.server.impl.uri.rules.resourceclassrule.accept(resourceclassrule.java:71) @ com.sun.jersey.server.impl.uri.rules.righthandpathrule.accept(righthandpathrule.java:111) @ com.sun.jersey.server.impl.uri.rules.rootresourceclassesrule.accept(rootresourceclassesrule.java:63) @ com.sun.jersey.server.impl.application.webapplicationimpl._handlerequest(webapplicationimpl.java:654) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:612) @ com.sun.jersey.server.impl.application.webapplicationimpl.handlerequest(webapplicationimpl.java:603) @ com.sun.jersey.spi.container.servlet.webcomponent.service(webcomponent.java:309) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:425) @ com.sun.jersey.spi.container.servlet.servletcontainer.service(servletcontainer.java:590) @ javax.servlet.http.httpservlet.service(httpservlet.java:727) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:303) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:241) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:208) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:220) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:122) @ org.apache.catalina.authenticator.authenticatorbase.invoke(authenticatorbase.java:501) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:170) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:98) @ org.apache.catalina.valves.accesslogvalve.invoke(accesslogvalve.java:950) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:116) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:408) @ org.apache.coyote.http11.abstracthttp11processor.process(abstracthttp11processor.java:1040) @ org.apache.coyote.abstractprotocol$abstractconnectionhandler.process(abstractprotocol.java:607) @ org.apache.tomcat.util.net.jioendpoint$socketprocessor.run(jioendpoint.java:313) @ java.util.concurrent.threadpoolexecutor.runworker(unknown source) @ java.util.concurrent.threadpoolexecutor$worker.run(unknown source) @ java.lang.thread.run(unknown source)
if has ideas, please let me know.
my guess getting two properties...
exception in real class added @xmljavatypeadapter(dateadapter.class)
annotation on method instead of field has @xmlattribute
annotation.
Comments
Post a Comment