Date: Fri, 5 Nov 2010 10:15:06 -0600
Message-ID: <000001cb7d04$9ca48540$d5ed8fc0$_at_technologist.com>
MIME-Version: 1.0
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-Mailer: Microsoft Outlook 14.0
Thread-Index: Act9A6PtZqYaSJfCSH+OrKvl5GHRRQAAHRBg
Content-Language: en-us
I have been doing something like this to add security headers, and I =
prefer
this method. It can probably be adapted to work in your handler, pretty
easily:
WSBindingProvider bp =3D (WSBindingProvider) port;
=20
SOAPMessage message =3D null;
message =3D =
javax.xml.soap.MessageFactory.newInstance().createMessage();
SOAPHeader header =3D message.getSOAPHeader();
SOAPElement securityElement =3D header.addHeaderElement(new =
QName("
http://schemas.xmlsoap.org/ws/2002/07/secext", "Security", =
"wsse"));
securityElement.addAttribute(new QName("mustUnderstand"), "0");
SOAPElement usernameToken =3D =
securityElement.addChildElement(new =
QName("
http://schemas.xmlsoap.org/ws/2002/07/secext", "UsernameToken", =
"wsse"));
usernameToken.addChildElement("Username", =
"wsse").addTextNode("someUsername"));
usernameToken.addChildElement("Password", =
"wsse").addTextNode(MeccaProperties.getProperty("somePassword"));
Header hdr =3D Headers.create(securityElement);
bp.setOutboundHeaders(hdr);
I suspect that if in your handler you can find the SoapHeader element, =
then you could add the above
securityElement to it.
I also use the below in a handler to dump the finished SOAP message =
before transmission:
public boolean handleMessage(SOAPMessageContext context) {
SOAPMessage msg =3D context.getMessage();
boolean isOutbound =3D ((Boolean) =
context.get(SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue()=
;
try {
ByteArrayOutputStream baos =3D new ByteArrayOutputStream();
msg.writeTo(baos);
logger.fine(String.format("%s: %s", (isOutbound ? "Request" =
: "Reply"), baos.toString()));
} catch (Exception ex) {
logger.log(Level.SEVERE, "Caught exception trying to log =
SOAP", ex);
}
// allow further processing to continue
return true;
}
> -----Original Message-----
> From: Apache [mailto:apache_at_sc350.sjc.collab.net] On Behalf Of
> noreply_at_java.net
> Sent: Friday, November 05, 2010 10:08 AM
> To: users_at_glassfish.dev.java.net
> Subject: How to add JAXB object to SOAPHeader in JAX-WS SOAPHandler
>=20
> Hi,
>=20
> I have created a JAX-WS client from a business partner's WSDL. I now =
have
> many JAXB objects for everything in the WSDL/XSD.
>=20
> They have provided a data structure for me to fill in and add to the
> SOAP header which is used for message routing and authentication. =
After
> doing some reading I think the proper solution is for me to create a
> SOAPHandler that intercepts every request and adds the
> SOAPHeader. Below is a snippet of what my handleMessage method looks
> like:
>=20
> public boolean handleMessage(SOAPMessageContext msgCtx) {
> SOAPEnvelope soapEnvelope; SOAPHeader soapHeader; PartnerHeader
> partnerHeader; // JAXB object boolean isOutboundMessage =3D ((Boolean)
> msgCtx.get(
> SOAPMessageContext.MESSAGE_OUTBOUND_PROPERTY))
> .booleanValue(); if
> (isOutboundMessage) { try { soapEnvelope =3D
> msgCtx.getMessage().getSOAPPart().getEnvelope(); soapHeader =3D
> envelope.getHeader(); partnerHeader =3D new PartnerHeader(); // JAXB
> object // fill in partnerHeader JAXB object // add partnerHeader to
> soapHeader } catch .... { ... } } } Can someone please show me how to =
add the
> filled-in JAXB object into the SOAPHeader?
>=20
>=20
>=20
> Thanks,
>=20
> Ryan
>=20
>=20
> --
>=20
> [Message sent by forum member 'rdelaplante']
>=20
> View Post: http://forums.java.net/node/712962
>=20
>=20
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net