Hello Folks!!.
I'm trying embed Jetty in Spring. This is my folder structure in the server side, this is a example that somebody has posted in this forum, but I don't remember the link, sorry by not to mention to Author:
conf
|
|--WEB-INF
| |
| |--lib
| | |
| | |-- commons-logging.jar
| | |-- jetty-6.1.3.jar
| | |-- jetty-util-6.1.3.jar
| | |-- servlet-api-2.5-6.1.3.jar
| | |-- spring.jar
| |
| |-- applicationContext.xml
| |-- remoting-servlet.xml
| |-- web.xml
|
|-- jetty.xml
The project has been developed with Eclipse.
This my code snippets:
HelloWorld.java:
HelloWorldImpl.javaCode:public interface HelloWorld { public String sayhello(); }
TestServiceExporter.javaCode:public class HelloWorldImpl implements HelloWorld { public String sayhello() { return "Hello"; } }
applicationContext.xmlCode:import org.springframework.context.support.FileSystemXmlApplicationContext; public class TestServiceExporter { public static void main( String[] args ){ FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("jetty.xml"); } }
remotingServlet.xmlCode:<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <!-- helloWorld --> <bean id="helloWorld" class="HelloWorldImpl"> </bean> </beans>
web.xmlCode:<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <!-- - Dispatcher servlet for HTTP remoting via Hessian, Burlap, and Spring's - HTTP invoker (see remoting-servlet.xml for the controllers). --> <beans> <!-- HTTP invoker exporter for the JPetStore OrderService --> <!-- Spring's HTTP invoker uses Java serialization via HTTP --> <!-- ModeState --> <bean id="remoteMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/helloWorld-httpinvoker">helloWorld-httpinvoker</prop> </props> </property> </bean> <bean id="helloWorld-httpinvoker" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter"> <property name="service"><ref bean="helloWorld"/></property> <property name="serviceInterface"><value>HelloWorld</value></property> </bean> </beans>
jetty.xmlCode:<?xml version="1.0" encoding="UTF-8" ?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <!-- - Location of the XML file that defines the root application context. - Applied by ContextLoaderServlet. --> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/remoting-servlet.xml, applicationContext.xml </param-value> </context-param> <!-- - Loads the root application context of this web app at startup, - by default from "/WEB-INF/applicationContext.xml". - Note that it is preferable to use ContextLoaderListener in a servlet container - that follows the Servlet 2.4 initialization order (most Servlet 2.3 containers do). - - Use WebApplicationContextUtils.getWebApplicationContext(servletContext) - to access it anywhere in the web application, outside of the framework. - - The root context is the parent of all servlet-specific contexts. - This means that its beans are automatically available in these child contexts, - both for getBean(name) calls and (external) bean references. --> <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <!-- - Dispatcher servlet definition for HTTP remoting via Hessian, Burlap, and - Spring's HTTP invoker (see remoting-servlet.xml for the controllers). --> <servlet> <servlet-name>remoting</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <!-- - Dispatcher servlet mapping for HTTP remoting via Hessian, Burlap, and - Spring's HTTP invoker (see remoting-servlet.xml for the controllers). --> <servlet-mapping> <servlet-name>remoting</servlet-name> <url-pattern>/remoting/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
In the client side:Code:<?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="Server" class="org.mortbay.jetty.Server" init-method="start" destroy-method="stop"> <property name="connectors"> <list> <bean id="Connector" class="org.mortbay.jetty.nio.SelectChannelConnector"> <property name="port" value="8181"/> </bean> </list> </property> <property name="handler"> <bean id="handlers" class="org.mortbay.jetty.handler.HandlerCollection"> <property name="handlers"> <list> <bean id="contexts" class="org.mortbay.jetty.handler.ContextHandlerCollection"> <property name="handlers"> <list> <bean class="org.mortbay.jetty.webapp.WebAppContext"> <property name="contextPath" value="/"/> <!-- <property name="war" value="conf" /> --> <property name="resourceBase" value="conf" /> </bean> </list> </property> </bean> </list> </property> </bean> </property> </bean> </beans>
HelloWorld.java
TestHello.javaCode:public interface HelloWorld { public String sayhello(); }
app-client.xmlCode:import org.springframework.context.support.ClassPathXmlApplicationContext; public class TestHello { public HelloWorld hello; public void sethello(HelloWorld hello){this.hello=hello;} public static void main(String[] args) { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] {"app-client.xml"}); TestHello t=(TestHello)appContext.getBean("testHello"); System.out.println(t.hello.sayhello()); } }
When I run the server and after the client, Always I get the same error.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:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <bean id="helloremotingHttpInvoker" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean"> <property name="serviceUrl" value="http://127.0.0.1:8181/remoting/helloWorld-httpinvoker" /> <property name="serviceInterface" value="HelloWorld" /> </bean> <bean id="testHello" class="TestHello"> <property name="hello" ref="helloremotingHttpInvoker"/> </bean> </beans>
Can somebody help me, please?Code:19-abr-2008 18:44:02 org.springframework.context.support.AbstractApplicationContext prepareRefresh INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@1bd747e: display name [org.springframework.context.support.ClassPathXmlApplicationContext@1bd747e]; startup date [Sat Apr 19 18:44:02 CEST 2008]; root of context hierarchy 19-abr-2008 18:44:02 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO: Loading XML bean definitions from class path resource [app-client.xml] 19-abr-2008 18:44:02 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext@1bd747e]: org.springframework.beans.factory.support.DefaultListableBeanFactory@18ee9d6 19-abr-2008 18:44:02 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18ee9d6: defining beans [helloremotingHttpInvoker,testHello]; root of factory hierarchy Exception in thread "main" org.springframework.remoting.RemoteAccessException: Could not access HTTP invoker remote service at [http://127.0.0.1:8181/remoting/helloWorld-httpinvoker]; nested exception is java.io.IOException: Did not receive successful HTTP response: status code = 404, status message = [Not Found] at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.convertHttpInvokerAccessException(HttpInvokerClientInterceptor.java:211)
Thanks in advance!!


Reply With Quote