本文整理匯總了Java中javax.xml.soap.SOAPEnvelope.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPEnvelope.addHeader方法的具體用法?Java SOAPEnvelope.addHeader怎麽用?Java SOAPEnvelope.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPEnvelope
的用法示例。
在下文中一共展示了SOAPEnvelope.addHeader方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean request = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!request) {
try {
SOAPMessage msg = context.getMessage();
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPHeader header = env.getHeader();
if (header == null) {
header = env.addHeader();
return false;
}
Node node = (Node) header.getElementsByTagName("token").item(0);
String token = node.getChildNodes().item(0).getNodeValue();
if (token != null && token.equals("Kalango Lab")) {
System.out.println("Token válido");
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
return true;
}
示例2: handleRequest
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Adds an "Access" element to the SOAP header
*/
public boolean handleRequest(MessageContext msgct) {
if (msgct instanceof SOAPMessageContext) {
SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
try {
SOAPMessage msg = smsgct.getMessage();
SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
SOAPHeader header = msg.getSOAPHeader();
if (header == null)
header = envelope.addHeader(); // add an header if non exists
SOAPHeaderElement accessElement = header.addHeaderElement(envelope.createName("Access", "ns0", JPLAG_TYPES_NS));
SOAPElement usernameelem = accessElement.addChildElement("username");
usernameelem.addTextNode(username);
SOAPElement passwordelem = accessElement.addChildElement("password");
passwordelem.addTextNode(password);
SOAPElement compatelem = accessElement.addChildElement("compatLevel");
compatelem.addTextNode(compatibilityLevel + "");
} catch (SOAPException x) {
System.out.println("Unable to create access SOAP header!");
x.printStackTrace();
}
}
return true;
}
示例3: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
// Indicator telling us which direction this message is going in
final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
// Handler must only add security headers to outbound messages
if (outInd.booleanValue()) {
try {
// Get the SOAP Envelope
final SOAPEnvelope envelope = msgCtx.getMessage().getSOAPPart().getEnvelope();
// Header may or may not exist yet
SOAPHeader header = envelope.getHeader();
if (header == null)
header = envelope.addHeader();
// Add WSS Usertoken Element Tree
final SOAPElement security = header.addChildElement("Security", "wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
final SOAPElement userToken = security.addChildElement("UsernameToken", "wsse");
userToken.addChildElement("Username", "wsse").addTextNode(userId);
userToken.addChildElement("Password", "wsse").addAttribute(new QName("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText").addTextNode(password);
} catch (final Exception e) {
e.printStackTrace();
return false;
}
}
return true;
}
示例4: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* The method is invoked for normal processing of outbound messages.
*
* @param context
* the message context.
* @return An indication of whether handler processing should continue for
* the current message. Return <code>true</code> to continue
* processing.
*
* @throws Exception
* Causes the JAX-WS runtime to cease fault message processing.
**/
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean request_p = (Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (request_p.booleanValue()) {
try {
SOAPMessage msg = context.getMessage();
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPHeader hdr = env.getHeader();
if (hdr == null) {
hdr = env.addHeader();
}
QName qname_user = new QName("http://com/auth/", "auth");
SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
helem_user.setActor(VERSION);
if (version != null && version.trim().length() != 0) {
helem_user.addTextNode(version);
}
msg.saveChanges();
message = soapMessage2String(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
示例5: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* The method is invoked for normal processing of outbound messages.
*
* @param context
* the message context.
* @return An indication of whether handler processing should continue for
* the current message. Return <code>true</code> to continue
* processing.
*
* @throws Exception
* Causes the JAX-WS runtime to cease fault message processing.
**/
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean request_p = (Boolean) context
.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (request_p.booleanValue()) {
try {
SOAPMessage msg = context.getMessage();
SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
SOAPHeader hdr = env.getHeader();
if (hdr == null) {
hdr = env.addHeader();
}
QName qname_user = new QName("http://com/auth/", "auth");
SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
helem_user.setActor(VERSION);
if (version == null || version.trim().length() == 0) {
helem_user.addTextNode(apiVersionInfo.getProperty(VERSION));
} else {
helem_user.addTextNode(version);
}
msg.saveChanges();
message = soapMessage2String(msg);
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}
示例6: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {
Boolean result = Boolean.TRUE;
// Indicator telling us which direction this message is going in
final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
// Handler must only add security headers to outbound messages
if (outInd) {
try {
// Get the SOAP Envelope
final SOAPEnvelope envelope = msgCtx.getMessage().getSOAPPart().getEnvelope();
// Header may or may not exist yet
SOAPHeader header = envelope.getHeader();
if (header == null)
header = envelope.addHeader();
// Add WSS Usertoken Element Tree
final SOAPElement security = header.addChildElement("Security", "wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
final SOAPElement userToken = security.addChildElement("UsernameToken", "wsse");
userToken.addChildElement("Username", "wsse").addTextNode(this.username);
userToken.addChildElement("Password", "wsse").addTextNode(this.password);
}
catch (final Exception e) {
log.warn(e);
result = Boolean.FALSE;
}
}
return result;
}
示例7: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (userAgent != null || userAgent.trim().length() < 1) {
if (outboundProperty.booleanValue()) {
try {
SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = envelope.getHeader();
if (header == null) {
header = envelope.addHeader();
}
SOAPElement security = header.addChildElement("userAgent", "commons",
"http://commons.ws.projectdirector.gs4tr.org");
security.addTextNode(userAgent);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
// SOAPMessage message = smc.getMessage();
// message.writeTo(System.out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
} else {
throw new NullPointerException("UserAgent is null or empty");
}
return outboundProperty;
}
示例8: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
SOAPEnvelope envelope = smc.getMessage().getSOAPPart().getEnvelope();
SOAPHeader header = envelope.addHeader();
SOAPElement security =
header.addChildElement("Security", "ns1", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameToken =
security.addChildElement("UsernameToken", "ns1");
usernameToken.addAttribute(new QName("xmlns:ns1"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement username =
usernameToken.addChildElement("Username", "ns1");
username.addTextNode(userName);
SOAPElement password =
usernameToken.addChildElement("Password", "ns1");
password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.addTextNode(pwd);
} catch (Exception e) {
e.printStackTrace();
}
} else {
// Put you response handler here
}
return outboundProperty;
}
示例9: addWssHeader
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Adds a webservices security header containing username/password credentials and
* optionally a Fortify authentication token
* @param envelope The soap envelope to add the header to
* @throws SOAPException
*/
private void addWssHeader(SOAPEnvelope envelope) throws SOAPException {
SOAPHeader header;
if (envelope.getHeader() == null)
header = envelope.addHeader();
else
header = envelope.getHeader();
if (sscToken != null) {
header.addAttribute(new QName("xmlns:axis2ns2"), "www.fortify.com/schema");
header.addAttribute(new QName("axis2ns2:token"), sscToken);
}
SOAPElement security = header.addChildElement("Security", "wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
SOAPElement usernameToken = security.addChildElement("UsernameToken", "wsse");
usernameToken.addAttribute(new QName("xmlns:wsu"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
if (sscUsername != null) {
SOAPElement username = usernameToken.addChildElement("Username", "wsse");
username.addTextNode(sscUsername);
}
if (sscPassword != null) {
SOAPElement password = usernameToken.addChildElement("Password", "wsse");
password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.addTextNode(sscPassword);
}
}
示例10: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
final Boolean outboundProperty =
(Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
final SOAPEnvelope envelope = context.getMessage().getSOAPPart().getEnvelope();
final SOAPFactory factory = SOAPFactory.newInstance();
final String prefix = "wsse";
final String uri = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
final SOAPElement securityElem = factory.createElement("Security", prefix, uri);
final 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");
final SOAPElement userElem = factory.createElement("Username", prefix, uri);
userElem.addTextNode(username);
final SOAPElement pwdElem = factory.createElement("Password", prefix, uri);
pwdElem.addTextNode(password);
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);
if (envelope.getHeader() != null) {
envelope.getHeader().detachNode();
}
final SOAPHeader header = envelope.addHeader();
header.addChildElement(securityElem);
} catch (Exception e) {
e.printStackTrace();
}
}
// else -> inbound
return true;
}
示例11: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
try {
Boolean outbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outbound) {
SOAPMessage message = context.getMessage();
SOAPHeader header = message.getSOAPHeader();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
if (header == null) {
header = envelope.addHeader();
}
for (Map.Entry<String, String> entry : headers.entrySet()) {
header.addHeaderElement(new QName(namespaceURI, entry.getKey())).addTextNode(entry.getValue());
}
} else {
String headerValue = getSpecificHeaderValue(context.getMessage().getSOAPHeader(), ServiceUtils.TRACKING_HEADER_NAME);
if (headerValue != null) {
context.put(ServiceUtils.TRACKING_KEY, headerValue);
context.setScope(ServiceUtils.TRACKING_KEY, MessageContext.Scope.APPLICATION);
}
}
} catch (Exception e) {
throw new InternalException(e);
}
return true;
}
示例12: handleRequest
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Adds an "Access" element to the SOAP header
*/
public boolean handleRequest(MessageContext msgct) {
if(msgct instanceof SOAPMessageContext) {
SOAPMessageContext smsgct=(SOAPMessageContext) msgct;
try {
SOAPMessage msg=smsgct.getMessage();
SOAPEnvelope envelope=msg.getSOAPPart().getEnvelope();
SOAPHeader header=msg.getSOAPHeader();
if(header==null)
header=envelope.addHeader(); // add an header if non exists
SOAPHeaderElement accessElement=header.addHeaderElement(
envelope.createName("Access","ns0",
"http://www.ipd.uni-karlsruhe.de/jplag/types"));
SOAPElement usernameelem=accessElement.addChildElement(
"username");
usernameelem.addTextNode(username);
SOAPElement passwordelem=accessElement.addChildElement(
"password");
passwordelem.addTextNode(password);
SOAPElement compatelem=accessElement.addChildElement(
"compatLevel");
compatelem.addTextNode(compatibilityLevel+"");
} catch (SOAPException x) {
System.out.println("Unable to create access SOAP header!");
x.printStackTrace();
}
}
return true;
}
示例13: serialise
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
/**
* Serialize the transaction context as a XML String.
* @param cc CoordinationContextType
* @return String representation of XML transaction context
* @throws Exception if it fails to serialise
*/
public String serialise(CoordinationContextType cc) throws Exception {
SOAPEnvelope soapenv = MessageFactory.newInstance().createMessage().getSOAPPart().getEnvelope();
SOAPHeader header = soapenv.getHeader();
if (header == null) {
header = soapenv.addHeader();
}
final Name name = soapenv.createName(CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT, CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
final SOAPHeaderElement root = header.addHeaderElement(name);
root.addNamespaceDeclaration(CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
/*
* TODO Is it possible to craft plain DOM element but not to create whole SOAPMessage?
* following code hits an NPE in the CoordinationContextHelper.serialise() when it invokes
* getPrefix().equals("xmlns") against the attribute generated by JAXB marshaller.
*
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document doc = factory.newDocumentBuilder().newDocument();
Element root = doc.createElement(CoordinationConstants.WSCOOR_PREFIX + ":" + CoordinationConstants.WSCOOR_ELEMENT_COORDINATION_CONTEXT);
root.setAttribute("xmlns:" + CoordinationConstants.WSCOOR_PREFIX, CoordinationConstants.WSCOOR_NAMESPACE);
*/
CoordinationContextHelper.serialise(cc, root);
StringWriter sw = new StringWriter();
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.transform(new DOMSource(root), new StreamResult(sw));
return sw.toString();
}
示例14: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean isRequest = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (isRequest) {
try {
SOAPMessage soapMsg = context.getMessage();
SOAPEnvelope soapEnv = soapMsg.getSOAPPart().getEnvelope();
SOAPHeader soapHeader = soapEnv.getHeader();
if (soapHeader == null) {
soapHeader = soapEnv.addHeader();
}
QName qname = new QName("http://www.2n.cz/2013/event", "SubscriptionId");
SOAPHeaderElement soapHeaderElement = soapHeader.addHeaderElement(qname);
soapHeaderElement.addAttribute(
new QName("http://www.w3.org/2005/08/addressing", "IsReferenceParameter"), "true");
if (handler.getSubscriptionID() != null) {
soapHeaderElement.addTextNode(handler.getSubscriptionID());
}
soapMsg.saveChanges();
} catch (Exception e) {
logger.debug("An exception occurred while formatting a SOAP header : '{}'", e.getMessage());
}
}
return true;
}
示例15: handleMessage
import javax.xml.soap.SOAPEnvelope; //導入方法依賴的package包/類
@Override
public boolean handleMessage(SOAPMessageContext context) {
Boolean outboundProperty = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (outboundProperty.booleanValue()) {
try {
SOAPMessage message = context.getMessage();
SOAPFactory factory = SOAPFactory.newInstance();
SOAPHeader header = message.getSOAPHeader();
if (header == null) {
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
header = envelope.addHeader();
}
SOAPElement partnerId = factory.createElement(new QName("http://oneclickforpartner.dpag.de", "PARTNER_ID"));
partnerId.addTextNode(partner.getPartnerId());
header.addChildElement(partnerId);
SOAPElement timestamp = factory.createElement(new QName("http://oneclickforpartner.dpag.de", "REQUEST_TIMESTAMP"));
timestamp.addTextNode(partner.getTimestamp());
header.addChildElement(timestamp);
SOAPElement keyPhase = factory.createElement(new QName("http://oneclickforpartner.dpag.de", "KEY_PHASE"));
keyPhase.addTextNode(Integer.toString(partner.getKeyPhase()));
header.addChildElement(keyPhase);
SOAPElement signature = factory.createElement(new QName("http://oneclickforpartner.dpag.de", "PARTNER_SIGNATURE"));
signature.addTextNode(partner.getSignature());
header.addChildElement(signature);
message.saveChanges();
} catch (Exception e) {
e.printStackTrace();
}
}
return true;
}