本文整理汇总了Java中javax.xml.soap.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于javax.xml.soap包,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import javax.xml.soap.Node; //导入依赖的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: load
import javax.xml.soap.Node; //导入依赖的package包/类
public ArrayList<T> load() throws Exception {
ArrayList<T> entities = new ArrayList<T>();
File fXmlFile = new File(this.xmlFilename);
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getElementsByTagName(this.entityTag);
for (int i = 0; i < nodeList.getLength(); i++) {
org.w3c.dom.Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) node;
entities.add(getEntityFromXmlElement(element));
}
}
return entities;
}
示例3: parseApiVersion_ctmg_1_8
import javax.xml.soap.Node; //导入依赖的package包/类
@Test
public void parseApiVersion_ctmg_1_8() throws Exception {
// given
SOAPPart part = mock(SOAPPart.class);
SOAPEnvelope envelope = mock(SOAPEnvelope.class);
SOAPHeader soapHeader = mock(SOAPHeader.class);
List<Node> version = new ArrayList<Node>();
Node node = mock(Node.class);
doReturn("testVersion").when(node).getValue();
version.add(node);
Iterator<?> it = version.iterator();
doReturn(it).when(soapHeader).extractHeaderElements(
eq("ctmg.service.version"));
doReturn(soapHeader).when(envelope).getHeader();
doReturn(envelope).when(part).getEnvelope();
doReturn(part).when(message).getSOAPPart();
// when
String result = SoapRequestParser.parseApiVersion(context);
// then
assertEquals("testVersion", result);
}
示例4: deserializeSOAPFault
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Tries to deserialize standard SOAP error message. If a standard error
* message is found true is returned. Otherwise false is returned.
*
* @param response ServiceResponse that holds the SOAPMessage
* @return true if and only if a standard SOAP fault is found; otherwise
* false
* @throws SOAPException if there's a SOAP error
*/
private boolean deserializeSOAPFault(final ServiceResponse response) throws SOAPException {
LOGGER.debug("Deserialize SOAP fault.");
Map<String, String> fault;
SOAPBody body = response.getSoapMessage().getSOAPBody();
NodeList list = body.getElementsByTagNameNS("*", "Fault");
if (list.getLength() == 1) {
fault = SOAPHelper.nodesToMap(list.item(0).getChildNodes(), true);
String faultCode = fault.get("FAULTCODE");
String faultString = fault.get("FAULTSTRING");
String faultActor = fault.get("FAULTACTOR");
Object detail = this.deserializeFaultDetail(SOAPHelper.getNode((Node) list.item(0), "detail"));
response.setErrorMessage(new ErrorMessage(faultCode, faultString, faultActor, detail));
LOGGER.info("SOAP fault was succesfully deserialized.");
return true;
}
LOGGER.debug("SOAP fault was not found.");
return false;
}
示例5: GuiData
import javax.xml.soap.Node; //导入依赖的package包/类
protected GuiData() {
try {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(FEFEditor.class.getResourceAsStream("data/xml/FileTypes.xml"));
doc.getDocumentElement().normalize();
NodeList nList = doc.getDocumentElement().getElementsByTagName("FatesTypes").item(0).getChildNodes();
for (int x = 0; x < nList.getLength(); x++) {
if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
baseTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
}
nList = doc.getDocumentElement().getElementsByTagName("DLC").item(0).getChildNodes();
for (int x = 0; x < nList.getLength(); x++) {
if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
dlcTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
}
nList = doc.getDocumentElement().getElementsByTagName("Awakening").item(0).getChildNodes();
for (int x = 0; x < nList.getLength(); x++) {
if (nList.item(x).getNodeType() == Node.ELEMENT_NODE)
awakeningTypes.add(nList.item(x).getAttributes().getNamedItem("name").getNodeValue());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
示例6: deserializeRequest
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Deserializes the "request" element.
*
* @param requestNode request element
* @return content of the request element
*/
@Override
protected String deserializeRequest(Node requestNode, SOAPMessage message) throws SOAPException {
if (requestNode == null) {
logger.warn("\"requestNode\" is null. Null is returned.");
return null;
}
for (int i = 0; i < requestNode.getChildNodes().getLength(); i++) {
// Request data is inside of "name" element
if (requestNode.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
&& "name".equals(requestNode.getChildNodes().item(i).getLocalName())) {
logger.debug("Found \"name\" element.");
// "name" element was found - return the text content
return requestNode.getChildNodes().item(i).getTextContent();
}
}
logger.warn("No \"name\" element found. Null is returned.");
return null;
}
示例7: deserializeResponseData
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Deserializes listMethods and allowedMethods meta service responses from
* SOAP to list of ProducerMember objects.
*
* @param responseNode response element of the SOAP message
* @param message entire SOAP message
* @return list ProducerMember objects
* @throws SOAPException if there's a SOAP exception
*/
@Override
protected List<ProducerMember> deserializeResponseData(Node responseNode, SOAPMessage message) throws SOAPException {
List<ProducerMember> producers = new ArrayList<>();
// Get list of services
NodeList list = message.getSOAPBody().getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_SERVICE);
LOGGER.debug("Found {} {} elements from SOAP body. ", list.getLength(), Constants.NS_XRD_ELEM_SERVICE);
for (int i = 0; i < list.getLength(); i++) {
LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_SERVICE);
// Service headers
Map<String, String> service = SOAPHelper.nodesToMap(list.item(i).getChildNodes());
// Service object type
ObjectType serviceObjectType = this.deserializeObjectType((Node) list.item(i));
try {
producers.add(super.getProducerMember(service, serviceObjectType));
} catch (Exception e) {
LOGGER.error("Deserializing \"{}\" failed - skip.", Constants.NS_XRD_ELEM_SERVICE);
LOGGER.error(e.getMessage(), e);
}
}
return producers;
}
示例8: processRequestNode
import javax.xml.soap.Node; //导入依赖的package包/类
private void processRequestNode(final SOAPBodyElement body, final ServiceResponse response,
final SOAPMessage soapRequest, final SOAPEnvelope envelope) throws SOAPException {
boolean requestFound = false;
NodeList list = soapRequest.getSOAPBody().getElementsByTagNameNS("*", response.getProducer().getServiceCode());
if (list.getLength() == 1) {
// Copy request from soapRequest
requestFound = copyRequestNode((Node) list.item(0), body, response);
}
// It was not possible to copy the request element, so we must create it
if (!requestFound) {
SOAPElement temp = body.addChildElement(envelope.createName("request"));
if (response.isAddNamespaceToRequest()) {
LOGGER.debug("Add provider namespace to request element.");
SOAPHelper.addNamespace(temp, response);
}
}
}
示例9: copyRequestNode
import javax.xml.soap.Node; //导入依赖的package包/类
private boolean copyRequestNode(final Node node, final SOAPBodyElement body, final ServiceResponse response) {
for (int i = 0; i < node.getChildNodes().getLength(); i++) {
if (node.getChildNodes().item(i).getNodeType() == Node.ELEMENT_NODE
&& "request".equals(node.getChildNodes().item(i).getLocalName())) {
Node requestNode = (Node) node.getChildNodes().item(i).cloneNode(true);
Node importNode = (Node) body.getOwnerDocument().importNode(requestNode, true);
body.appendChild(importNode);
if (response.isAddNamespaceToRequest()) {
LOGGER.debug("Add provider namespace to request element.");
SOAPHelper.addNamespace(importNode, response);
}
return true;
}
}
return false;
}
示例10: deserializeConsumer
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Deserializes the client element of the SOAP header to a ConsumerMember
* object.
*
* @param header SOAP header to be deserialized
* @return ConsumerMember object
* @throws XRd4JException if there's a XRd4J error
* @throws XRd4JMissingMemberException if ConsumerMember is missing
*/
protected final ConsumerMember deserializeConsumer(final SOAPHeader header)
throws XRd4JException, XRd4JMissingMemberException {
LOGGER.debug("Deserialize \"{}\".", Constants.NS_XRD_ELEM_CLIENT);
// Client headers
Map<String, String> client;
// Client object type
ObjectType clientObjectType;
NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_CLIENT);
if (list.getLength() == 1) {
clientObjectType = this.deserializeObjectType((Node) list.item(0));
client = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_CLIENT);
return this.getConsumerMember(client, clientObjectType);
}
LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_CLIENT);
throw new XRd4JMissingMemberException("Client element is missing from SOAP header.");
}
示例11: deserializeProducer
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Deserializes the service element of the SOAP header to a ProducerMember
* object.
*
* @param header SOAP header to be deserialized
* @return ProducerMember object
* @throws XRd4JException if there's a XRd4J error
* @throws XRd4JMissingMemberException if ProducerMember is missing
*/
protected final ProducerMember deserializeProducer(final SOAPHeader header)
throws XRd4JException, XRd4JMissingMemberException {
LOGGER.debug(DESERIALIZE_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
// Service headers
Map<String, String> service;
// Service object type
ObjectType serviceObjectType;
NodeList list = header.getElementsByTagNameNS(Constants.NS_XRD_URL, Constants.NS_XRD_ELEM_SERVICE);
if (list.getLength() == 1) {
serviceObjectType = this.deserializeObjectType((Node) list.item(0));
service = SOAPHelper.nodesToMap(list.item(0).getChildNodes());
LOGGER.trace(ELEMENT_FOUND_LOG_PATTERN, Constants.NS_XRD_ELEM_SERVICE);
return this.getProducerMember(service, serviceObjectType);
}
LOGGER.warn("\"{}\" element missing from SOAP header.", Constants.NS_XRD_ELEM_SERVICE);
throw new XRd4JMissingMemberException("Service element is missing from SOAP header.");
}
示例12: getXRdVersionInfo
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Reads installed X-Road packages and their version info from environmental
* monitoring metrics.
*
* @param metrics NodeList containing "metricSet" element returned by
* environmental monitoring service
* @return installed X-Road packages as key-value pairs
*/
public static Map<String, String> getXRdVersionInfo(NodeList metrics) {
LOGGER.trace("Start reading X-Road version info from metrics.");
Map<String, String> results = new HashMap<>();
// Check for null and empty
if (metrics == null || metrics.getLength() == 0) {
LOGGER.trace("Metrics set is null or empty.");
return results;
}
// Loop through metrics
for (int i = 0; i < metrics.getLength(); i++) {
Node node = SOAPHelper.getNode((Node) metrics.item(i), "name");
// Jump to next element if this is not Packages
if (node == null || !Constants.NS_ENV_MONITORING_ELEM_PACKAGES.equals(node.getTextContent())) {
continue;
}
// Loop through packages and add X-Road packages to results
getXRdPackages(metrics.item(i).getChildNodes(), results);
}
LOGGER.trace("Metrics info read. {} X-Road packages found.", results.size());
return results;
}
示例13: getXRdPackages
import javax.xml.soap.Node; //导入依赖的package包/类
/**
* Reads installed X-Road packages and their version info from environmental
* monitoring metrics.
*
* @param packages NodeList containing "metricSet" element which children
* all the installed packages are
* @param results Map object for results
*/
private static void getXRdPackages(NodeList packages, Map<String, String> results) {
// Loop through packages
for (int j = 0; j < packages.getLength(); j++) {
// We're looking for "stringMetric" elements
if (Constants.NS_ENV_MONITORING_ELEM_STRING_METRIC.equals(packages.item(j).getLocalName())) {
// Get name and value
Node name = SOAPHelper.getNode((Node) packages.item(j), "name");
Node value = SOAPHelper.getNode((Node) packages.item(j), "value");
// X-Road packages start with "xroad-prefix"
if (name != null && value != null && name.getTextContent().startsWith("xroad-")) {
results.put(name.getTextContent(), value.getTextContent());
LOGGER.debug("X-Road package version info found: \"{}\" = \"{}\".", name.getTextContent(),
value.getTextContent());
}
}
}
}
示例14: parseApiVersion_cm_1_8
import javax.xml.soap.Node; //导入依赖的package包/类
@Test
public void parseApiVersion_cm_1_8() throws Exception {
// given
SOAPPart part = mock(SOAPPart.class);
SOAPEnvelope envelope = mock(SOAPEnvelope.class);
SOAPHeader soapHeader = mock(SOAPHeader.class);
List<Node> version = new ArrayList<Node>();
Node node = mock(Node.class);
doReturn("testVersion").when(node).getValue();
version.add(node);
Iterator<?> it = version.iterator();
doReturn(it).when(soapHeader).extractHeaderElements(
eq("cm.service.version"));
doReturn(soapHeader).when(envelope).getHeader();
doReturn(envelope).when(part).getEnvelope();
doReturn(part).when(message).getSOAPPart();
// when
String result = SoapRequestParser.parseApiVersion(context);
// then
assertEquals("testVersion", result);
}
示例15: inputNeeded
import javax.xml.soap.Node; //导入依赖的package包/类
private static void inputNeeded( SOAPElement ele, List<SOAPElement> l )
{
// input is needed for leafs or for existing text-nods
if ( !ele.hasChildNodes()
|| ( ele.getChildNodes().getLength() == 1 && ( ele.getFirstChild().getNodeType() == Node.TEXT_NODE ) ) )
{
// check if element is a special element that should never get input
String namespace = ele.getNamespaceURI();
// only add to list if element has no namspace or namespace is no
// soap namespace
if ( namespace == null
|| ( !namespace.equals( SOAP_11_NAMESPACE_URL ) && !namespace.equals( SOAP_12_NAMESPACE_URL ) ) )
{
log.trace( "Adding node " + ele.getNodeName() );
l.add( ele );
}
}
for ( SOAPElement e : getSoapChilds( ele ) )
{
inputNeeded( e, l );
}
}