本文整理匯總了Java中javax.xml.soap.SOAPHeader.addChildElement方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPHeader.addChildElement方法的具體用法?Java SOAPHeader.addChildElement怎麽用?Java SOAPHeader.addChildElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPHeader
的用法示例。
在下文中一共展示了SOAPHeader.addChildElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: serializeClient
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void serializeClient(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
LOGGER.debug("Generate \"Client\" element.");
ObjectType clientObjectType = MessageHelper.getObjectType(message.getConsumer());
SOAPElement clientHeader = header.addChildElement(Constants.NS_XRD_ELEM_CLIENT, Constants.NS_XRD_PREFIX);
clientHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), clientObjectType.toString());
SOAPElement xRoadInstance = clientHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
xRoadInstance.addTextNode(message.getConsumer().getXRoadInstance());
SOAPElement memberClass = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
memberClass.addTextNode(message.getConsumer().getMemberClass());
SOAPElement memberCode = clientHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
memberCode.addTextNode(message.getConsumer().getMemberCode());
if (clientObjectType == ObjectType.SUBSYSTEM) {
SOAPElement subsystem = clientHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
subsystem.addTextNode(message.getConsumer().getSubsystemCode());
}
LOGGER.debug("\"Client\" element was succesfully generated.");
}
示例2: addSoapHeader
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
protected void addSoapHeader(SOAPMessage soapMessage) throws SOAPException, NoSuchAlgorithmException {
onvifDevice.createNonce();
String encrypedPassword = onvifDevice.getEncryptedPassword();
if (encrypedPassword != null && onvifDevice.getUsername() != null) {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPHeader header = soapMessage.getSOAPHeader();
se.addNamespaceDeclaration("wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
se.addNamespaceDeclaration("wsu",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement securityElem = header.addChildElement("Security", "wsse");
// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");
SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");
SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
usernameElem.setTextContent(onvifDevice.getUsername());
SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
passwordElem.setAttribute("Type",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
passwordElem.setTextContent(encrypedPassword);
SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
nonceElem.setAttribute("EncodingType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
nonceElem.setTextContent(onvifDevice.getEncryptedNonce());
SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
createdElem.setTextContent(onvifDevice.getLastUTCTime());
}
}
示例3: serializeService
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void serializeService(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
LOGGER.debug("Generate \"Service\" element.");
ObjectType serviceObjectType = MessageHelper.getObjectType(message.getProducer());
SOAPElement serviceHeader = header.addChildElement(Constants.NS_XRD_ELEM_SERVICE, Constants.NS_XRD_PREFIX);
serviceHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), serviceObjectType.toString());
SOAPElement xRoadInstance = serviceHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
xRoadInstance.addTextNode(message.getProducer().getXRoadInstance());
if (serviceObjectType == ObjectType.SERVICE) {
SOAPElement memberClass = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
memberClass.addTextNode(message.getProducer().getMemberClass());
SOAPElement memberCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
memberCode.addTextNode(message.getProducer().getMemberCode());
}
if (message.getProducer().getSubsystemCode() != null && !message.getProducer().getSubsystemCode().isEmpty()) {
SOAPElement subsystem = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SUBSYSTEM_CODE, Constants.NS_ID_PREFIX);
subsystem.addTextNode(message.getProducer().getSubsystemCode());
}
SOAPElement serviceCode = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_CODE, Constants.NS_ID_PREFIX);
serviceCode.addTextNode(message.getProducer().getServiceCode());
if (message.getProducer().getServiceVersion() != null && !message.getProducer().getServiceVersion().isEmpty()) {
SOAPElement serviceVersion = serviceHeader.addChildElement(Constants.NS_ID_ELEM_SERVICE_VERSION, Constants.NS_ID_PREFIX);
serviceVersion.addTextNode(message.getProducer().getServiceVersion());
}
LOGGER.debug("\"Service\" element was succesfully generated.");
}
示例4: addXTeeHeaderElements
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Override
public void addXTeeHeaderElements(SOAPEnvelope env, XRoadServiceConfiguration conf) throws SOAPException {
SOAPHeader header = env.getHeader();
if(StringUtils.isNotBlank(conf.getIdCode())) {
SOAPElement userId = header.addChildElement("userId", protocol.getNamespacePrefix());
userId.addTextNode(conf.getIdCode());
}
SOAPElement id = header.addChildElement("id", protocol.getNamespacePrefix());
id.addTextNode(generateUniqueMessageId(conf));
if (StringUtils.isNotBlank(conf.getFile())) {
SOAPElement issue = header.addChildElement("issue", protocol.getNamespacePrefix());
issue.addTextNode(conf.getFile());
}
SOAPElement protocolVersion = header.addChildElement("protocolVersion", protocol.getNamespacePrefix());
protocolVersion.addTextNode(protocol.getCode());
addClientElements(env, conf, header);
addServiceElements(env, conf, header);
}
示例5: addClientElements
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void addClientElements(SOAPEnvelope env, XRoadServiceConfiguration conf, SOAPHeader header)
throws SOAPException {
// TODO: maybe we should create headers differently according to object type?
XroadObjectType objectType =
conf.getClientObjectType() != null ? conf.getClientObjectType() : XroadObjectType.SUBSYSTEM;
SOAPElement client = header.addChildElement("client", protocol.getNamespacePrefix());
client.addAttribute(env.createName("id:objectType"), objectType.name());
SOAPElement clientXRoadInstance = client.addChildElement("xRoadInstance", "id");
clientXRoadInstance.addTextNode(conf.getClientXRoadInstance());
SOAPElement clientMemberClass = client.addChildElement("memberClass", "id");
clientMemberClass.addTextNode(conf.getClientMemberClass());
SOAPElement clientMemberCode = client.addChildElement("memberCode", "id");
clientMemberCode.addTextNode(conf.getClientMemberCode());
if (StringUtils.isNotBlank(conf.getClientSubsystemCode())) {
SOAPElement clientSubsystemCode = client.addChildElement("subsystemCode", "id");
clientSubsystemCode.addTextNode(conf.getClientSubsystemCode());
}
}
示例6: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
/**
* Captures pertinent information from SOAP messages exchanged by the SOAP
* service this handler is attached to. Also responsible for placing custom
* (implicit) SOAP headers on outgoing messages.
*
* @see SOAPHandler#handleMessage(MessageContext)
* @param context the context of the SOAP message passing through this handler
* @return whether this SOAP interaction should continue
*/
@Override
public boolean handleMessage(SOAPMessageContext context) {
if ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)) {
// Outbound message (request), so reset the last request and response builders.
lastRequestInfo = new RequestInfo.Builder();
lastResponseInfo = new ResponseInfo.Builder();
SOAPMessage soapMessage = context.getMessage();
try {
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
if (soapHeader == null) {
soapHeader = soapMessage.getSOAPPart().getEnvelope().addHeader();
}
for (SOAPElement header : soapHeaders) {
soapHeader.addChildElement(header);
}
} catch (SOAPException e) {
throw new ServiceException("Error setting SOAP headers on outbound message.", e);
}
captureServiceAndOperationNames(context);
}
captureSoapXml(context);
return true;
}
示例7: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例8: createProbeXML
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private byte[] createProbeXML() throws SOAPException, IOException {
MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SOAPMessage message = messageFactory.createMessage();
SOAPPart part = message.getSOAPPart();
SOAPEnvelope envelope = part.getEnvelope();
envelope.addNamespaceDeclaration("wsa", "http://schemas.xmlsoap.org/ws/2004/08/addressing");
envelope.addNamespaceDeclaration("tns", "http://schemas.xmlsoap.org/ws/2005/04/discovery");
envelope.addNamespaceDeclaration("nns", "http://www.onvif.org/ver10/network/wsdl");
QName action = envelope.createQName("Action", "wsa");
QName mid = envelope.createQName("MessageID", "wsa");
QName to = envelope.createQName("To", "wsa");
QName probe = envelope.createQName("Probe", "tns");
QName types = envelope.createQName("Types", "tns");
QName tramsmitter=envelope.createQName("NetworkVideoTransmitter", "nns");
SOAPHeader header = envelope.getHeader();
SOAPElement actionEl = header.addChildElement(action);
actionEl.setTextContent("http://schemas.xmlsoap.org/ws/2005/04/discovery/Probe");
SOAPElement messIsEl = header.addChildElement(mid);
messIsEl.setTextContent("urn:uuid:" + UUID.randomUUID().toString());
SOAPElement toEl = header.addChildElement(to);
toEl.setTextContent("urn:schemas-xmlsoap-org:ws:2005:04:discovery");
SOAPBody body = envelope.getBody();
SOAPElement probeEl = body.addChildElement(probe);
SOAPElement typesEl=probeEl.addChildElement(types);
typesEl.setTextContent("nns:NetworkVideoTransmitter");
ByteArrayOutputStream out = new ByteArrayOutputStream();
message.writeTo(out);
return out.toByteArray();
}
示例9: serializeSecurityServer
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void serializeSecurityServer(final SOAPHeader header, final AbstractMessage message, final SOAPEnvelope envelope) throws SOAPException {
LOGGER.debug("Generate \"SecurityServer\" element.");
SOAPElement securityServerHeader = header.addChildElement(Constants.NS_XRD_ELEM_SECURITY_SERVER, Constants.NS_XRD_PREFIX);
securityServerHeader.addAttribute(envelope.createQName(Constants.NS_ID_ATTR_OBJECT_TYPE, Constants.NS_ID_PREFIX), ObjectType.SERVER.toString());
SOAPElement xRoadInstance = securityServerHeader.addChildElement(Constants.NS_ID_ELEM_XROAD_INSTANCE, Constants.NS_ID_PREFIX);
xRoadInstance.addTextNode(message.getSecurityServer().getXRoadInstance());
SOAPElement memberClass = securityServerHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CLASS, Constants.NS_ID_PREFIX);
memberClass.addTextNode(message.getSecurityServer().getMemberClass());
SOAPElement memberCode = securityServerHeader.addChildElement(Constants.NS_ID_ELEM_MEMBER_CODE, Constants.NS_ID_PREFIX);
memberCode.addTextNode(message.getSecurityServer().getMemberCode());
SOAPElement serverCode = securityServerHeader.addChildElement(Constants.NS_ID_ELEM_SERVER_CODE, Constants.NS_ID_PREFIX);
serverCode.addTextNode(message.getSecurityServer().getServerCode());
LOGGER.debug("\"SecurityServer\" element was succesfully generated.");
}
示例10: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例11: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例12: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例13: addWssHeader
import javax.xml.soap.SOAPHeader; //導入方法依賴的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);
}
}
示例14: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例15: createSoapHeader
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
protected void createSoapHeader(SOAPMessage soapMessage) throws SOAPException {
onvifDevice.createNonce();
String encrypedPassword = onvifDevice.getEncryptedPassword();
if (encrypedPassword != null && onvifDevice.getUsername() != null) {
SOAPPart sp = soapMessage.getSOAPPart();
SOAPEnvelope se = sp.getEnvelope();
SOAPHeader header = soapMessage.getSOAPHeader();
se.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
se.addNamespaceDeclaration("wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
SOAPElement securityElem = header.addChildElement("Security", "wsse");
// securityElem.setAttribute("SOAP-ENV:mustUnderstand", "1");
SOAPElement usernameTokenElem = securityElem.addChildElement("UsernameToken", "wsse");
SOAPElement usernameElem = usernameTokenElem.addChildElement("Username", "wsse");
usernameElem.setTextContent(onvifDevice.getUsername());
SOAPElement passwordElem = usernameTokenElem.addChildElement("Password", "wsse");
passwordElem.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest");
passwordElem.setTextContent(encrypedPassword);
SOAPElement nonceElem = usernameTokenElem.addChildElement("Nonce", "wsse");
nonceElem.setAttribute("EncodingType", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
nonceElem.setTextContent(onvifDevice.getEncryptedNonce());
SOAPElement createdElem = usernameTokenElem.addChildElement("Created", "wsu");
createdElem.setTextContent(onvifDevice.getLastUTCTime());
}
}