Hi Stephan,
I can't find your test class, but I have create following classes to show how I am using Restlet and the extension:
import org.restlet.Context;
import org.restlet.ext.jaxrs.JaxRsApplication;
public class MdWebServiceJaxRsApplication extends JaxRsApplication {
public MdWebServiceJaxRsApplication(Context context) {
super(context);
this.add(new MdWebServiceApplication());
//this.setGuard(...);
//this.setRoleChecker(...);
}
}
-------------------------------------
import javax.ws.rs.core.Application;
import java.util.Set;
import java.util.HashSet;
public class MdWebServiceApplication extends Application {
public Set<Class<?>> getClasses() {
Set<Class<?>> rrcs = new HashSet<Class<?>>();
rrcs.add(TestResource.class);
return rrcs;
}
}
-------------------------------------------
import javax.ws.rs.*;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.MediaType;
/**
* Created by IntelliJ IDEA.
* User: hvtranho
* Date: Nov 6, 2009
* Time: 1:40:40 PM
* To change this template use File | Settings | File Templates.
*/
@Path("/mytestpath/entity/{id}")
public class TestResource {
@GET
@Produces("application/xml")
public Response getSupplementalAsXml(@PathParam("id") String id) {
return Response.ok(id, MediaType.APPLICATION_XML).build();
}
}
------------------------------------
and the test class:
public class ClientApp {
String URLPREFIX = "
http://localhost:8080/mws";
/**
*
* @param args
*/
public static void main(String args[]) {
org.junit.runner.JUnitCore.main("gov.nasa.gsfc.gcmd.mdwebservice.rest.ClientApp");
}
@Test
public void getTestResource() throws Exception {
Client client = new Client(Protocol.HTTP);
String id = URLEncoder.encode("PMEL/NOAA", "UTF-8");
System.out.println(id);
String url = URLPREFIX + "/mytestpath/entity/" + id;
System.out.println(url);
Request r = new Request();
r.setResourceRef(url);
r.setMethod(Method.GET);
r.getClientInfo().getAcceptedMediaTypes().add(new Preference<MediaType>(MediaType.APPLICATION_XML));
Response response = client.handle(r);
System.out.println(response.getStatus());
if (response.isEntityAvailable()) {
response.getEntity().write(System.out);
}
}
}
-----------------------------------------
I received this test result:
PMEL%2FNOAA
http://localhost:8080/mws/mytestpath/entity/PMEL%2FNOAANov 6, 2009 3:02:43 PM com.noelios.restlet.http.StreamClientHelper start
INFO: Starting the HTTP client
Bad Request (400) - Bad Request
I am using Apache Tomcat 5.5.27, jdk 1.50_20 on Mac OS X 10.5.8
Best regards,
Hoan-Vu Tran-Ho.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2415231