-
1. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 18, 2011 6:25 PM (in response to abhi0123)44 views and no response? Is this too complex or too rudimentary to bother?
-
2. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 18, 2011 10:46 PM (in response to abhi0123)Are you running the server in preview mode?
./standalone.sh --server-config=standalone-preview.xml
-
3. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 19, 2011 10:39 PM (in response to swd847)./standalone.sh --server-config=standalone-preview.xml
{code}
21:01:09,038 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/movieservicerestful]] (MSC service thread 1-3) Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
at org.scannotation.WarUrlFinder.findWebInfClassesPath(WarUrlFinder.java:56) [scannotation-1.0.2.jar:]
at org.jboss.resteasy.plugins.server.servlet.ListenerBootstrap.getScanningUrls(ListenerBootstrap.java:64) [resteasy-jaxrs-2.2.1.GA.jar:]
21:01:09,044 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Error listenerStart
21:01:09,045 ERROR [org.apache.catalina.core.StandardContext] (MSC service thread 1-3) Context [/movieservicerestful] startup failed due to previous errors
21:01:09,045 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/movieservicerestful]] (MSC service thread 1-3) Exception sending context destroyed event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap: java.lang.NullPointerException
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextDestroyed(ResteasyBootstrap.java:37) [resteasy-jaxrs-2.2.1.GA.jar:]
{code}
{code:xml}
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.jboss.resteasy.resteasy-jaxrs export service,javax.servlet.api export service,org.scannotation.scannotation export service</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
{code}
-
4. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 10:45 PM (in response to abhi0123)You are you bootstrapping resteasy? Can you post your web.xml?
-
5. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 19, 2011 11:01 PM (in response to swd847)Sure, here it is. I tried initializing RESTEasy as a Servlet and then as a Filter, similar errors. You can still see the Servlet part commented.
{code:xml}
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<!-- <listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping> -->
<filter>
<filter-name>Resteasy</filter-name>
<filter-class>
org.jboss.resteasy.plugins.server.servlet.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>Resteasy</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
{code}
-
6. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 11:12 PM (in response to abhi0123)AS7 sets up Resteasy for you, there is no need to set it up yourself. You should remove all of the resteasy configuration from your web.xml and replace it with one of the following three options detailed in this document that I just created:
https://docs.jboss.org/author/display/AS7/JAX-RS+Reference+Guide
-
7. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 19, 2011 11:34 PM (in response to swd847)Followed the 3rd approach, "Using web.xml". Service got deployed alright, but blew up with 500 as soon as it got the first client request.
{code}
23:21:33,022 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/movieservicerestful].[Application]] (http-localhost.localdomain-127.0.0.1-9090-1) Allocate exception for servlet Application: java.lang.ClassCastException: javax.ws.rs.core.Application cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1156) [jbossweb-7.0.0.CR4.jar:7.0.0.Final]
{code}
web.xml
{code:xml}
<servlet>
<servlet-name>Application</servlet-name>
<servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
{code}
MovieServiceRestfulClient.java
{code}
public class MovieServiceRestfulClient {
private static final String ENDPOINT = "http://localhost:9090/movieservicerestful";
public static void main(String[] args) {
new MovieServiceRestfulClient().sendRequest();
}
/* default access so that it can be tested from JUnit */
void sendRequest() {
HttpURLConnection conn = null;
try {
conn = getConnection(ENDPOINT
+ "?path=/media", "GET");
conn.connect();
parseAndPrint(conn, false);
} catch (IOException e) {
e.printStackTrace();
}
}
private HttpURLConnection getConnection(String urlString, String httpVerb) {
HttpURLConnection conn = null;
try {
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod(httpVerb);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return conn;
}
private void parseAndPrint(HttpURLConnection conn, boolean parse) {
String xml = "";
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
conn.getInputStream()));
String next = null;
while ((next = reader.readLine()) != null)
xml += next;
System.out.println("The raw XML:\n" + xml);
} catch (Exception e) {
e.printStackTrace();
}
}
}
{code}
-
8. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 11:32 PM (in response to abhi0123)Get rid of this:
<servlet>
<servlet-name>Application</servlet-name>
<servlet-class>javax.ws.rs.core.Application</servlet-class>
</servlet>it is not required.
-
9. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 11:33 PM (in response to swd847)Also the name is wrong in the servlet mapping, it must be javax.ws.rs.core.Application not Application.
-
10. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 11:36 PM (in response to swd847)I have updated the docs to try and make this clearer, also I added a note about the section of the specification that details the three different methods.
-
11. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 19, 2011 11:47 PM (in response to swd847)You need to remove the resteasy.scan parameter as well, can you remove this, and then post your full log and the contents of the class that should be providing the resource?
-
12. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 19, 2011 11:57 PM (in response to swd847)I tried without the resteasy.scan too.
[Sorry about deleting the post - I was trying to sober up the formatting.]
I will post the service and detailed log.
{code:xml}
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
{code}
{code}
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running name.app.abhi.movieservice.restful.client.MovieServiceRestfulClientTest
java.io.FileNotFoundException: http://localhost:9090/movieservicerestful?path=/media
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
at name.app.abhi.movieservice.restful.client.MovieServiceRestfulClient.parseAndPrint(MovieServiceRestfulClient.java:59)
{code}
-
13. Re: Problem migrating RESTful service from AS6 to AS7
abhi0123 Jul 19, 2011 11:54 PM (in response to abhi0123){code}
@WebServiceProvider
@BindingType(value = HTTPBinding.HTTP_BINDING)
public class MovieServiceRestful implements Provider<Source> {
@Resource
protected WebServiceContext wsCtx;
private MovieServiceImpl movieService = new MovieServiceImpl();
@Override
public Source invoke(Source request) {
if (wsCtx == null) {
throw new RuntimeException("DI failed on wsCtx.");
}
/* Grab the message context and extract the request verb */
MessageContext msgCtx = wsCtx.getMessageContext();
String httpVerb = (String) msgCtx
.get(MessageContext.HTTP_REQUEST_METHOD);
httpVerb = httpVerb.trim().toUpperCase();
/* Act on the verb. Only GET requests accepted */
if (httpVerb.equals("GET")) {
try {
return doGet(msgCtx);
} catch (Exception e) {
e.printStackTrace();
throw new HTTPException(500);
}
}
throw new HTTPException(405); // method not allowed
}
private Source doGet(MessageContext msgCtx) throws IOException {
String queryString = (String) msgCtx.get(MessageContext.QUERY_STRING);
ByteArrayOutputStream stream = null;
XMLEncoder enc = null;
if (queryString != null) {
/* Serialize object to XML and return */
stream = new ByteArrayOutputStream();
enc = new XMLEncoder(stream);
enc.writeObject(getMovieSet(getPathFromQueryString(queryString,
"path")));
enc.close();
return new StreamSource(new ByteArrayInputStream(
stream.toByteArray()));
}
throw new HTTPException(404);
}
private String getPathFromQueryString(String queryString, String key) {
String[] parts = queryString.split("=");
if (!parts[0].equalsIgnoreCase(key)) {
throw new HTTPException(400); // bad request
}
return parts[1].trim();
}
private SortedSet<Movie> getMovieSet(String path) throws IOException {
return movieService.getMovieSet(path);
}
}
{code}
{code}
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running name.app.abhi.movieservice.restful.client.MovieServiceRestfulClientTest
java.io.FileNotFoundException: http://localhost:9090/movieservicerestful?path=/media
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1434)
at name.app.abhi.movieservice.restful.client.MovieServiceRestfulClient.parseAndPrint(MovieServiceRestfulClient.java:59)
at name.app.abhi.movieservice.restful.client.MovieServiceRestfulClient.sendRequest(MovieServiceRestfulClient.java:35)
at name.app.abhi.movieservice.restful.client.MovieServiceRestfulClientTest.testSendRequest(MovieServiceRestfulClientTest.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:172)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:104)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:70)
{code}
-
14. Re: Problem migrating RESTful service from AS6 to AS7
swd847 Jul 20, 2011 12:02 AM (in response to abhi0123)Thats not a JAX-RS webservice, the resteasy configuration should not affect it.
JAX-WS is only partly implemented in 7.0, it may be that you have to wait for 7.1