示例#1
0
  /** @param args */
  public static void main(String[] args) {
    String url = (args.length > 0) ? args[0] : "http://localhost:4434";
    String nam = (args.length > 1) ? args[1] : "ich";
    url = url + "/helloworld?name=" + nam;
    System.out.println("URL: " + url);

    WebResource wrs = Client.create().resource(url);

    System.out.println("\nTextausgabe:");
    System.out.println(wrs.accept("text/plain").get(String.class));
    System.out.println("\nHTML-Ausgabe:");
    System.out.println(wrs.accept("text/html").get(String.class));
  }
示例#2
0
  public static void main(String argv[]) {

    if (argv.length != 1) {
      System.out.println("java Irc <name>");
      return;
    }
    myName = argv[0];

    // initialize the system
    Client.init();

    // look up the IRC object in the name server
    // if not found, create it, and register it in the name server
    Sentence_itf s = (Sentence_itf) Client.lookup("IRC");
    if (s == null) {
      s = (Sentence_itf) Client.create(new Sentence());
      Client.register("IRC", s);
    }
    // create the graphical part
    new Irc(s);
  }
  public static void main(String[] args) {

    java.net.URI serviceURI = UriBuilder.fromUri("http://localhost:8080/jaxrs").build();

    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource weatherService = client.resource(serviceURI);

    String weatherResult =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Rain")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult2 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult3 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/12345")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult);
    System.out.println(weatherResult2);
    System.out.println(weatherResult3);

    MultivaluedMap formData = new MultivaluedMapImpl();
    formData.add("temperature", "25");
    formData.add("humidity", "15%");
    formData.add("rain", "false");
    formData.add("zipCode", "94043");

    String response =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .type("application/x-www-form-urlencoded")
            .post(String.class, formData);

    System.out.println(response);

    String weatherResult4 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult4);

    String weatherResult5 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_XML)
            .get(String.class);

    System.out.println(weatherResult5);
  }