cancel
Showing results for 
Search instead for 
Did you mean: 

Can we access HttpServletRequest Object in Webdynpro ?

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

vijayakhanna_raman
Active Contributor
0 Kudos

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

Former Member
0 Kudos

java.lang.NoClassDefFoundError: com/sap/tc/webdynpro/services/sal/adapter/core/IWebContextAdapter

Former Member
0 Kudos

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

http://www.NetWeaverTeam.com

Former Member
0 Kudos

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"

Former Member
0 Kudos

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

http://www.NetWeaverTeam.com

Former Member
0 Kudos

Hi,

We have an analogous code in NW04s, but I do not see a method to get the user. Any workarounds here ?

IWDRequest req = WDProtocolAdapter.getProtocolAdapter().getRequestObject();

req.getClientHostName();

Answers (2)

Answers (2)

Former Member
0 Kudos

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();

Former Member
0 Kudos

Thank You Mohamed... that works just fine!

Former Member
0 Kudos

You can use the below code in CE 7.1 or above versions.

IWDRequest requestObj = ((IWDProtocolAdapter) WDProtocolAdapter.getProtocolAdapter()).getRequestObject();

HttpServletRequest request = (HttpServletRequest)requestObj.getProtocolRequest();

Former Member
0 Kudos

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

chintan_virani
Active Contributor
0 Kudos

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>