Http Header in Axis

12
How-to Guide e SAP NetWeaver 7.0 (2004s) SAP NetWeaver 7.0 (2004s) How To… How To… Set http- Header Parameters using the Axis Framework Version 1.10 – June 2008 Applicable Releases: SAP NetWeaver ’04 SAP NetWeaver 7.0 (2004s) End-to End-Process Integration Enabling Application-to-Application Processes Enabling Business-to-Business Processes

Transcript of Http Header in Axis

Page 1: Http Header in Axis

How-to Guide e SAP NetWeaver 7.0 (2004s) SAP NetWeaver 7.0 (2004s)

How To…How To… Set http-Header Parameters using the Axis Framework Version 1.10 – June 2008 Applicable Releases: SAP NetWeaver ’04 SAP NetWeaver 7.0 (2004s) End-to End-Process Integration Enabling Application-to-Application Processes Enabling Business-to-Business Processes

Page 2: Http Header in Axis

© Copyright 2007 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, and Informix are trademarks or registered trademarks of IBM Corporation in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data

contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty. These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. SAP NetWeaver “How-to” Guides are intended to simplify the product implementation. While specific product features and procedures typically are explained in a practical business context, it is not implied that those features and procedures are the only approach in solving a specific business problem using SAP NetWeaver. Should you wish to receive additional information, clarification or support, please refer to SAP Consulting. Any software coding and/or code lines / strings (“Code”) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.

Page 3: Http Header in Axis

1 Scenario As per XI 3.0 SP 20 (SAP NetWeaver 7.0 SP12, Usage Type Process Integration, respectively), HTTP header parameters can be set dynamically by means of the Axis Framework used by XI's SOAP adapter. Within the scope of this How-to guide the relevant settings will be exemplified by the parameters Cookie, Set-Cookie and SOAPAction which often occur in SOA communication scenarios. HTTP cookies are a frequently used technology to enable stateful client-server interactions. This How-to guide provides a detailed description, how cookies can be exchanged between the HTTP header and XI’s payload. According to World Wide Web Consortium (W3C), “The SOAPAction HTTP request header field can be used to indicate the intent of the SOAP HTTP request. The value is a URI identifying the intent. SOAP places no restrictions on the format or specificity of the URI or that it is resolvable. An HTTP client MUST use this header field when issuing a SOAP HTTP Request.”1 This How-to guide provides a detailed description, how the SOAPAction parameter can be set dynamically by means of the Axis Framework.

2 Introduction

2.1 What are Cookies The HTTP protocol is stateless by definition. Each HTTP call is technically independent from any precedent call. In order to enable stateful processing, session information has to be handled on client side. HTTP cookies are a common technique to associate the session on the client side to the one on the server side. The cookies contain a unique session identifier and they are passed forth and back as HTTP header parameters. Cookies are mainly used in the following use cases:

• Cookies may support server-sessions where a specific set of session data is kept on the server. This data can then be set-up, re-used, enhanced in multiple sequential HTTP calls.

• Cookies allow single sign-on to web servers. A session ID transported by the cookie parameters might be used instead of a repetitive sending of logon data.

• Cookies can be used to enable load balancing on the servers. Cookies are transported as name-value pairs of the attributes “Set-Cookie” and “Cookie” in the HTTP header. In case that a session has to be kept during a sequence of HTTP calls, the response message of the first HTTP call of that session returns the cookie information in the Set-Cookie attribute: HTTP/1.0 200 OK Content-Type: text/xml; charset=utf-8 Set-Cookie: SessionID=myOwnPrivateSession12345 All following HTTP calls sent within the scope of that session will make use of the content of the Set-Cookie parameter. The client application will have to provide the cookie information of the initial response message in all following request messages. This 1 See: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/

- 1 -

Page 4: Http Header in Axis

information is transported in the Cookie attribute of the HTTP header of the request message: POST /service/services/MyService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Host: <host>:<port> Cookie: SessionID=myOwnPrivateSession12345 The server application will than allocate the HTTP call to the correct session.

2.2 How to Handle Cookies in XI Since XI 3.0 SP 20 (SAP NetWeaver 7.0 SP12, Usage Type Process Integration, respectively), HTTP header attributes can be set and read in the SOAP adapter using the Axis Framework provided by the Adapter Engine. The content of the header attributes can be transferred from/to the DynamicConfiguration header of the XI SOAP protocol using the DynamicConfigurationHandler of the Axis Framework. The relevant settings will be explained in details in section 3. The XI-header parameters of the DynamicConfiguration (the so-called adapter-specific message attributes – ASMAs) can then be accessed (read/write) in a mapping program. The following schema provides an overview how cookies can be handled during message processing in XI.

1. During the first call (logon, session create, …) the server application creates cookie to identify the session and sends it in the Set-Cookie parameter of the HTTP header of the response message of the synchronous call.

2. The SOAP adapter transfers the header parameter “Set-Cookie” to the DynamicConfiguration header of the XI SOAP message using the Axis framework.

3. The DynamicConfiguration header of the XI SOAP message can be accessed by means of a mapping program and its content can be transferred to the message payload.

- 2 -

Page 5: Http Header in Axis

4. The client application handles the cookie within its session and adds it to the payload of all following calls belonging to that session.

5. A mapping program transfers the content of the cookie to the DynamicConfiguration header of the XI SOAP message.

6. By means of the Axis framework the content of the cookie is written to the HTTP header of synchronous request message in the SOAP adapter.

7. The server application allocates the HTTP call to the correct session.

2.3 How to set the SOAPAction HTTP Header Field dynamically The handling of the SOAPAction HTTP Header field in the Axis Framework of the SOAP adapter follows the schema of the Cookie attribute described in section 3.3: In a first step an ASMA of the DynamicConfiguration header of the XI SOAP protocol has to be filled with the relevant value (e.g. by means of a mapping). Its content is then populated to the HTTP header using the DynamicConfigurationHandler of the Axis Framework. Since the configuration for the SOAPAction header field varies slightly from the one for the Cookie attribute, it will be highlighted in section 3.4.

- 3 -

Page 6: Http Header in Axis

3 The Step By Step Solution

3.1 General settings for the Axis Framework of the SOAP adapter 1. Set up the SOAP receiver

Communication Channel to handle HTTP header parameter dynamically

It is important to set following parameters: Transport Protocol HTTP(Axis)

Message Protocol Axis

Keep XI Headers “true”

3.2 Transferring the content of Set-Cookie to the message payload

HTTP/1.0 200 OK Content-Type: text/xml; charset=utf-8 Set-Cookie: SessionID=myOwnPrivateSession12345

1. We assume that the content aimed for the cookie is provided by the Set-Cookie parameter in the HTTP message header.

2. To transfer the HTTP header parameter Set-Cookie to the XI’s Dynamic Configuration header called SetCookie add a module of type AF_Adapters/axis/HandlerBean to your processing sequence of the SOAP receiver Communication Channel created before. It has to be inserted just before the predefined module “xires”. You may choose an arbitrary name as module key (here “ dcres”)

- 4 -

Page 7: Http Header in Axis

Module Key

Parameter Name

Parameter Value

dcres handler.type

java:com.sap.aii.axis.xi.XI30DynamicConfigurationHandler

dcres key.a read http://sap.com/xi/System/HTTP SetCookie

dcres location.a

header

dcres value.a Set-Cookie

Your Module Configuration should look like this:

3. Specify the following parameters for that module

4. Set up a mapping program for the response message (here: a Message Mapping). Develop a user-defined function getHeaderParameter to transfer the content of XI’s Dynamic Configuration parameter SetCookie to the message payload.

public String getHeaderParameter(String paramName,String paramNamespace,Container container){

//write your code here

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(paramNamespace, paramName);

String value = conf.get(key);

return value;

}

5. Set up a mapping to transfer the parameter to the relevant field of your message payload. The input parameters have to follow the names of the keys of XI’s Dynamic Configuration header defined in step 3 of this section.

<Item>SessionID=myOwnPrivateSession12345</Item>

6. This field can now be evaluated in your client application and can be used in the following calls of your session.

- 5 -

Page 8: Http Header in Axis

3.3 Filling the Cookie parameter of the HTTP header 1. We assume that the content aimed

for the Cookie parameter is provided by the message payload (here: within a field called Item).

