[ 
http://jira.codehaus.org/browse/XFIRE-522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_106640
 ] 

Dwayne Perkins commented on XFIRE-522:
--------------------------------------

Spring wraps your class in a proxy wrapper that implements the same interface 
as your handler class (If you didn't implement an interface, you should).   

When attempting to get your bean class from the context, you must cast it to an 
instance of the interface.  

If you don't , you will get an exception saying that it was expecting your 
class but got a proxy class instead.  

If you try to cast it to your actual class instead of the interface, you will 
get a class cast exception.

Here is an example, although it is not exactly the same as what you are doing, 
it is similar enough:

//Assuming that you have defined a bean in your applicationContext file called 
SitesDataHandler which 
//configures a class that implements the ISitesDataHandler interface - an 
interface that simply has the
//methods you desire to put into your data handler.

ApplicationContext myContext = new 
ClassPathXmlApplicationContext("config/spring/applicationContext.xml");

SitesDataHandler sdh = (ISitesDataHandler)myContext.getBean("SitesDataHandler");
Object sdh = myContext.getBean("SitesDataHandler");
//You can now call the methods of your interface

Hope that helps!

> Proxy Class cast exception on deploying spring, java15 annotated service
> ------------------------------------------------------------------------
>
>                 Key: XFIRE-522
>                 URL: http://jira.codehaus.org/browse/XFIRE-522
>             Project: XFire
>          Issue Type: Bug
>          Components: Annotations
>    Affects Versions: 1.1.2
>         Environment: JBOSS 4.0.4 GA
>            Reporter: Alex Fishlock
>            Assignee: Dan Diephouse
>
> Create a basic service, called echo:
> =======================================
> @WebService(serviceName = "EchoService")
> public class EchoImpl
>         implements Echo
> {
>     @WebMethod()
>     public String echo( String echo )
>     {
>         return echo;
>     }
> }
> ========================================
> using context xml of:
> ============================================
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" 
> "http://www.springframework.org/dtd/spring-beans.dtd";>
> <beans>
>   <bean id="webAnnotations" 
> class="org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations"/>
>   <bean id="handlerMapping" 
> class="org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping">
>     <property name="typeMappingRegistry">
>       <ref bean="xfire.typeMappingRegistry"/>
>     </property>
>     <property name="xfire">
>       <ref bean="xfire"/>
>     </property>
>     <property name="webAnnotations">
>       <ref bean="webAnnotations"/>
>     </property>
>   </bean>
>   <bean id="annotatedEcho" 
> class="org.codehaus.xfire.spring.example.EchoImpl"/>
>   <bean 
> class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
>     <property name="urlMap">
>       <map>
>         <entry key="/">
>           <ref bean="handlerMapping"/>
>         </entry>
>       </map>
>     </property>
>   </bean>
>   <import resource="classpath:org/codehaus/xfire/spring/xfire.xml"/>
> </beans>
> ========================================================
> and web.xml of:
> ========================================================
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <!DOCTYPE web-app
>     PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
>     "http://java.sun.com/dtd/web-app_2_3.dtd";>
> <web-app>
>     <context-param>
>         <param-name>contextConfigLocation</param-name>
>         <param-value>
>         WEB-INF/xfire-annotations.xml</param-value>
>     </context-param>
>  
>     <listener>
>         
> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
>     </listener>
>     <servlet>
>         <servlet-name>xfire</servlet-name>
>         
> <servlet-class>org.codehaus.xfire.transport.http.XFireConfigurableServlet</servlet-class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>xfire</servlet-name>
>         <url-pattern>/services/*</url-pattern>
>     </servlet-mapping>
>   <servlet-mapping>
>     <servlet-name>xfire</servlet-name>
>     <url-pattern>/servlet/XFireServlet/*</url-pattern>
>   </servlet-mapping>
> </web-app>
> ======================================
> results in a class cast execption of 
> ======================================
> 17:32:28,531 INFO  [DefaultListableBeanFactory] Pre-instantiating singletons 
> in
> factory [org.springframework.beans.factory.support.DefaultListableBeanFactory 
> de
> fining beans 
> [webAnnotations,handlerMapping,annotatedEcho,org.springframework.we
> b.servlet.handler.SimpleUrlHandlerMapping,customEditorConfigurer,xfire.serviceRe
> gistry,xfire.transportManager,xfire,xfire.typeMappingRegistry,xfire.aegisBinding
> Provider,xfire.serviceFactory,xfire.servletController,xfire.messageServiceFactor
> y,xfire.messageBindingProvider]; root of BeanFactory hierarchy]
> 17:32:28,640 INFO  [DefaultListableBeanFactory] Destroying singletons in 
> factory
>  {org.springframework.beans.factory.support.DefaultListableBeanFactory 
> defining
> beans 
> [webAnnotations,handlerMapping,annotatedEcho,org.springframework.web.servl
> et.handler.SimpleUrlHandlerMapping,customEditorConfigurer,xfire.serviceRegistry,
> xfire.transportManager,xfire,xfire.typeMappingRegistry,xfire.aegisBindingProvide
> r,xfire.serviceFactory,xfire.servletController,xfire.messageServiceFactory,xfire
> .messageBindingProvider]; root of BeanFactory hierarchy}
> 17:32:28,640 ERROR [ContextLoader] Context initialization failed
> org.springframework.beans.factory.BeanCreationException: Error creating bean 
> wit
> h name 'handlerMapping' defined in ServletContext resource 
> [/WEB-INF/xfire-annot
> ations.xml]: Initialization of bean failed; nested exception is 
> java.lang.ClassC
> astException: $Proxy52
> java.lang.ClassCastException: $Proxy52
>         at 
> sun.reflect.annotation.AnnotationParser.annotationForMap(AnnotationPa
> rser.java:223)
>         at 
> sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationPar
> ser.java:213)
>         at 
> sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationP
> arser.java:69)
>         at 
> sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationPa
> rser.java:52)
>         at java.lang.Class.initAnnotationsIfNecessary(Class.java:2998)
>         at java.lang.Class.getAnnotation(Class.java:2958)
>         at java.lang.Class.isAnnotationPresent(Class.java:2970)
>         at 
> org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations.hasWebServ
> iceAnnotation(Jsr181WebAnnotations.java:27)
>         at 
> org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping.processBeans(
> Jsr181HandlerMapping.java:104)
>         at 
> org.codehaus.xfire.spring.remoting.Jsr181HandlerMapping.initApplicati
> onContext(Jsr181HandlerMapping.java:64)
> =====================================
> Am I doing anything wrong?

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to