本文整理匯總了Java中javax.xml.soap.SOAPHeader.addHeaderElement方法的典型用法代碼示例。如果您正苦於以下問題:Java SOAPHeader.addHeaderElement方法的具體用法?Java SOAPHeader.addHeaderElement怎麽用?Java SOAPHeader.addHeaderElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.xml.soap.SOAPHeader
的用法示例。
在下文中一共展示了SOAPHeader.addHeaderElement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleRequest
import javax.xml.soap.SOAPHeader; //導入方法依賴的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;
}
示例2: testHeaderElements
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Validated @Test
public void testHeaderElements() throws Exception {
SOAPEnvelope envelope = getSOAPEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPHeaderElement headerEle = header.addHeaderElement(envelope.createName("foo1",
"f1",
"foo1-URI"));
headerEle.setActor("actor-URI");
headerEle.setMustUnderstand(true);
Iterator iterator = header.extractHeaderElements("actor-URI");
int cnt = 0;
while (iterator.hasNext()) {
cnt++;
SOAPHeaderElement resultHeaderEle = (SOAPHeaderElement)iterator.next();
assertEquals(headerEle.getActor(), resultHeaderEle.getActor());
assertEquals(resultHeaderEle.getMustUnderstand(), headerEle.getMustUnderstand());
}
assertTrue(cnt == 1);
iterator = header.extractHeaderElements("actor-URI");
assertTrue(!iterator.hasNext());
}
示例3: testMarshall_Simple
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
/**
* Test method for {@link io.apiman.gateway.engine.io.SoapPayloadIO#marshall(org.w3c.dom.Document)}.
*/
@Test
public void testMarshall_Simple() throws Exception {
MessageFactory msgFactory = MessageFactory.newInstance();
SOAPMessage message = msgFactory.createMessage();
SOAPEnvelope envelope = message.getSOAPPart().getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPHeaderElement cheader = header.addHeaderElement(new QName("urn:ns1", "CustomHeader"));
cheader.setTextContent("CVALUE");
SoapPayloadIO io = new SoapPayloadIO();
byte[] data = io.marshall(envelope);
String actual = new String(data);
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"><SOAP-ENV:Header><CustomHeader xmlns=\"urn:ns1\">CVALUE</CustomHeader></SOAP-ENV:Header><SOAP-ENV:Body/></SOAP-ENV:Envelope>";
Assert.assertEquals(expected, actual);
}
示例4: handleMessage
import javax.xml.soap.SOAPHeader; //導入方法依賴的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.SOAPHeader; //導入方法依賴的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: writeTo
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
SOAPHeader header = saaj.getSOAPHeader();
if (header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
SOAPHeaderElement she = header.addHeaderElement(av.faultDetailTag);
she = header.addHeaderElement(new QName(av.nsUri, wrapper));
she.addTextNode(problemValue);
}
示例7: writeTo
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
SOAPHeaderElement she = header.addHeaderElement(name);
if(mustUnderstand) {
she.setMustUnderstand(true);
}
she.addTextNode(value);
}
示例8: writeTo
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
public void writeTo(SOAPMessage saaj) throws SOAPException {
SOAPHeader header = saaj.getSOAPHeader();
if(header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
she.addChildElement(actionLocalName);
she.addTextNode(action);
if (soapAction != null) {
she.addChildElement(soapActionLocalName);
she.addTextNode(soapAction);
}
}
示例9: writeTo
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Override
public void writeTo(SOAPMessage saaj) throws SOAPException {
SOAPHeader header = saaj.getSOAPHeader();
if (header == null)
header = saaj.getSOAPPart().getEnvelope().addHeader();
SOAPHeaderElement she = header.addHeaderElement(name);
if (type != null)
she.addAttribute(typeAttributeName, type);
she.addTextNode(value);
}
示例10: sendJaxmMsg
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void sendJaxmMsg (String aMsg, String u) {
try {
System.setProperty("javax.net.ssl.trustStore", u);
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection connection = scf.createConnection();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage message = mf.createMessage();
SOAPPart sp = message.getSOAPPart();
SOAPEnvelope envelope = sp.getEnvelope();
SOAPHeader header = envelope.getHeader();
SOAPBody body = envelope.getBody();
SOAPHeaderElement headerElement = header.addHeaderElement(envelope.createName("OSCAR", "DT", "http://www.oscarhome.org/"));
headerElement.addTextNode("header");
SOAPBodyElement bodyElement = body.addBodyElement(envelope.createName("Service"));
bodyElement.addTextNode("compete");
AttachmentPart ap1 = message.createAttachmentPart();
ap1.setContent(aMsg, "text/plain");
message.addAttachmentPart(ap1);
URLEndpoint endPoint = new URLEndpoint (URLService); //"https://67.69.12.115:8443/OscarComm/DummyReceiver");
SOAPMessage reply = connection.call(message, endPoint);
connection.close();
} catch (Exception e) {
MiscUtils.getLogger().error("Error", e);
}
}
示例11: decorateHeader
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private void decorateHeader(SOAPEnvelope envelope, String username, String passwordHash) throws Exception {
SOAPHeader header = envelope.getHeader();
SOAPHeaderElement security = header.addHeaderElement(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security", "wsse"));
security.addNamespaceDeclaration("wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
security.setMustUnderstand(true);
SOAPElement usrToken = security.addChildElement("UsernameToken", "wsse");
usrToken.addAttribute(new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd", "Id", "wsu"), "UsernameToken-27777511");
SOAPElement usr = usrToken.addChildElement("Username", "wsse");
usr.setTextContent(username);
SOAPElement password = usrToken.addChildElement("Password", "wsse");
password.setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
password.setTextContent(passwordHash);
}
示例12: getMessageToSign
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
private static final SOAPMessage getMessageToSign(final String pathBase)
throws SOAPException, IOException {
final SOAPMessage soapMessage;
final SOAPPart soapPart;
final SOAPEnvelope soapEnvelope;
final SOAPHeader soapHeader;
final SOAPHeaderElement secElement;
final SOAPElement binaryTokenElement;
soapMessage = SoapMessageUtils.getMessage(pathBase);
soapPart = soapMessage.getSOAPPart();
soapEnvelope = soapPart.getEnvelope();
soapHeader = soapEnvelope.getHeader();
secElement = soapHeader.addHeaderElement(soapEnvelope.createName(
"Security", "wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
binaryTokenElement = secElement.addChildElement(soapEnvelope.createName(
"BinarySecurityToken", "wsse",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"));
binaryTokenElement.setAttribute("EncodingType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary");
binaryTokenElement.setAttribute("ValueType",
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
return soapMessage;
}
示例13: handleInbound
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("AuthorizationHandlerInbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|AuthIn");
}
catch (SOAPException e)
{
throw new WebServiceException(e);
}
return true;
}
示例14: handleOutbound
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Override
protected boolean handleOutbound(SOAPMessageContext msgContext)
{
log.info("handleOutbound");
try
{
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("AuthorizationHandlerOutbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|AuthOut");
}
catch (SOAPException e)
{
throw new WebServiceException(e);
}
return true;
}
示例15: handleInbound
import javax.xml.soap.SOAPHeader; //導入方法依賴的package包/類
@Override
protected boolean handleInbound(SOAPMessageContext msgContext)
{
log.info("handleInbound");
try
{
SOAPMessage soapMessage = msgContext.getMessage();
SOAPHeader soapHeader = getFailsafeSOAPHeader(soapMessage);
SOAPBody soapBody = soapMessage.getSOAPBody();
SOAPFactory soapFactory = SOAPFactory.newInstance();
Name headerName = soapFactory.createName("LogHandlerInbound", "ns1", "http://somens");
SOAPHeaderElement she = soapHeader.addHeaderElement(headerName);
she.setValue("true");
SOAPBodyElement soapBodyElement = (SOAPBodyElement)soapBody.getChildElements().next();
SOAPElement soapElement = (SOAPElement)soapBodyElement.getChildElements().next();
String value = soapElement.getValue();
soapElement.setValue(value + "|LogIn");
}
catch (SOAPException e)
{
throw new WebServiceException(e);
}
return true;
}