Hello everyone,

As I am learning REST development in Java and with Apache Wink, I am
implementing a very simple HelloNickName server/client.

I am using Eclipse Kepler 4.3 and Tomcat 6 (under Ubuntu 64 bits 13.10).
I managed to create a localhost server inside Tomcat 6 with Wink library.
I've joined the web.xml, HelloApplication.java and HelloResource.java for
the server side.
HelloResource has a GET and a PUT method.

But there is the problem I am facing :
I've written a tiny client (HelloNicknameClient) class in javase 7 in order
to test the GET/PUT methods.
What I was expecting is that the final String (result2) give me "Hello
Laurent !", but it is still "Hello World !" as result1 String.

What's wrong with my understanding of RESTful applications ? Should I
change a kind of configuration in my server side ? And if yes, which one ?

Regards
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns="http://java.sun.com/xml/ns/javaee"; xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"; id="WebApp_ID" version="3.0">
  <display-name>HelloNickName</display-name>
  <servlet>
      <servlet-name>HelloNickname</servlet-name>
      <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class>
      <init-param>
          <param-name>javax.ws.rs.Application</param-name>
          <param-value>com.loloof64.javaee.hello_nickname.HelloApplication</param-value>
      </init-param>
  </servlet>
  <servlet-mapping>
      <servlet-name>HelloNickname</servlet-name>
      <url-pattern>/*</url-pattern>
  </servlet-mapping>
</web-app>
package com.loloof64.javaee.hello_nickname;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

public class HelloApplication extends Application {

	@Override
	public Set<Class<?>> getClasses() {
		Set<Class<?>> classesToReturn = new HashSet<>();
		classesToReturn.add(HelloResource.class);
		return classesToReturn;
	}

	
	
}
package com.loloof64.javaee.hello_nickname;

import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Path("/hello")
public class HelloResource {

	@GET
	public Response sayHello(){
		return Response.ok(String.format("Hello %s !", nickname)).build();
	}
	
	@PUT
	public void changeNickname(String newNickname){
		nickname = newNickname;
	}
	
	private String nickname = "world";
	
}
package com.loloof64.j2se.hello_nickname_client;

import org.apache.wink.client.Resource;
import org.apache.wink.client.RestClient;

public class HelloNicknameClient {

	public static void main(String[] args) {
		RestClient client = new RestClient();
		Resource helloResource = client.resource("http://localhost:8080/HelloNickName/hello";);
		
		String result1 = helloResource.get().getEntity(String.class);
		System.out.println(result1);
		
		helloResource.put(String.class, "Laurent");
		
		String result2 = helloResource.get().getEntity(String.class);
		System.out.println(result2);
	}
	
}

Reply via email to