File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Problem with addAttribute in SOAPBody Element. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Problem with addAttribute in SOAPBody Element." Watch "Problem with addAttribute in SOAPBody Element." New topic

Problem with addAttribute in SOAPBody Element.

Potti Ramesh

Joined: Mar 08, 2005
Posts: 5
This is my class file:

Class file:

import javax.xml.namespace.QName;

import javax.xml.rpc.JAXRPCException;

import javax.xml.rpc.handler.GenericHandler;

import javax.xml.rpc.handler.HandlerInfo;

import javax.xml.rpc.handler.MessageContext;

import javax.xml.rpc.handler.soap.SOAPMessageContext;

import javax.xml.soap.Name;

import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPException;

import javax.xml.soap.SOAPHeader;

import javax.xml.soap.SOAPHeaderElement;

import javax.xml.soap.SOAPMessage;

public class ClientMessageHandler extends GenericHandler{

QName[] headerNames = null;

public QName[] getHeaders(){

if (headerNames == null){

QName myHeader = new QName ("", "MessageId");

headerNames = new QName[] {myHeader};

}//End IF

return headerNames;

}//End GetHeaders

public boolean handleRequest(MessageContext context){

String messageId = "myMessageId";


SOAPMessageContext soapCntxt = (SOAPMessageContext)context;

SOAPMessage message = soapCntxt.getMessage();

SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();

SOAPBody body = message.getSOAPPart().getEnvelope().getBody();

//Add attribute to the SOAP Body

Name bodyAttribute = message.getSOAPPart().getEnvelope().createName("Id", "wsu", "http://docs.oasis-open-arg/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");


SOAPHeaderElement messageIdTag = header.addHeaderElement(message.getSOAPPart().getEnvelope().createName("MessageId", "wsa",""));



return true;

}catch (SOAPException se){

throw new JAXRPCException(se);


}//End HandleRequest

/* (non-Javadoc)

* @see javax.xml.rpc.handler.Handler#init(javax.xml.rpc.handler.HandlerInfo)


public void init(HandlerInfo arg0) {

// TODO Auto-generated method stub


System.out.println("In init handler");


}//End ClientMessageHandler

This is the output of the above program (SOAP Element). In the SOAPBody Part, I am adding attribute. but it is showing namespcae prefix like like ns-2131842456 in output instead of wsu( as i mentioned the createName function)

<soapenv:Envelope xmlns:soapenv="" xmlns:soapenc="" xmlns:xsd="" xmlns:xsi=""><soapenv:Header><wsa:MessageId xmlns:soapenv="" xmlns:soapenc="" xmlns:xsd="" xmlns:xsi="" xmlns:wsa="">myMessageId</wsa:MessageId></soapenv:Header><soapenv:Body ns-2131842456:Id="Body" xmlns:ns-2131842456="http://docs.oasis-open-arg/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><AccountInformationRequest xmlns:soapenv="" xmlns:soapenc="" xmlns:xsd="" xmlns:xsi="" xmlns:ia="" xmlns:iso20022="urn:interpay:iso:stdiso:a20022:xsd ain.001.001.01" xmlns=""><Hdr xmlns=""><ia:Sdr xmlns:ia="">Sdr</ia:Sdr><ia:SdrAppId xmlns:ia="">SdrAppId</ia:SdrAppId><ia:MsgRef xmlns:ia=""/><ia:CreDtTm xmlns:ia="">DateTime</ia:CreDtTm></Hdr><ReqBdy xmlns=""><AccInfReq xmlns=""><Ctry xmlns="">NL</Ctry><Acct xmlns="">0123456789</Acct><ReqRef xmlns="">sdadasdasdasdasdasd-asdas</ReqRef><SwtchOvReq xmlns="">false</SwtchOvReq></AccInfReq></ReqBdy></AccountInformationRequest></soapenv:Body></soapenv:Envelope>

i am using WSAD 5.1 Tool for developing this one.
I agree. Here's the link:
subject: Problem with addAttribute in SOAPBody Element.
Similar Threads
SOAPTextElement in my SOAPBody
SOAP Fault for SOAP Action property
sendind SOAP request
Does WSAD 5.1.0 support SOAP 1.2
WSAD 5.1.1 SOAP RPC return type of Object[]