Java Mailing List Archive

http://www.junlu.com/

Home » user.castor »

[castor-user] No Introspector defined in properties!

Alvaro

2013-05-29

Replies: Find Java Web Hosting

Author LoginPost Reply
Hi all,

Im trying to create a simple Spring REST app using SpringOXM and Castor for
XML handling. So far so good, the problem is that when sending an XML POST
request to create a contact, Castor crashes complaining that:
<p>Problem accessing /contacts. Reason:
<pre>    Server Error</pre></p><h3>Caused
by:</h3><pre>java.lang.IllegalStateException: No Introspector defined in
properties!

The simple xml Im sending looks like:
<?xml version="1.0" encoding="UTF-8"?>
<contact><name>Sonoo</name><lastName>Jaiswal</lastName></contact>

My mapping.xml:
<?xml version="1.0"?>
<mapping>
 <class name="com.test.model.Contact">
    <map-to xml="contact"/>
    <field name="name" type="string">
       <bind-xml name="name" node="element"/>
    </field>
    <field name="lastName" type="string">
       <bind-xml name="lastName" node="element"/>
    </field>
 </class>
</mapping>

The Spring configuration:
    <context:component-scan base-package="com.test />

    <!-- REST service -->
    <bean

class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
        <property name="messageConverters">
            <util:list id="beanList">
                <ref bean="castorMarshallingHttpMessageConverter" />
            </util:list>
        </property>
    </bean>

    <bean id="castorMarshallingHttpMessageConverter"

class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
        <property name="marshaller" ref="castorMarshaller" />
        <property name="unmarshaller" ref="castorMarshaller" />
    </bean>

    <bean id="castorMarshaller"
class="org.springframework.oxm.castor.CastorMarshaller">
        <property name="mappingLocation"
            value="classpath:com/test//model/mapping.xml" />
    </bean>

And finally the controller looks like:

package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.http.HttpStatus;

@Controller
@RequestMapping("/contacts")
public class ContactsController {


   @RequestMapping(value="/{name}", method = RequestMethod.GET)
   @ResponseStatus(HttpStatus.OK)
   @ResponseBody
   public Contact getContact(@PathVariable String name) {
      Contact c = new Contact();
      c.setName(name);
      c.setLastName("test");
      return c;
   }


   @RequestMapping( method = RequestMethod.POST )
   @ResponseStatus( HttpStatus.CREATED )
   @ResponseBody
   public Long create( @RequestBody Contact contact ){
         System.out.println("Contact " + contact.getName());
      return 1L;
   }

}


As you see its a quick and dirty test to try out Castor and Spring OXM.

Actually, a GET request to the getContact method works and the xml is
returned, so the mapping.xml is loaded correctly.

Do you have any idea why Castor is crashing when unmarshalling the POST
request xml??

Thanks in advance,
A

--20cf302ad6669f206904ddd8f514
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi all,<br><div class=3D"gmail_quote"><div dir=3D"ltr"><di=
v><div><div><div><div><div><div><div><div><br></div>Im trying to create a s=
imple Spring REST app using SpringOXM and Castor for XML handling. So far s=
o good, the problem is that when sending an XML POST request to create a co=
ntact, Castor crashes complaining that:<br>

&lt;p&gt;Problem accessing /contacts. Reason:<br>&lt;pre&gt;=A0=A0=A0 Serve=
r Error&lt;/pre&gt;&lt;/p&gt;&lt;h3&gt;Caused by:&lt;/h3&gt;&lt;pre&gt;java=
.lang.IllegalStateException: No Introspector defined in properties!<br><br>=
</div>

The simple xml Im sending looks like:<br>&lt;?xml version=3D&quot;1.0&quot;=
 encoding=3D&quot;UTF-8&quot;?&gt;<br>&lt;contact&gt;&lt;name&gt;Sonoo&lt;/=
name&gt;&lt;lastName&gt;Jaiswal&lt;/lastName&gt;&lt;/contact&gt;<br><br></d=
iv>

My mapping.xml:<br>&lt;?xml version=3D&quot;1.0&quot;?&gt;<br>&lt;mapping&g=
t;<br>=A0&lt;class name=3D&quot;com.test.model.Contact&quot;&gt;<br>=A0=A0=
=A0 &lt;map-to xml=3D&quot;contact&quot;/&gt;<br>=A0=A0=A0 &lt;field name=
=3D&quot;name&quot; type=3D&quot;string&quot;&gt;<br>

=A0=A0=A0=A0=A0=A0 &lt;bind-xml name=3D&quot;name&quot; node=3D&quot;elemen=
t&quot;/&gt;<br>=A0=A0=A0 &lt;/field&gt;<br>=A0=A0=A0 &lt;field name=3D&quo=
t;lastName&quot; type=3D&quot;string&quot;&gt;<br>=A0=A0=A0=A0=A0=A0 &lt;bi=
nd-xml name=3D&quot;lastName&quot; node=3D&quot;element&quot;/&gt;<br>

