Search code examples
javasoapheaderapache-axis

how to add a http header to a soaprequest in java


I try to connect to a Yahoo webservice. I generated the classes by axis2. The problem I am facing right now is, that the webservice requires a specific key value pair in the header and I am absolutely not able, to do so. I searched the web and found different possibilities - none of them worked for me. The most promissing was the post nearly at the end of this page, were Claude Coulombe sugested to change the code of the generated stub, but this failed as well. Can anybody show me a way how to solve this issue?

Edit

The suggested way using Options produced the following exception:

Exception in thread "main" org.apache.axis2.AxisFault: Address information does not exist in the Endpoint Reference (EPR).The system cannot infer the transport mechanism.

Here is my code:

val stub = new IndexToolsApiServiceStub("https://api.web.analytics.yahoo.com/IndexTools/services/IndexToolsApiV3")

val client = stub._getServiceClient
val options = new Options
val list = new ArrayList[Header]()
val header = new Header
header.setName("YWA_API_TOKEN")
header.setValue("NOTtheREALvalue")
list.add(header)
options.setProperty(HTTPConstants.HTTP_HEADERS, list)
client.setOptions(options)
stub._setServiceClient(client)

Solution

  • I found a solution for the problem two months ago. You are not able to set a customized header with Axis2. So I fell back to the older Axisversion, where you can do it. Setting the Http-header by yourself is no good practice and mostly unneccesary. On top it is not a part of the SOAP-specification. That is the reason why you cannot do it with Axis2.