Hellowebservice mit Jersey?

flashray

Erfahrenes Mitglied
Hallo,

versuche mich seit gestern mit Jersey:
https://jersey.dev.java.net/

Hab das Helloworld Beispiel immer noch nicht zum Laufen bekommen! :(

Hab viel hin und her probiert, http4e meldet jedes mal das die angefragte Ressource nicht gefunden wird.

https://jersey.dev.java.net/use/getting-started.html
http://www.qalem.de/_jersey/

Java:
package com.sun.jersey.samples.helloworld.resources;

import javax.ws.rs.GET;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.Path;

// The Java class will be hosted at the URI path "/helloworld"
@Path("/helloworld")
public class HelloWorldResource {

    // The Java method will process HTTP GET requests
    @GET 
    // The Java method will produce content identified by the MIME Media
    // type "text/plain"
    @ProduceMime("text/plain")
    public String getClichedMessage() {
        // Return some cliched textual content
        return "Hello World";
    }
}
 
Hallo,

funktioniert wunderbar:
Java:
package de.tutorials;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.ProduceMime;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;

// The Java class will be hosted at the URI path "/helloworld"
@Path("helloworld")
public class HelloWorldResource {

    @Context
    private UriInfo context;

    /** Creates a new instance of HelloWorldResource */
    public HelloWorldResource() {
    }

   /**
   * Retrieves representation of an instance of hello.world.HelloWorldResource
   * @return an instance of java.lang.String
   */
   @GET
   @ProduceMime("text/plain")
   public String getClichedMessage() {
       //Return some cliched textual content
       return ("Hello World! Here is " + context.getAbsolutePath());
   }
}

Java:
/**
 * 
 */
package de.tutorials;

import com.sun.jersey.api.container.httpserver.HttpServerFactory;
import com.sun.net.httpserver.HttpServer;

/**
 * @author Thomas.Darimont
 * 
 */
public class JerseyExample {

    /**
     * @param args
     */
    public static void main(String[] args) throws Exception {
        HttpServer server = HttpServerFactory.create("http://localhost:9998/");
        server.start();

        System.out.println("Server running");
        System.out.println("Visit: http://localhost:9998/helloworld");
        System.out.println("Hit return to stop...");
        System.in.read();
        System.out.println("Stopping server");
        server.stop(0);
        System.out.println("Server stopped");
    }

}

Ausgabe: Server console:
Code:
25.06.2008 11:44:10 com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Scanning for root resource and provider classes in the paths:
  D:\eclipse\workspaces\workspace-3.4M7\de.tutorials.java\bin
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\activation.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\ant.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\asm-3.1.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\comresrcgen.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\grizzly-servlet-webserver-1.7.3.2.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\http.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-api.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-impl.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jaxb-xjc.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jdom-1.0.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jersey.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jettison-1.0-RC1.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsp-api-2.0-20040521.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr173_api.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr250-api.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\jsr311-api.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\localizer.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\mail.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\persistence-api-1.0.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\rome-0.9.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\servlet.jar
  D:\stuff\jersey\0.9\jersey-0.9-ea\lib\wadl2java.jar
25.06.2008 11:44:11 com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Root resource classes found:
  class de.tutorials.HelloWorldResource
25.06.2008 11:44:11 com.sun.jersey.api.core.ClasspathResourceConfig init
INFO: Provider classes found:
Server running
Visit: http://localhost:9998/helloworld
Hit return to stop...

Ausgabe Browser:
Code:
Hello World! Here is http://localhost:9998/helloworld


Gruß Tom
 

Anhänge

  • de.tutorials.jersey.zip
    3,6 KB · Aufrufe: 53

Neue Beiträge

Zurück