=A0=A0=A0 &lt;/field&gt;<br>=A0&lt;/class&gt;<br>&lt;/mapping&gt;<br><br></=
div>The Spring configuration:<br>=A0=A0=A0 &lt;context:component-scan base-=
package=3D&quot;com.test /&gt;<br><br>=A0=A0=A0 &lt;!-- REST service --&gt;=
<br>=A0=A0=A0 &lt;bean<br>

=A0=A0=A0=A0=A0=A0=A0 class=3D&quot;org.springframework.web.servlet.mvc.ann=
otation.AnnotationMethodHandlerAdapter&quot;&gt;<br>=A0=A0=A0=A0=A0=A0=A0 &=
lt;property name=3D&quot;messageConverters&quot;&gt;<br>=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0 &lt;util:list id=3D&quot;beanList&quot;&gt;<br>

=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 &lt;ref bean=3D&quot;castorMa=
rshallingHttpMessageConverter&quot; /&gt;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0 &lt;/util:list&gt;<br>=A0=A0=A0=A0=A0=A0=A0 &lt;/property&gt;<br>=A0=A0=
=A0 &lt;/bean&gt;<br><br>=A0=A0=A0 &lt;bean id=3D&quot;castorMarshallingHtt=
pMessageConverter&quot;<br>

=A0=A0=A0=A0=A0=A0=A0 class=3D&quot;org.springframework.http.converter.xml.=
MarshallingHttpMessageConverter&quot;&gt;<br>=A0=A0=A0=A0=A0=A0=A0 &lt;prop=
erty name=3D&quot;marshaller&quot; ref=3D&quot;castorMarshaller&quot; /&gt;=
<br>=A0=A0=A0=A0=A0=A0=A0 &lt;property name=3D&quot;unmarshaller&quot; ref=
=3D&quot;castorMarshaller&quot; /&gt;<br>

=A0=A0=A0 &lt;/bean&gt;<br><br>=A0=A0=A0 &lt;bean id=3D&quot;castorMarshall=
er&quot; class=3D&quot;org.springframework.oxm.castor.CastorMarshaller&quot=
;&gt;<br>=A0=A0=A0=A0=A0=A0=A0 &lt;property name=3D&quot;mappingLocation&qu=
ot;<br>=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 value=3D&quot;classpath:com/test//=
model/mapping.xml&quot; /&gt;<br>

=A0=A0=A0 &lt;/bean&gt;<br><br></div>And finally the controller looks like:=
<br><br>package com.test.controller;<br><br>import org.springframework.ster=
eotype.Controller;<br>import org.springframework.ui.ModelMap;<br>import org=
.springframework.web.bind.annotation.PathVariable;<br>

import org.springframework.web.bind.annotation.RequestMapping;<br>import or=
g.springframework.web.bind.annotation.RequestMethod;<br>import org.springfr=
amework.web.bind.annotation.ResponseStatus;<br>import org.springframework.w=
eb.bind.annotation.RequestBody;<br>

import org.springframework.web.bind.annotation.ResponseBody;<br>import org.=
springframework.http.HttpStatus;<br><br>@Controller<br>@RequestMapping(&quo=
t;/contacts&quot;)<br>public class ContactsController {<br><br><br>=A0=A0 @=
RequestMapping(value=3D&quot;/{name}&quot;, method =3D RequestMethod.GET)<b=
r>

=A0=A0 @ResponseStatus(HttpStatus.OK)<br>=A0=A0 @ResponseBody<br>=A0=A0 pub=
lic Contact getContact(@PathVariable String name) {<br>=A0=A0=A0=A0=A0 Cont=
act c =3D new Contact();<br>=A0=A0=A0=A0=A0 c.setName(name);<br>=A0=A0=A0=
=A0=A0 c.setLastName(&quot;test&quot;);<br>

=A0=A0=A0=A0=A0 return c;<br>=A0=A0 }<br><br><br>=A0=A0 @RequestMapping( me=
thod =3D RequestMethod.POST )<br>=A0=A0 @ResponseStatus( HttpStatus.CREATED=
 )<br>=A0=A0 @ResponseBody<br>=A0=A0 public Long create( @RequestBody Conta=
ct contact ){<br>=A0=A0 =A0=A0=A0 =A0 System.out.println(&quot;Contact &quo=
t; + contact.getName());<br>

=A0=A0=A0=A0=A0 return 1L;<br>=A0=A0 }<br>=A0=A0=A0 <br>}<br><br><br></div>=
As you see its a quick and dirty test to try out Castor and Spring OXM.<br>=
<br></div>Actually, a GET request to the getContact method works and the xm=
l is returned, so the mapping.xml is loaded correctly.<br>

<br>Do you have any idea why Castor is crashing when unmarshalling the POST=
 request xml??<br><br></div>Thanks in advance,<br></div>A<br></div>
</div><br></div>

--20cf302ad6669f206904ddd8f514--

©2008 junlu.com - Jax Systems, LLC, U.S.A.