Announcement Announcement Module
Collapse
No announcement yet.
Spring Remoting - HTTP Invoker is not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Remoting - HTTP Invoker is not working


    Hi All,
    I am doing some POC on Spring Remoting using HTTP Invoker . I have got few sample programs from spring site and I have followed the complete step . My server side code is deployed in tomcat and it is running . Code fragments

    1)

    package com.test;

    public interface Calculation {
    int cube(int number);
    }



    2)

    package com.test;

    public class CalculationImpl implements Calculation{
    public int cube(int number) {
    return number*number*number;
    }
    }

    3) web.xml


    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
    <display-name>RemoteTest</display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <servlet>
    <servlet-name>httpInvoker</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>httpInvoker</servlet-name>
    <url-pattern>*.http</url-pattern>
    </servlet-mapping>

    </web-app>


    4) httpInvoker-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="calculationBean" class="com.test.CalculationImpl"></bean>
    <bean name="/Calculation.http"
    class="org.springframework.remoting.httpinvoker.Ht tpInvokerServiceExporter">
    <property name="service" ref="calculationBean"></property>
    <property name="serviceInterface" value="com.test.Calculation"></property>
    </bean>

    </beans>


    and this server is running in local server

    http://localhost:8080/SpringRemoteExample/


    Now the client program . For this I have created another simple java project

    1) client-beans.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="calculationBean"
    class="org.springframework.remoting.httpinvoker.Ht tpInvokerProxyFactoryBean">
    <property name="serviceUrl"
    value="http://localhost:8080/httpinvoker/Calculation.http"></property>
    <property name="serviceInterface" value="com.test.Calculation"></property>
    </bean>
    </beans>




    2)Client .java

    package com.example;



    public class Client {
    public static void main(String[] args){
    ApplicationContext context = new ClassPathXmlApplicationContext("classpath:/resource/client-beans.xml");
    Calculation calculation = (Calculation)context.getBean("calculationBean");
    System.out.println(calculation.cube(5));



    }
    }

    But while running this program getting following exceptions



    Exception in thread "main" org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'calculationBean' defined in class path resource [resource/client-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'serviceInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.test.Calculation]
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:527)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.Abstract BeanFactory$1.getObject(AbstractBeanFactory.java:2 94)
    at org.springframework.beans.factory.support.DefaultS ingletonBeanRegistry.getSingleton(DefaultSingleton BeanRegistry.java:225)
    at org.springframework.beans.factory.support.Abstract BeanFactory.doGetBean(AbstractBeanFactory.java:291 )
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:567)
    at org.springframework.context.support.AbstractApplic ationContext.finishBeanFactoryInitialization(Abstr actApplicationContext.java:913)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:464)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
    at com.example.Client.main(Client.java:11)
    Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Class' for property 'serviceInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [com.test.Calculation]
    at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:490)
    at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:516)
    at org.springframework.beans.BeanWrapperImpl.convertF orProperty(BeanWrapperImpl.java:510)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.convertForProperty(Abst ractAutowireCapableBeanFactory.java:1406)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.applyPropertyValues(Abs tractAutowireCapableBeanFactory.java:1365)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.populateBean(AbstractAu towireCapableBeanFactory.java:1118)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:517)
    ... 11 more
    Caused by: java.lang.IllegalArgumentException: Cannot find class [com.test.Calculation]
    at org.springframework.util.ClassUtils.resolveClassNa me(ClassUtils.java:293)
    at org.springframework.beans.propertyeditors.ClassEdi tor.setAsText(ClassEditor.java:63)
    at org.springframework.beans.TypeConverterDelegate.do ConvertTextValue(TypeConverterDelegate.java:431)
    at org.springframework.beans.TypeConverterDelegate.do ConvertValue(TypeConverterDelegate.java:403)
    at org.springframework.beans.TypeConverterDelegate.co nvertIfNecessary(TypeConverterDelegate.java:163)
    at org.springframework.beans.BeanWrapperImpl.convertI fNecessary(BeanWrapperImpl.java:470)
    ... 17 more
    Caused by: java.lang.ClassNotFoundException: com.test.Calculation
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 07)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 52)
    at org.springframework.util.ClassUtils.forName(ClassU tils.java:257)
    at org.springframework.util.ClassUtils.resolveClassNa me(ClassUtils.java:290)
    ... 22 more


    Thank You
    Joby
    Last edited by joby; Dec 23rd, 2013, 12:14 AM.
Working...
X