Announcement Announcement Module
Collapse
No announcement yet.
Simple HttpInvoker not working Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple HttpInvoker not working

    I am new to spring and am having trouble with invoking a remote service via HttpInvoker. Here is my code for a simple greeting service that takes a name string parameter and returns a string "Hello " + [name]. Here is my code...

    Service is an eclipse java project.
    Service Interface:
    Code:
    package example;
    public interface Hello {
    	public String Greetings(String name);
    }
    Service Implementation:
    Code:
    package example;
    public class HelloImpl implements Hello {
    	public String Greetings(String name) {
    		return "Hello " + name;
    	}
    }
    I create a jar file with the above classes so I can reference it from an eclipse web app project. The web app project has the required jars added to the build path.

    Webapp Web.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
    	xmlns="http://java.sun.com/xml/ns/javaee" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    	http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    	
    	<!-- beans in this file will make up the 'root' web application context -->
    	<context-param>
    		<param-name>contextConfigLocation</param-name>
    		<param-value>/WEB-INF/remoting-webapp-config.xml</param-value>
    	</context-param>
    	
    	<!-- load root web application context before servlet initialization -->
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	
    	<!-- start the web app front controller also known as dispatcher servlet -->
    	<servlet>
    		<servlet-name>hello</servlet-name>
    		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    		<!-- override which web context config file gets loaded -->
    		<init-param>
    			<param-name>contextConfigLocation</param-name>
    			<param-value>/WEB-INF/remoting-servlet-config.xml</param-value>
    		</init-param>
    	</servlet>
    	
    	<!-- designate which URLs are mapped to this Dispatcher servlet -->
    	<servlet-mapping>
    		<servlet-name>hello</servlet-name>
    		<url-pattern>/httpInvoker/*</url-pattern>
    	</servlet-mapping>
    
    </web-app>
    Web app remoting-servlet-config.xml:
    Code:
    <?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-2.0.xsd">
    	
    	<!-- HttpInvoker endpoint for the Person service -->
    	<bean name="/helloService"
    		class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
    		<property name="service" ref="helloService"/>
    		<property name="serviceInterface" value="example.helloService"/>
    	</bean>
    
    </beans>
    Web app remoting-webapp-config.xml:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans
    	xmlns="http://www.springframework.org/schema/beans"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:tx="http://www.springframework.org/schema/tx"
    	xsi:schemaLocation="http://www.springframework.org/schema/beans 
    						http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
    						http://www.springframework.org/schema/tx
    						http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    						
    	<!-- service bean -->
    	<bean id="helloService" class="example.HelloImpl">
    	</bean>
    
    </beans>
    Client is an Eclipse java project.
    Client code:
    Code:
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    import example.Hello;
    
    public class MyApp {
    	public static void main(String[] args) {
    		MyApp app = new MyApp();
    		app.run();
    	}
    	public void run() {
    		ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    		
    		Hello hello = (Hello)ctx.getBean("helloService");
    		System.out.println(hello.Greetings("Fred"));
    		
    		Hello remoteHello = (Hello)ctx.getBean("remoteHelloService");
    		System.out.println("remoteHelloService: " + remoteHello.Greetings("Barny"));
    	}
    }
    Client spring config:
    Code:
    <?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-2.0.xsd">
    
    	<bean id="helloService" class="example.HelloImpl">
    	</bean>
    	 
    	<bean id="remoteHelloService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
    		<property name="serviceUrl">
    			<value>http://localhost:8080/MyRemoteHelloService/httpInvoker/helloService</value>
    		</property>
    		<property name="serviceInterface">
    			<value>example.Hello</value>
    		</property>
    	</bean>
    
    </beans>
    Error message:
    Exception in thread "main" org.springframework.remoting.RemoteAccessException : Could not access HTTP invoker remote service at [http://localhost:8080/MyRemoteHelloS...helloService]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 500, status message = [Internal Server Error]
    at org.springframework.remoting.httpinvoker.HttpInvok erClientInterceptor.convertHttpInvokerAccessExcept ion(HttpInvokerClientInterceptor.java:211)
    at org.springframework.remoting.httpinvoker.HttpInvok erClientInterceptor.invoke(HttpInvokerClientInterc eptor.java:160)
    at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :171)
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
    at $Proxy0.Greetings(Unknown Source)
    at MyApp.run(MyApp.java:18)
    at MyApp.main(MyApp.java:9)
    Caused by: java.io.IOException: Did not receive successful HTTP response: status code = 500, status message = [Internal Server Error]
    at org.springframework.remoting.httpinvoker.SimpleHtt pInvokerRequestExecutor.validateResponse(SimpleHtt pInvokerRequestExecutor.java:139)
    at org.springframework.remoting.httpinvoker.SimpleHtt pInvokerRequestExecutor.doExecuteRequest(SimpleHtt pInvokerRequestExecutor.java:62)
    at org.springframework.remoting.httpinvoker.AbstractH ttpInvokerRequestExecutor.executeRequest(AbstractH ttpInvokerRequestExecutor.java:134)
    at org.springframework.remoting.httpinvoker.HttpInvok erClientInterceptor.executeRequest(HttpInvokerClie ntInterceptor.java:191)
    at org.springframework.remoting.httpinvoker.HttpInvok erClientInterceptor.invoke(HttpInvokerClientInterc eptor.java:157)
    ... 5 more

    Can some one please help me out? Thanks in advance.

    Jim

  • #2
    One potential issue:

    Code:
    <bean name="/helloService"
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
      <property name="service" ref="helloService"/>
      <property name="serviceInterface" value="example.helloService"/>
    </bean>
    Instead, try:

    Code:
    <bean name="/helloService"
    class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
      <property name="service" ref="helloService"/>
      <property name="serviceInterface" value="example.Hello"/>
    </bean>
    The stack trace in your sample was from the client. Also check for startup and/or runtime exceptions reported by the server (i.e., web container).

    Comment

    Working...
    X