File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Problem with addAttribute in SOAPBody Element." Watch "Problem with addAttribute in SOAPBody Element." New topic
Author

Problem with addAttribute in SOAPBody Element.

Potti Ramesh
Greenhorn

Joined: Mar 08, 2005
Posts: 5
Hi
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 ("http://www.w3.org/2005/08/addressing", "MessageId");


headerNames = new QName[] {myHeader};

}//End IF

return headerNames;


}//End GetHeaders


public boolean handleRequest(MessageContext context){

String messageId = "myMessageId";


try{


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");

body.addAttribute(bodyAttribute,"Body");


SOAPHeaderElement messageIdTag = header.addHeaderElement(message.getSOAPPart().getEnvelope().createName("MessageId", "wsa","http://www.w3.org/2005/08/addressing"));

messageIdTag.addTextNode(messageId);

System.out.println(message.getSOAPPart().getEnvelope().toString());

return true;


}catch (SOAPException se){

throw new JAXRPCException(se);


}//End TRY_CATCH


}//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

super.init(arg0);

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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Header><wsa:MessageId xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:wsa="http://www.w3.org/2005/08/addressing">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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ia="http://www.interpay.nl/InterActive/schemas/core/v1.0/" xmlns:iso20022="urn:interpay:iso:stdiso:a20022:xsd ain.001.001.01" xmlns="http://www.interpay.nl/InterActive/AccountInformation"><Hdr xmlns=""><ia:Sdr xmlns:ia="http://www.interpay.nl/InterActive/schemas/core/v1.0/">Sdr</ia:Sdr><ia:SdrAppId xmlns:ia="http://www.interpay.nl/InterActive/schemas/core/v1.0/">SdrAppId</ia:SdrAppId><ia:MsgRef xmlns:ia="http://www.interpay.nl/InterActive/schemas/core/v1.0/"/><ia:CreDtTm xmlns:ia="http://www.interpay.nl/InterActive/schemas/core/v1.0/">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.
 
 
subject: Problem with addAttribute in SOAPBody Element.