<Item>SessionID=myOwnPrivateSession12345</Item> … public String setHeaderParameter(String paramValue,String paramName,String paramNamespace,Container container){

//write your code here

DynamicConfiguration conf =(DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key =DynamicConfigurationKey.create(paramNamespace, paramName); conf.put(key, paramValue); return paramValue;

}

2. Set up a mapping program for the request mapping (here: a Message Mapping). Develop a user-defined function setHeaderParameter to transfer the content of the message payload to XI’s Dynamic Configuration parameter Cookie.

3. Set up a mapping to transfer the parameter to XI’s Dynamic Configuration parameter Cookie. The input parameters have to follow the names of the keys of XI’s Dynamic Configuration header defined in step 5 of this section (here: http://sap.com/xi/System/HTTP Cookie).

4. To transfer XI’s Dynamic Configuration header called Cookie to the HTTP header parameter Cookie you have to add two modules of type AF_Adapters/axis/HandlerBean to your processing sequence of the SOAP receiver Communication Channel created before. They have to be inserted just after the predefined module “xireq”. You may choose an arbitrary name as module key (here “ dcreq” and “rem”)

- 6 -

Page 9: Http Header in Axis

Module Key

Parameter Name

Parameter Value

dcreq handler.type

java:com.sap.aii.axis.xi.XI30DynamicConfigurationHandler

dcreq key.b write http://sap.com/xi/System/HTTP Cookie

dcreq location.b

header

dcreq value.b Cookie

rem handler.type

java:com.sap.aii.axis.soap.HeaderRemovalHandler

rem namespace

http://sap.com/xi/XI/Message/30

5. Specify the following parameters for these modules

Your Module Configuration should look like this.

Note:

1. The parameters key.c, location.c and value.c are discussed in section 3.4

2. The module “rem” has to be used in order to remove the XI specific SOAP header. POST /service/services/MyService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Host: <host>:<port> SOAPAction: "urn:doSomething" Cookie: SessionID=myOwnPrivateSession12345

6. The header of your HTTP request looks like the following

- 7 -

Page 10: Http Header in Axis

3.4 Filling the SOAPAction parameter of the HTTP header

<Item>urn:doSomethingDifferent</Item>

1. We assume that the content aimed for the SOAPAction parameter is provided by the message payload (here: within a field called Item).

public String setHeaderParameter(String paramValue,String paramName,String paramNamespace,Container container){

//write your code here

DynamicConfiguration conf =(DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION); DynamicConfigurationKey key =DynamicConfigurationKey.create(paramNamespace, paramName); conf.put(key, paramValue); return paramValue;

}

2. Set up a mapping program for the request mapping (here: a Message Mapping). Develop a user-defined function setHeaderParameter to transfer the content of the message payload to XI’s Dynamic Configuration parameter THeaderSOAPACTION (You may reuse the user-defined function of step 2 of section 3.3).

3. Set up a mapping to transfer the parameter to XI’s Dynamic Configuration parameter THeaderSOAPACTION. The input parameters have to follow the names of the keys of XI’s Dynamic Configuration header defined in step 5 of this section. You can make use of the Adapter-Specific Message Attribute http://sap.com/xi/XI/System/SOAP THeaderSOAPACTION of the SOAP adapter.

4. To transfer XI’s Dynamic Configuration header called THeaderSOAPACTION to the HTTP header parameter SOAPAction, add two modules of type AF_Adapters/axis/HandlerBean to your processing sequence of the SOAP receiver Communication Channel created before. They have to be inserted just after the predefined module “xireq”. You may choose an arbitrary name as module key (here “ dcreq” and “rem”)

- 8 -

Page 11: Http Header in Axis

- 9 -

Module Key

Parameter Name

Parameter Value

xireq defaultSOAPAction

urn:doSomething

xireq handler.type

java:com.sap.aii.axis.xi.XI30OutboundHandler

dcreq handler.type

java:com.sap.aii.axis.xi.XI30DynamicConfigurationHandler

dcreq key.c write http://sap.com/xi/XI/System/SOAP THeaderSOAPACTION

dcreq location.c

context

dcreq value.c javax.xml.rpc.soap.http.soapaction.uri

rem handler.type

java:com.sap.aii.axis.soap.HeaderRemovalHandler

rem namespace

http://sap.com/xi/XI/Message/30

Your Module Configuration should look like this.

Note:

1. It is mandatory to set the parameter defaultSOAPAction in module xireq

5. Specify the following parameters for these modules

2. The parameters key.b, location.b and value.b are discussed in section 3.3.

3. The module “rem” has to be used in order to remove the XI specific SOAP header.

POST /service/services/MyService HTTP/1.0 Content-Type: text/xml; charset=utf-8 Host: <host>:<port> SOAPAction: "urn:doSomethingDifferent" Cookie: SessionID=myOwnPrivateSession12345

6. The header of your HTTP request looks like the following

Page 12: Http Header in Axis

www.sdn.sap.com/irj/sdn/howtoguides