1 pièce(s) jointe(s)
Web service Jersey et JQuery
Hello all,
Je souhaite écrire une webservice (via Jersey) qui soit utilisable avec JQuery. Jusque là pas de grosse difficulté me diriez vous mais pourtant si !
Voici un webservice simple avec Jersey :
Code:
1 2 3 4 5 6 7 8
| @Path("/helloworld")
public class HelloWorldResource {
@GET @Produces("text/html")
public String getClichedMessage() {
System.out.println("Hellworld called");
return "Hello world !";
}
} |
En appelant cette classe via un browser, le "Hello world !" s'affiche, ainsi que le "Hello world called" en console. Parfait !
Le problème se pose une fois que je souhaite l'appeler via JQuery, avec ceci :
Code:
1 2 3 4 5 6 7 8
| $.ajax({
type: 'GET',
url: 'http://localhost:9998/helloworld',
dataType: 'html',
success: function(data){
console.log(data);
}
}); |
Ici, aucun retour et une erreur étrange dans le log de firebug (cf en pj)
J'ai trouvé plusieurs posts sur le net parlant de Jersey et JQuery mais aucun ne m'a aidé à résoudre ce problème.
Quelqu'un a t-il une idée ?
Merci d'avance !
PS : Je tiens à préciser que le serveur est Grizzly en standalone, démarré via ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public static void main(String[] args) throws IOException {
final String baseUri = "http://localhost:9998/";
final Map<String, String> initParams = new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages",
"com.webservice.resource");
System.out.println("Starting grizzly...");
SelectorThread threadSelector =
GrizzlyWebContainerFactory.create(baseUri, initParams);
System.out.println(String.format(
"Jersey app started with WADL available at %sapplication.wadl\n" +
"Hit enter to stop it...", baseUri));
System.in.read();
threadSelector.stopEndpoint();
System.exit(0);
} |