How to retrieve the HTTP header as a context parameter in a Java application from the response of a web service with Soap/HTTP binding?

How to retrieve the HTTP header as a context parameter in a Java application from the response of a web service with Soap/HTTP binding?

book

Article ID: KB0092935

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix Service Grid -
Not Applicable -

Description

Description:
The response HTTP header may contain information that is useful in a Java application. The context parameter is recommended to retrieve the HTTP header. For more details, refer to our document at the Java Component Implementations : Context Parameters.

Issue/Introduction

How to retrieve the HTTP header as a context parameter in a Java application from the response of a web service with Soap/HTTP binding?

Environment

Product: TIBCO ActiveMatrix Service BusVersion:OS: All Supported Operating Systems--------------------Product: TIBCO ActiveMatrix Service GridVersion:OS: All Supported Operating Systems--------------------

Resolution

1). Add context Parameters in Component Reference.
2). In Promoted Reference->Bindings->Context Parameter Mapping, set Direction is "OUTPUT", Header Source is "HTTP_TRANSPORT_HEADERS" and Header Name is <the HTTP header you want to retrieve>.
3). In the Java application, use the code below to get the header "Content-Type" and "Expires".

//test code;
//This is test code for retrive http header "Content-Type" and "Expires" in response of Soap/Http
//We must initial MutableRequestContext before call another web service through reference.
MutableRequestContext mutableRequestContext = componentContext.createMutableRequestContext();
componentContext.setRequestContext(mutableRequestContext);
System.out.println("mutableRequestContext object has been created!");
//invoke external web service
TimeResponseDocument resp = getDateManagerPT().getCurrentTime(timezone);
 
System.out.println("--> Date Manager Component Response: \n\t\t" + resp.getTimeResponse());
CallbackContext callbackContext = mutableRequestContext.getCallbackContext();
System.out.println("callbackContext object has been created!");
String http_header1 = callbackContext.getParameter("contextParameter3", String.class);
String http_header2 = callbackContext.getParameter("contextParameter4", String.class);
System.out.println("http_header_Content_Encoding and http_header_Expires strings has been created!");
System.out.println("---------------------------------------------");
System.out.println("Content-Type = "+ http_header1);
System.out.println("Expires = "+ http_header2);


For more details, refer to the attached project. (Filename: workspace_helloworld.zip and workspace_helloworld3_fault_bag.zip).

Additional Information

https://docs.tibco.com/pub/activematrix_service_grid/3.3.0_september_2013/doc/pdf/tib_amx_it_java_component_development/tib_amx_it_java_component_development.pdf

Attachments

How to retrieve the HTTP header as a context parameter in a Java application from the response of a web service with Soap/HTTP binding? get_app
How to retrieve the HTTP header as a context parameter in a Java application from the response of a web service with Soap/HTTP binding? get_app