cancel
Showing results for 
Search instead for 
Did you mean: 

Get a cookie from web dynpro application

0 Kudos

Hi everybody!

I am developing a web dynpro component and I need to get the value of the MYSAPSSO2 cookie. I have tried hard but I can not get that value. I am using the classes if_http_client, if_http_server and if_http_request but I sting have not get any result. I do not what I am doing wrong or whether I am completely lost.

My program:

path_sap = 'http://sapdes.metrovacesa.es:8002/sap/bc/webdynpro/sap/zwd_docs_empleado?sap-language=ES'.

name_Cookie = 'MYSAPSSO2'.

CALL METHOD cl_http_client=>create_by_url

EXPORTING

url = path_sap

IMPORTING

client = http_client

EXCEPTIONS

argument_not_found = 1

plugin_not_active = 2

internal_error = 3

OTHERS = 4.

CALL METHOD HTTP_CLIENT->request->get_cookie

exporting

name = name_Cookie

path = '/''

importing

value = value_Cookie.

sap_path is the url of the web dynpro component. Can somebody help me?

Greetings from Spain.

Accepted Solutions (1)

Accepted Solutions (1)

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

Web dynpro applications should never be designed to interact with client side cookies becuause doing so would break the client independence ( what happens if your WD applicaiton runs in the NWBC SmartClient or the Flex Client?). CL_HTTP_CLIENT class is use when you want ABAP to act as the web browser and make an HTTP call to another server. It can't be used to interact with the incomming request object from within Web Dynpro.

Why do you want to access the SSO cookie in the first place?

0 Kudos

My application has to call a web service that is located in another server. In this call, I need to send the value of the cookie as a paremeter because the web service validate the user. This is the reason why I try to get the cookie first. I do not know if I need to use de HTTP_CLIENT or I could retrieve the cookie value in a different way.

After retrieving the cookie, I am calling a web service with HTTP_CLIENT class and it is running OK (Obviusly I wrote hard code instead of the cookie value).

Thanks!

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I seriously doubt the reuse of the SSO cookie would be supported in such a manner. The SSO cookie would only work with another SAP system - ABAP or JAVA. Why would you use HTTP_CLIENT class directly if talking to another SAP system.

At the least you should use an RFC destination (of type G - HTTP) and use the Logon & Security tab to specify that you want to Send a Logon Ticket.

0 Kudos

The cookie will not be reused. I just need to send its value because the web service (developed in vb.net) decrypt this value and obtain the user ID (necesary to intentify him).

In conclusion, I need to get the cookie value in order to send it, is it possible?

Thanks a lot!

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

This doesn't sound like correct usage of the sso cookie>. you do know that the user id is stored in variable sy-uname. You can just send that value to the web service.

0 Kudos

So that, you don't know the solucion, do you?

Obviusly I know the sy-uname variable but for security reason I shouldn't send it to the web service because its value could be manipulated and my application access to confidential documents (like payrolls).

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

>

> So that, you don't know the solucion, do you?

I do believe that I recommend a solution to you earlier based upon the use of a HTTP Destination from SM59. This would be the only SAP supported approach to using a SSO ticket in the way you describe.

You should not try and hi-jack the SSO ticket that was generated for the browser access to a WDA application.

0 Kudos

You told me that I should take a solution based in RFC, maybe you are right, but I would need you to give some advice a more specific.

In the way I am working (with http_client), I am very close to te solution.

Greetings.

thomas_jung
Developer Advocate
Developer Advocate
0 Kudos

I never said to use RFC. I said that you sue use an HTTP destination that has been setup in SM59. This allows for greater control over the connection parameters, but this SM59 destination can still be used with CL_HTTP_CLIENT. It just means that you would use CL_HTTP_CLIENT=>CREATE_BY_DESTINATION as the starting point of your CL_HTTP_CLIENT_CODING.

Answers (2)

Answers (2)

Former Member
0 Kudos
former_member185029
Active Contributor
0 Kudos

Refer to the code written in this post.

The person did not find the solution yet.