本文整理汇总了Java中javax.xml.soap.SOAPHeaderElement类的典型用法代码示例。如果您正苦于以下问题:Java SOAPHeaderElement类的具体用法?Java SOAPHeaderElement怎么用?Java SOAPHeaderElement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SOAPHeaderElement类属于javax.xml.soap包,在下文中一共展示了SOAPHeaderElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleRequest
import javax.xml.soap.SOAPHeaderElement; //导入依赖的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: processElement
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
private Document processElement(SOAPHeaderElement element)
throws TransformerException, ParserConfigurationException, SAXException, IOException, SOAPException {
NamedNodeMap attrs = element.getAttributes();
element.setPrefix("");
while (attrs.getLength() > 0) {
attrs.removeNamedItem(attrs.item(0).getNodeName());
}
String xmlString = "";
Iterator list = element.getChildElements();
while (list.hasNext()) {
Node node = (Node) list.next();
xmlString += nodeToString(node);
}
xmlString = xmlString.replace(URN, URN1);
xmlString = xmlString.replace(EIN, REQUIRED_EIN_TAG);
xmlString = xmlString.replace("xmlns:urn1=\"urn1:us:gov:treasury:irs:ext:aca:air:7.0\"", "");
xmlString = xmlString.replace(ACA_END_TAG, URN + ":" + ACA_END_TAG);
xmlString = ("<" + ACA_TAG + ">" + xmlString + "</" + ACA_END_TAG + ">");
return stringParser(xmlString);
}
示例3: initHeaderUnderstanding
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
/** Set the initial understood/not understood state of the headers in this
* object
*/
private void initHeaderUnderstanding() {
SOAPHeader soapHeader = ensureSOAPHeader();
if (soapHeader == null) {
return;
}
Iterator allHeaders = soapHeader.examineAllHeaderElements();
while(allHeaders.hasNext()) {
SOAPHeaderElement nextHdrElem = (SOAPHeaderElement) allHeaders.next();
if (nextHdrElem == null) {
continue;
}
if (nextHdrElem.getMustUnderstand()) {
notUnderstood(nextHdrElem.getElementQName());
}
//only headers explicitly marked as understood should be
//in the understoodHeaders set, so don't add anything to
//that set at the beginning
}
}
示例4: addHeaderElement
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
@Override
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
SOAPElement newHeaderElement =
ElementFactory.createNamedElement(
((SOAPDocument) getOwnerDocument()).getDocument(),
name.getLocalName(),
name.getPrefix(),
name.getURI());
if (newHeaderElement == null
|| !(newHeaderElement instanceof SOAPHeaderElement)) {
newHeaderElement = createHeaderElement(name);
}
// header elements must be namespace qualified
// check that URI is not empty, ensuring that the element is NS qualified.
String uri = newHeaderElement.getElementQName().getNamespaceURI();
if ((uri == null) || ("").equals(uri)) {
log.severe("SAAJ0131.impl.header.elems.ns.qualified");
throw new SOAPExceptionImpl("HeaderElements must be namespace qualified");
}
addNode(newHeaderElement);
return (SOAPHeaderElement) newHeaderElement;
}
示例5: convertToSoapElement
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
@Override
protected SOAPElement convertToSoapElement(Element element) {
final org.w3c.dom.Node soapNode = getSoapDocument().findIfPresent(element);
if (soapNode instanceof SOAPHeaderElement) {
return (SOAPElement) soapNode;
} else {
SOAPHeaderElement headerElement;
try {
headerElement =
createHeaderElement(NameImpl.copyElementName(element));
} catch (SOAPException e) {
throw new ClassCastException("Could not convert Element to SOAPHeaderElement: " + e.getMessage());
}
return replaceElementWithSOAPElement(
element,
(ElementImpl) headerElement);
}
}
示例6: getObject
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
public ACATransmitterManifestReqDtl getObject(File file) {
ACATransmitterManifestReqDtl dtl = null;
try {
String fileContents = FileUtils.readFileToString(file, "UTF-8");
SOAPMessage message = MessageFactory.newInstance().createMessage(null,
new ByteArrayInputStream(fileContents.getBytes()));
Unmarshaller unmarshaller = JAXBContext.newInstance(ACATransmitterManifestReqDtl.class)
.createUnmarshaller();
Iterator iterator = message.getSOAPHeader().examineAllHeaderElements();
while (iterator.hasNext()) {
SOAPHeaderElement element = (SOAPHeaderElement) iterator.next();
QName name = new QName("urn:us:gov:treasury:irs:ext:aca:air:7.0", "ACATransmitterManifestReqDtl",
"urn");
if (element.getElementQName().equals(name)) {
dtl = (ACATransmitterManifestReqDtl) unmarshaller.unmarshal(processElement(element));
}
}
} catch (Exception e) {
LOG.error("Error", e);
}
return dtl;
}
示例7: addSoapMetaInfo
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
protected Map<String,String> addSoapMetaInfo(Map<String, String> metaInfo, SOAPMessage soapMessage)
throws SOAPException {
SOAPHeader soapHeader = soapMessage.getSOAPHeader();
if (soapHeader == null) {
return metaInfo;
}
else {
Map<String, String> newMetaInfo = new HashMap<String, String>();
newMetaInfo.putAll(metaInfo);
Iterator<?> iter = soapHeader.examineAllHeaderElements();
while (iter.hasNext()) {
SOAPHeaderElement headerElem = (SOAPHeaderElement) iter.next();
if (!Listener.AUTHENTICATED_USER_HEADER.equals(headerElem.getNodeName()))
newMetaInfo.put(headerElem.getNodeName(), headerElem.getTextContent());
}
return newMetaInfo;
}
}
示例8: getOperationFromSOAPHdr
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
private String getOperationFromSOAPHdr(SOAPHeader soapHeader) {
@SuppressWarnings("unchecked")
Iterator<SOAPHeaderElement> it = soapHeader.examineAllHeaderElements();
SOAPHeaderElement opHdr = null;
while (it.hasNext()) {
opHdr = it.next();
if ("operation".equals(opHdr.getLocalName())) {
System.out.println("Found operation in SOAP header");
return opHdr.getTextContent();
}
}
return null;
}
示例9: getSecurityHeader
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
private SOAPHeaderElement getSecurityHeader(SOAPEnvelope envelope) throws SOAPException {
if (envelope != null) {
SOAPHeader header = envelope.getHeader();
if (header != null) {
Iterator<?> iter = header.getChildElements(WSSE_QNAME);
if (iter.hasNext()) {
return (SOAPHeaderElement)iter.next();
}
iter = header.getChildElements(WSSE_2_QNAME);
if (iter.hasNext()) {
return (SOAPHeaderElement)iter.next();
}
iter = header.getChildElements(WSSE_11_QNAME);
if (iter.hasNext()) {
return (SOAPHeaderElement)iter.next();
}
}
}
return null;
}
示例10: addHeaderElement
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
/**
* Creates a new <CODE>SOAPHeaderElement</CODE> object initialized with the specified name and
* adds it to this <CODE>SOAPHeader</CODE> object.
*
* @param name a <CODE>Name</CODE> object with the name of the new <CODE>SOAPHeaderElement</CODE>
* object
* @return the new <CODE>SOAPHeaderElement</CODE> object that was inserted into this
* <CODE>SOAPHeader</CODE> object
* @throws SOAPException if a SOAP error occurs
*/
public SOAPHeaderElement addHeaderElement(Name name) throws SOAPException {
if (name.getURI() == null
|| name.getURI().trim().length() == 0) {
throw new SOAPException("SOAP1.1 and SOAP1.2 requires all HeaderElements to have " +
"a namespace.");
}
String prefix = name.getPrefix() == null ? "" : name.getPrefix();
OMNamespace ns = new NamespaceImpl(name.getURI(), prefix);
SOAPHeaderBlock headerBlock = null;
if (this.element.getOMFactory() instanceof SOAP11Factory) {
headerBlock = new SOAP11HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
(SOAPFactory)this.element.getOMFactory());
} else {
headerBlock = new SOAP12HeaderBlockImpl(name.getLocalName(), ns, omSOAPHeader,
(SOAPFactory)this.element.getOMFactory());
}
SOAPHeaderElementImpl soapHeaderElement = new SOAPHeaderElementImpl(headerBlock);
element.setUserData(SAAJ_NODE, this, null);
soapHeaderElement.element.setUserData(SAAJ_NODE, soapHeaderElement, null);
soapHeaderElement.setParentElement(this);
return soapHeaderElement;
}
示例11: getChildren
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
private Iterator getChildren(Iterator childIter) {
Collection childElements = new ArrayList();
while (childIter.hasNext()) {
org.w3c.dom.Node domNode = (org.w3c.dom.Node)childIter.next();
Node saajNode = toSAAJNode(domNode);
if (saajNode instanceof javax.xml.soap.Text) {
childElements.add(saajNode);
} else if (!(saajNode instanceof SOAPHeaderElement)) {
// silently replace node, as per saaj 1.2 spec
SOAPHeaderElement headerEle = new SOAPHeaderElementImpl((SOAPHeaderBlock)domNode);
((NodeImpl)domNode).setUserData(SAAJ_NODE, headerEle, null);
childElements.add(headerEle);
} else {
childElements.add(saajNode);
}
}
return childElements.iterator();
}
示例12: testHeaderElements
import javax.xml.soap.SOAPHeaderElement; //导入依赖的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());
}
示例13: testAddSource2
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
@Validated @Test
public void testAddSource2() throws Exception {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = soapEnv.getHeader();
SOAPBody body = soapEnv.getBody();
assertTrue(header.addChildElement("ebxmlms1", "ch2",
"http://test.apache.org") instanceof SOAPHeaderElement);
assertTrue(header.addHeaderElement(
soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
assertTrue(header.addHeaderElement(
new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
soapMessage.saveChanges();
SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage2.getSOAPPart();
soapPart.setContent(soapMessage.getSOAPPart().getContent());
soapMessage2.saveChanges();
assertNotNull(soapMessage2);
}
示例14: testAddSource3
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
@Validated @Test
public void testAddSource3() throws Exception {
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage();
SOAPEnvelope soapEnv = soapMessage.getSOAPPart().getEnvelope();
SOAPHeader header = soapEnv.getHeader();
SOAPBody body = soapEnv.getBody();
assertTrue(header.addChildElement("ebxmlms1", "ch2",
"http://test.apache.org") instanceof SOAPHeaderElement);
assertTrue(header.addHeaderElement(
soapEnv.createName("ebxmlms2", "ch3", "http://test2.apache.org")) != null);
assertTrue(header.addHeaderElement(
new PrefixedQName("http://test3.apache.org", "ebxmlms3", "ch5")) != null);
body.addChildElement("bodyEle1", "ele1", "http://ws.apache.org");
soapMessage.saveChanges();
SOAPMessage soapMessage2 = MessageFactory.newInstance().createMessage();
SOAPPart soapPart = soapMessage2.getSOAPPart();
soapPart.setContent(soapMessage.getSOAPPart().getContent());
soapMessage2.saveChanges();
assertNotNull(soapMessage2);
}
示例15: testExamineHeaderElements
import javax.xml.soap.SOAPHeaderElement; //导入依赖的package包/类
@Validated @Test
public void testExamineHeaderElements() throws Exception {
javax.xml.soap.SOAPMessage soapMessage =
javax.xml.soap.MessageFactory.newInstance(
SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
javax.xml.soap.SOAPEnvelope soapEnv =
soapMessage.getSOAPPart().getEnvelope();
javax.xml.soap.SOAPHeader header = soapEnv.getHeader();
SOAPHeaderElement soapHeaderElement =
header.addHeaderElement(envelope.createName("foo1", "f1", "foo1-URI"));
Iterator iterator = null;
soapHeaderElement.setRole("role-URI");
iterator = header.examineHeaderElements("role1-URI");
int count = 0;
while (iterator.hasNext()) {
count++;
iterator.next();
}
assertEquals(0, count);
}