cancel
Showing results for 
Search instead for 
Did you mean: 

Java webdypro : how to create /read cookie with NW 7.0 ?

0 Kudos

Hi everybody,

I'd be grateful if you could advise me on how to treat this problem :

I found many discussion about cookies manipulation with application running on NW7 (nw2004s) or later ... but there isn't any clear response ...(I'm not expert in WDJ development)

1- SAP WDJ methods are no more available with version NW7 (NW2004S) ? ( true or false?)

2- No possibility to use Java standards methods to manipulate cookies in WDJ application ? (create/read)

Thanks a lot

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

You can use this code below:


	HttpServletResponse httpServletResponse = (HttpServletResponse) TaskBinder.getCurrentTask().getProtocolAdapter().getResponseObjectInternal().getProtocolResponse();
	Cookie testCookie = new Cookie("testCookie", "testValue");
	httpServletResponse.addCookie(testCookie);
	
	HttpServletRequest httpServletRequest = (HttpServletRequest) TaskBinder.getCurrentTask().getProtocolAdapter().getRequestObjectInternal().getProtocolRequest();
	Cookie[] cookies = httpServletRequest.getCookies();
	if (null != cookies) {
		for (int i = 0; i < cookies.length; i++) {
			String cookieName = cookies<i>.getName();
			String cookieValue = cookies<i>.getValue();
			if ("testCookie".equals(cookieName)) {
				wdComponentAPI.getMessageManager().reportSuccess("Cookie: [testCookie] " + cookieValue);
			}
		}
	}

As said before, WD does not "expose" the Request / Response objects. It expose it's "own" implementation, which uses the Request object but blocks most functions. Personally, I do not see a good reason to not allow a developer to use Cookies.

You will need to add the servlet.jar to your Project Build-Path. Right click the Project, -> Properties -> Java Build-Path -> Add Variable -> Select SAP_SYSTEM_ADD_LIBS -> Extend -> comp/SAP-JEE/DCs/sap.com/servlet... go all the way down!

Hope it helps,

Daniel

Former Member
0 Kudos

hi

I have used following code

IResponse responseObj = ((IProtocolAdapter) WDProtocolAdapter.getProtocolAdapter()).getResponseObjectInternal();

HttpServletResponse response = (HttpServletResponse)responseObj.getProtocolResponse();

but the response variable is coming as null.

Could you please help me to resolve this issue.

Regards,

Anupama

Answers (1)

Answers (1)

Former Member
0 Kudos

WebDynpro abstracts the presentation from the view you create via a meta model.

So even if you only develop web based software, the framework doesn't expect to be running in a browser environment. Thats why everything you normally use (session, HTML/JS includes, cookies) wont work in WD4J.

You may find clues that describe how to hack some issues, but I strongly advise not to. Learn how to do things the SAP/WD4J way or choose a different framework instead ...