• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem with addAttribute in SOAPBody Element.

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic