• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to bind soap header using jax-rpc  RSS feed

 
John Smith
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 577
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi John,
Trying using SAAJ API.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!