Note that there are some explanatory texts on larger screens.

plurals
  1. POEmbedded jetty for automated tests
    primarykey
    data
    text
    <p>I am trying to use embedded jetty for automated tests of a web service. However, I keep getting an error 404 when I try to access the service.</p> <p>This is my src/main/webapp/WEB-INF/web.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;display-name&gt;Snafucator&lt;/display-name&gt; &lt;session-config&gt; &lt;session-timeout&gt;60&lt;/session-timeout&gt; &lt;/session-config&gt; &lt;context-param&gt; &lt;param-name&gt;webAppRootKey&lt;/param-name&gt; &lt;param-value&gt;Snafucator&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath*:snafucator.service.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;servlet&gt; &lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.xml.ws.transport.http.servlet.WSSpringServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;jaxws-servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/Snafucator&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p></p> <p>I also want my src/test/resources to be on the classpath as they contain setup of DAOs and other components that implement the service. All the beans required by the service are configured in the snafucator.service.xml. This mainly happens through loading several spring context files. These are files from lower layers and the snafucator.context.xml which defines the service binding and implementation:</p> <pre><code>&lt;import resource="classpath*:setup.context.xml" /&gt; &lt;import resource="classpath*:core.context.xml" /&gt; &lt;import resource="classpath*:snafucator.context.xml" /&gt; </code></pre> <p>Morever, I need the target/classes on the classpath as it contains the snafucator.context.xml:</p> <pre><code>&lt;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:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet" xmlns:security="http://www.springframework.org/schema/security" xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd http://jax-ws.dev.java.net/spring/servlet http://jax-ws.java.net/spring/servlet.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- enable autowiring by annotations --&gt; &lt;context:annotation-config /&gt; &lt;wss:binding url="/Snafucator"&gt; &lt;wss:service&gt; &lt;ws:service bean="#snafucatorWs" /&gt; &lt;/wss:service&gt; &lt;/wss:binding&gt; &lt;bean id="snafucatorWs" class="com.snafu.SnafucatorWSImpl" /&gt; </code></pre> <p></p> <p>This is how I start jetty:</p> <pre><code> server = new Server(iPort); WebAppContext root = new WebAppContext(); root.setExtraClasspath("target/classes/,src/test/resources/"); root.setDescriptor("src/main/webapp/WEB-INF/web.xml"); root.setResourceBase("src/main/webapp"); root.setWar("src/main/webapp"); root.setContextPath("/"); root.setServer(server); root.setParentLoaderPriority(true); server.setHandler(root); System.out.println("Starting jetty server on port:" + iPort); server.start(); System.out.println("Jetty server is started!"); </code></pre> <p>When I access <code>"http://localhost:8082"</code> I see the WEB-INF and META-INF directories, so Jetty is running. When I try <code>"http://localhost:8082/Snafucator"</code> I get an error 404 and the command line says "JAX-WS-Servlet Initialized". When I access any other url under <code>"http://localhost:8082"</code> I get a slightly differently formatted 404. So I assume some WS-handling happens. I am also developing a web application that the service is designed to be a part of. When I include the snafucator.context.xml into that application's context and start the application using the jetty eclipse plugin then everything works fine. But for automated tests I need to start the service standalone. </p> <p>By the way, I am using Jetty 7.6.14.</p> <p>What am I doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload