Jump to content

Java Webservice Doubt.


Recommended Posts

Posted

My 2 cents....

 

<?xml version="1.0"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="1">
<wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1">
<wsse:Username>yourusername</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">yourpassword</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</soapenv:Header>
<soapenv:Body>
<yourbodygoeshere>
</soapenv:Body>
</soapenv:Envelope>

Posted

if you are using SOAPFactory soapFactory = SOAPFactory.newInstance();

 

You can try this..

try {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPFactory factory = SOAPFactory.newInstance();
String prefix = "wsse";
String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
SOAPElement securityElem =
factory.createElement("Security", prefix, uri);
SOAPElement tokenElem =
factory.createElement("UsernameToken", prefix, uri);
tokenElem.addAttribute(QName.valueOf("wsu:Id"), "UsernameToken-2");
tokenElem.addAttribute(QName.valueOf("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement userElem =
factory.createElement("Username", prefix, uri);
userElem.addTextNode(login);
SOAPElement pwdElem =
factory.createElement("Password", prefix, uri);
pwdElem.addTextNode(pwd);
pwdElem.addAttribute(QName.valueOf("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
tokenElem.addChildElement(userElem);
tokenElem.addChildElement(pwdElem);
securityElem.addChildElement(tokenElem);
SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);

} catch (Exception e) {
e.printStackTrace();
}

Posted

if you are using SOAPFactory soapFactory = SOAPFactory.newInstance();

 

You can try this..

try {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPFactory factory = SOAPFactory.newInstance();
String prefix = "wsse";
String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
SOAPElement securityElem =
factory.createElement("Security", prefix, uri);
SOAPElement tokenElem =
factory.createElement("UsernameToken", prefix, uri);
tokenElem.addAttribute(QName.valueOf("wsu:Id"), "UsernameToken-2");
tokenElem.addAttribute(QName.valueOf("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement userElem =
factory.createElement("Username", prefix, uri);
userElem.addTextNode(login);
SOAPElement pwdElem =
factory.createElement("Password", prefix, uri);
pwdElem.addTextNode(pwd);
pwdElem.addAttribute(QName.valueOf("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
tokenElem.addChildElement(userElem);
tokenElem.addChildElement(pwdElem);
securityElem.addChildElement(tokenElem);
SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);

} catch (Exception e) {
e.printStackTrace();
}

copied from http://java.dzone.com/articles/jax-ws-header-part-1-client

Posted

if you are using SOAPFactory soapFactory = SOAPFactory.newInstance();

 

You can try this..

try {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPFactory factory = SOAPFactory.newInstance();
String prefix = "wsse";
String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
SOAPElement securityElem =
factory.createElement("Security", prefix, uri);
SOAPElement tokenElem =
factory.createElement("UsernameToken", prefix, uri);
tokenElem.addAttribute(QName.valueOf("wsu:Id"), "UsernameToken-2");
tokenElem.addAttribute(QName.valueOf("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement userElem =
factory.createElement("Username", prefix, uri);
userElem.addTextNode(login);
SOAPElement pwdElem =
factory.createElement("Password", prefix, uri);
pwdElem.addTextNode(pwd);
pwdElem.addAttribute(QName.valueOf("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
tokenElem.addChildElement(userElem);
tokenElem.addChildElement(pwdElem);
securityElem.addChildElement(tokenElem);
SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);

} catch (Exception e) {
e.printStackTrace();
}

 

Ohk I tried. but When I tried to print header 

 

It's says [S:Header: null]

Posted

check this...

 

// add an <AuthenticationInfo> node with a <UserName> subnode
// to the SOAP Header
SOAPHeaderElement header = new SOAPHeaderElement(
"urn:thisNamespace", "AuthenticationInfo");
SOAPElement node = header.addChildElement("UserName");
node.addTextNode("John Doe");
((Stub) service).setHeader(header);

Posted

my opinion :

 

if you have generated clients, did you use cxf and binding-jxab to generate classes??

 

if yes, then use those classes (interface) to login first then make a actual call.

 
Posted

Ohk I tried. but When I tried to print header 

 

It's says [S:Header: null]

 

this should have worked for you, if you are getting null which mean there is some exception in between when you are not tracking ...

inkaa simple gaa rayaliii antee

SOAPEnvelope soapEnvelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.addHeader();
SOAPElement securityElement = soapHeader.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameTokenElement = securityElement.addChildElement("UsernameToken", "wsse");
SOAPElement uName = usernameTokenElement.addChildElement("Username", "wsse");
uName.addTextNode("AFDB");
SOAPElement pwd = usernameTokenElement.addChildElement("Password", "wsse");
pwd.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
pwd.addTextNode("LOLBOB");

If you already have header setup then change line to by getting the header instead of adding

Posted

if you are using SOAPFactory soapFactory = SOAPFactory.newInstance();

 

You can try this..

try {
SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
SOAPFactory factory = SOAPFactory.newInstance();
String prefix = "wsse";
String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
SOAPElement securityElem =
factory.createElement("Security", prefix, uri);
SOAPElement tokenElem =
factory.createElement("UsernameToken", prefix, uri);
tokenElem.addAttribute(QName.valueOf("wsu:Id"), "UsernameToken-2");
tokenElem.addAttribute(QName.valueOf("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement userElem =
factory.createElement("Username", prefix, uri);
userElem.addTextNode(login);
SOAPElement pwdElem =
factory.createElement("Password", prefix, uri);
pwdElem.addTextNode(pwd);
pwdElem.addAttribute(QName.valueOf("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
tokenElem.addChildElement(userElem);
tokenElem.addChildElement(pwdElem);
securityElem.addChildElement(tokenElem);
SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);

} catch (Exception e) {
e.printStackTrace();
}

 

Yes bro it worked. 

 

Thanks a lot. 

 

this should have worked for you, if you are getting null which mean there is some exception in between when you are not tracking ...

inkaa simple gaa rayaliii antee

SOAPEnvelope soapEnvelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnvelope.addHeader();
SOAPElement securityElement = soapHeader.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameTokenElement = securityElement.addChildElement("UsernameToken", "wsse");
SOAPElement uName = usernameTokenElement.addChildElement("Username", "wsse");
uName.addTextNode("AFDB");
SOAPElement pwd = usernameTokenElement.addChildElement("Password", "wsse");
pwd.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
pwd.addTextNode("LOLBOB");

If you already have header setup then change line to by getting the header instead of adding

 

SOAP:BODY ni sarigga print cheyyaledu anduke koncham confuse ayyanu 

 

I was trying with 

              System.out.println("soap message : " + soapMessageContext.getMessage().getSOAPPart().getEnvelope().getBody());
 
 

did SOAPBODY.writeTo(System.out);

 

And moreover stubs are created with JAXElement<T> 's but I tiried to pass T class directly akkada stuck ayyanu .. but stacktrace chesi errors ni chusukunna 

 

Now able to send the request completely .. 

 

Thanks a lot bayya's 

Posted

my opinion :

 

if you have generated clients, did you use cxf and binding-jxab to generate classes??

 

if yes, then use those classes (interface) to login first then make a actual call.

 

Thanks mayya ... finally worked.

×
×
  • Create New...