This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Web Services and the fly likes How to bind soap header using jax-rpc Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Web Services
Reply Bookmark "How to bind soap header using jax-rpc" Watch "How to bind soap header using jax-rpc" New topic
Author

How to bind soap header using jax-rpc

John Smith
Ranch Hand

Joined: Aug 21, 2004
Posts: 48
To Whom It May Concern:

I am using Rad7, Ibm Websphere 6.1, on Windows XP.
I created an SoapHeader first using a string and bind it using jax-ws.
It works for jax-ws but unfortunately, my work services uses jax-rpc.
Does anybody know how to bind the soap header using jax-rpc.

Any help or hint would be greatly appreciated it.

Here is my code:


import org.apache.cxf.headers.Header;
import org.apache.cxf.headers.Header.Direction;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.binding.soap.SoapHeader;

import javax.xml.namespace.QName;
import java.io.StringReader;
import java.util.List;
import java.util.ArrayList;
import javax.xml.ws.BindingProvider;


@Test
public void testService() throws Exception {
try
{

URL wsdlURL = new URL("http://localhost:9087/abc/services/ServiceABCService");
ServiceRequestServiceService service = new ServiceRequestServiceServiceLocator();
ServiceRequestService port = service.getServiceRequestService(wsdlURL);

//How to Add Soap Header using jax-ws


String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ABCHdrRq "
+ "xmlns=\"http://xmlns.ABCgc.net/ABC/2002/header/\" "
+ ">"
+ "<version>1.0</version><srcInfo><chType>abc</chType><chInst>0124</chInst>" +
"<appName>sSAR</appName><hostName>DW70210521</hostName><userId>fxue</userId>" +
"</srcInfo><startTimeStamp>2010-06-04T13:44:45.132</startTimeStamp><clientDt>2010-06-04T13:44:53.242</clientDt><serviceInfo><serviceName>ServiceRequestService</serviceName>" +
"<serviceFunc>addServiceRequest</serviceFunc></serviceInfo>" +
"<prevTransInfo><prevRqUID>BORS2010-06-04T13:41:10.2067f9368d1-8c5c</prevRqUID>" +
"<prevRespTimestamp>2010-06-04T13:41:10.871</prevRespTimestamp>"+
"<prevRespEndTimestamp>2010-06-04T13:41:10.902</prevRespEndTimestamp>+</prevTransInfo>"+
"</ABCHdrRq>";
SoapHeader dummyHeader1 = new SoapHeader(new QName("uri:http://xmlns.ABCgc.net/ABC/2002/header/", "ABCHdrRq"),
DOMUtils.readXml(new StringReader(xml)).getDocumentElement());
dummyHeader1.setDirection(Direction.DIRECTION_OUT);
List<Header> headers = new ArrayList<Header>();
headers.add(dummyHeader1);

((BindingProvider)port).getRequestContext().put(Header.HEADER_LIST, headers);

//How to Add Soap Header to the request using jax-ws

}
catch(Exception e)
{
System.out.println("Exception message:"+e.getMessage());
}
}

Yours,

Frustrated
Naren Chivukula
Ranch Hand

Joined: Feb 03, 2004
Posts: 542

Hi John,
Trying using SAAJ API.


Cheers,
Naren (SCJP, SCDJWS and SCWCD)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: How to bind soap header using jax-rpc
 
Similar Threads
How to create SOAP Header elements in SAAJ?
Adding JAXB object to Soap Header
Testing Web Services
Basic SOAP Header Question
sending pdf or any attachment from a java webservice to java client using JAX-WS and SAAJ