package com.developi.wink.demo.api;

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

import com.ibm.commons.util.io.json.JsonJavaObject;
import com.ibm.domino.osgi.core.context.ContextInfo;

import lotus.domino.NotesException;
import lotus.domino.Session;

@Path("/test")
public class TestResource {

	@GET
	public Response test(){
		JsonJavaObject resp = new JsonJavaObject();
		
		try {
			resp.put("message", "Hello " + getUserSession().getEffectiveUserName());
			return Response.ok().type(MediaType.APPLICATION_JSON).entity(resp.toString()).build();
		} catch (NotesException e) {
			e.printStackTrace();
			return Response.serverError().build();
		}
				
	}

	private Session getUserSession() {
		return ContextInfo.getUserSession();
	}
	
	
}

@@ -152,60 +152,49 @@
 se;%0A
-%0A
 import 
-com.ibm.commons.util.io.json.JsonJavaObject;
+javax.ws.rs.core.Response.Status;%0A
 %0Aimp
@@ -391,139 +391,561 @@
 %7B%0A%09%09
-JsonJavaObject resp = new JsonJavaObject
+try %7B%0A%09%09%09String userName = getUserSession().getEffectiveUserName
 ();%0A%09%09
+%09
 %0A%09%09
-try %7B%0A%09%09%09resp.put(%22message%22, %22Hello %22 + getUserSession().getEffectiveUserName())
+%09if(%22Anonymous%22.equals(userName)) %7B%0A%09%09%09%09// If connected through a browser, this response will signal for authentication and redirected to the login form. %0A%09%09%09%09// However, be careful with 40x responses. If session authentication is enabled for the server,%0A%09%09%09%09// The consumer might receive the login form and 200-OK response. This would be a code-breaker.%0A%09%09%09%09return Response.status(Status.UNAUTHORIZED).build();%0A%09%09%09%7D else %7B%0A%09%09%09%09String message = %22%3Cb%3EHello %22 + userName + %22%3C/b%3E%22
 ;%0A
+%09
 %09%09%09r
@@ -983,24 +983,17 @@
 ype.
-APPLICATION_JSON
+TEXT_HTML
 ).en
@@ -1001,23 +1001,15 @@
 ity(
-resp.toString()
+message
 ).bu
@@ -1015,16 +1015,21 @@
 uild();%0A
+%09%09%09%7D%0A
 %09%09%7D catc

Add authentication and modify response type for /test