cancel
Showing results for 
Search instead for 
Did you mean: 

Acess "set-cookie" and set later in lookup in UDF?

Former Member

Hello Experts,

I' have a senario where I need to get a session ID in order to handle a series of web service request. Therefore I have written a UDF in the mapping where the first method (as login message) where I get a login key as payload and the session-id in the response header. This session Id then needs to be set before several other calls within the same udf are made to the webservice. We are not able to use the Axis-adapter and therefore have to use the normal SOAP-adapter.

My question now is, is there any way to access the header of the first response message? I need to read the returned session-id and then write it to the other requests. Any idea?

regards

Christian

0 Kudos

Hi Christian,

Can you share the UDF, how you have taken the session-id from the response header. I have similar requirement.

Regards.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor

Hi Christian,

Can you show us your UDF? Maybe this blog can help:

Simple Way to Get HTTP Response Header in Java • Crunchify

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

for sure I can post the UDF. This UDF that I have written is a generic UDF that I call from several other UDF's where ever I need to create a lookup:


AbstractTrace trace = container.getTrace();
String returnValue = "";

try {
   
  Channel channel =  LookupService.getChannel(party,communicationComponent, communicationChannel);
  SystemAccessor accessor = LookupService.getSystemAccessor(channel);     

  InputStream inputStream = new ByteArrayInputStream(requestXMLString.getBytes());
  XmlPayload payload = LookupService.getXmlPayload(inputStream);

  Payload SOAPOutPayload = null;  

  /*The SOAP call is made here and the response obtained is in the SOAPOutPayload.*/     
  SOAPOutPayload = accessor.call(payload);   

  /* Parsing the Returnvalue     */
  InputStream inp = SOAPOutPayload.getContent();     
  DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();   

  /* Build DOM Structure for Input XML */     
  DocumentBuilder builder = factory.newDocumentBuilder();     
  Document document = builder.parse(inp);  

  /* Set the XML-Tag for the Response  */     
  NodeList list = document.getElementsByTagName(requestXMLValueTag);
 
  Node node = list.item(0);     
  if (node != null)
  {          
   node = node.getFirstChild();
   if (node != null)
   {               
    returnValue = node.getNodeValue();          
   }     
  }
} catch (Exception e)
{     
  trace.addWarning("Error" + e);
}

return returnValue;

So within this function I need to access the set-cookie and then set it accordingly. If have you have any suggestions I'm very happy to hear about it.

I don't think that I can use your link that you posted as I don't have a URLConnection-Object


Can you show us your UDF? Maybe this blog can help:

Simple Way to Get HTTP Response Header in Java • Crunchify

regards

Christian

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Christian,

I think dynamic configuration will not work for lookups. If they did, all you have to do is to check variable transport binding and then enter the name of the header e.g in a SOAP UI test:

In sender/receiver cc, check variable transport binding and place the name (ASMA should also be checked).

And in moni:

XHeaderName1 value can be obtained using Dynamic Config for UDF.

You need to use a UDF similar to the link I posted above.

And here it is in test tab:

PS: I am using an HTTP Proxy. If you are not using a proxy, just use

URLConnection conn = url.openConnection();

Hope this helps,

Mark

Former Member
0 Kudos

Thanks for the tip. But I can't use code example as I don't use the Connection-Object. I use the Accessor-Object for the call:


/*The SOAP call is made here and the response obtained is in the SOAPOutPayload.*/       

  SOAPOutPayload = accessor.call(payload);

How can I access the UDF within the accessor-Object?

Regards

Christian

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Christian,

I'm afraid it is not possible.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

so is there anyway In updating or changeing my udf in order to use the conection-object rather than the accessor-object?

Regards

Christian

rajakumar
Explorer
0 Kudos

Hi Christain,

Try SOAP call like this and get the header info from the response.

How to do a SOAP Web Service call from Java class? - Stack Overflow

Regards,

Rajakumar

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Christian,

Here is a POC that connects to this webservice StockQuote Web Service using SOAP 1.1 specifications:

For this to work, you need to import com.sap.aii.utilxi.core.io.IOUtil (you can find it in your local java directory) as an imported archive and refer it

to archives used.

The response HTTP Headers are on the left side, the SOAP Output is on the left.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

that looks really great! I've got one little problem:

I can't find the required jar: com.sap.aii.utilxi.core.io.IOUtil

I can only find these jar-files on our pi-system under /j2ee/cluster/bin/ext/com.sap.xi.util.misc/lib

  • com.sap.aii.proxy.gen.jar
  • com.sap.aii.utilxi.core.jar
  • com.sap.aii.utilxi.server.jar

Where can I find the jar-file that you have mentioned?

Regards

Christian

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Christian,

When you open ESR, the jar files are automatically downloaded in your user directory in windows. Say for example in Windows 7, here is the path:

PS: Do not use the 1KB jar files, they are just shortcuts.

Hope this helps,

Mark

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Christian,

use comp.sap.aii.utixi.core.jar. Import it as an imported archive.

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

thank for teh response. I got it working with your description!

regards

Christian

ahmad_shaik
Explorer
0 Kudos

Hi Mark,

I have same requirement but need to connect through REST adapter. Any solution for this .

My Senorio Proxy to APi (REST) Synchronous.

Answers (1)

Answers (1)

0 Kudos

Hi Christian,

Can you share the UDF, how you have taken the session-id from the response header. I have similar requirement.

Regards.