on 06-21-2006 8:24 AM
Hi,
Can we access the HttpServletRequest Object in Webdynpro view controller code ? I would like typed access to this object so as to invoke some methods e.g getCookies and getRemoteUser.
Reg, Sameer.
Hi,
Yes. We can access it. Have a look at this code.
HttpServletRequest req =((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter)WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
Cookie[] cookies = req.getCookies();
for ( int i=0; i<cookies.length; i++) {
wdComponentAPI.getMessageManager().reportSuccess(cookies.getName());
wdComponentAPI.getMessageManager().reportSuccess(cookies.getValue());
}
Add the appropriate jar file com.tssap.ext.libs.j2ee_1.3/lib/servlet.jar and check.
.
Regards,
Vijayakhanna Raman
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sameer,
You answered yourself.
It is forbidden to access non-API classes in WD.
Your IDE is NW04 and it contains (mistakenly) some internal classes, so your code compiles.
Your WebAS, on other hand, is NW04s and internal implementation was changed. Hence you get NoClassDefFoundError.
Rely only on API classes.
To access some HttpServletRequest variables you may create servlet that gets these variables, then append them as startup parameters of WD application URL and redirects to this URL. This way in WD you simple access Startup Inbound Plug parameters.
Valery Silaev
EPAM System
Hi Valery,
What if I port my application code to a NW04s IDE ? Would it work then ? Actually the method described by Vijay is really simple and takes care of an issue for which otherwise I'll have to use UME (alongwith client_cert) authentication etc which is too complex and till now not doable according to internal policies for getting SSO_CA certificates.
The work around which you suggested is also ok, but I do not know how to do that esp. "append them as startup parameters of WD application URL and redirects to this URL"
Sameer,
<i>What if I port my application code to a NW04s IDE ? Would it work then ?</i>
It will not even be compiled.
<i>The work around which you suggested is also ok, but I do not know how to do that esp. "append them as startup parameters of WD application URL and redirects to this URL"</i>
In servlet do something like this (do not remeber exact coding):
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) {
res.sendRedirect(
"http://host:53000/webdynpro/dispatcher/local/YourApp"
+ "?remoteUser=" + req.getRemoteUser();
}
}
Then you can declare parameter named "remoteUser" type string in inbound startup plug of interface view of main component of WD application and use it.
Valery Silaev
EPAM Systems
You can use the below code in SAP J2EE 7.0 version.
IRequest requestObj = ((IProtocolAdapter) WDProtocolAdapter.getProtocolAdapter()).getRequestObjectInternal();
HttpServletRequest request = (HttpServletRequest)requestObj.getProtocolRequest();
IResponse responseObj = ((IProtocolAdapter) WDProtocolAdapter.getProtocolAdapter()).getResponseObjectInternal();
HttpServletResponse response = (HttpServletResponse)responseObj.getProtocolResponse();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
In our NW04 SP16 implementation of Netweaver portal we had used
HttpServletRequest objRequest = (IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
String strShipHostName = objRequest.getServerName();
to get the hostname of the server (if its myserver.jay.net/webdynpro/.... it will return myserver.jay.net) on which the application is hosted. Can any body help us to know how to do it in NW04s?
Please help.
Regards
Jay Kapadia
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jay,
You can use the following code to get localhost name:-
try
{
String strName1=InetAddress.getLocalHost().getHostName();
String strName2=InetAddress.getLocalHost().getHostAddress();
}
catch(Exception e)
{
wdComponentAPI.getMessageManager().reportException("exception is : "+e.getMessage(),true);
}
And then do Organize Imports for adding the import for InetAddress class.
<b>- Chintan</b>
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.