Subversion Repositories XServices

Rev

Rev 198 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 198 Rev 199
Line 30... Line 30...
30
import javax.xml.namespace.QName;
30
import javax.xml.namespace.QName;
31
import javax.xml.stream.XMLOutputFactory;
31
import javax.xml.stream.XMLOutputFactory;
32
import javax.xml.stream.XMLStreamException;
32
import javax.xml.stream.XMLStreamException;
33
import javax.xml.stream.XMLStreamWriter;
33
import javax.xml.stream.XMLStreamWriter;
Line -... Line 34...
-
 
34
 
34
 
35
import lombok.extern.slf4j.Slf4j;
35
import net.brutex.xservices.types.AttributeType;
36
import net.brutex.xservices.types.AttributeType;
36
import net.brutex.xservices.types.NamespaceListType;
37
import net.brutex.xservices.types.NamespaceListType;
37
import net.brutex.xservices.types.NamespaceType;
38
import net.brutex.xservices.types.NamespaceType;
38
import net.brutex.xservices.types.StringSplitType;
39
import net.brutex.xservices.types.StringSplitType;
Line 52... Line 53...
52
import org.apache.axiom.om.OMProcessingInstruction;
53
import org.apache.axiom.om.OMProcessingInstruction;
53
import org.apache.axiom.om.OMText;
54
import org.apache.axiom.om.OMText;
54
import org.apache.axiom.om.OMXMLBuilderFactory;
55
import org.apache.axiom.om.OMXMLBuilderFactory;
55
import org.apache.axiom.om.xpath.AXIOMXPath;
56
import org.apache.axiom.om.xpath.AXIOMXPath;
Line 56... Line -...
56
 
-
 
57
import org.apache.logging.log4j.LogManager;
-
 
-
 
57
 
58
import org.apache.logging.log4j.Logger;
58
 
59
import org.apache.shiro.authz.annotation.RequiresPermissions;
59
import org.apache.shiro.authz.annotation.RequiresPermissions;
60
import org.jaxen.JaxenException;
60
import org.jaxen.JaxenException;
Line 61... Line 61...
61
import org.jaxen.SimpleNamespaceContext;
61
import org.jaxen.SimpleNamespaceContext;
62
 
62
 
63
/**
63
/**
64
 * @author Brian Rosenberger, bru(at)brutex.de
64
 * @author Brian Rosenberger, bru(at)brutex.de
-
 
65
 * 
65
 * 
66
 */
66
 */
67
@Slf4j 
67
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.XmlService", serviceName = "XmlService")
-
 
-
 
68
@WebService(targetNamespace = "http://ws.xservices.brutex.net", endpointInterface = "net.brutex.xservices.ws.XmlService", serviceName = "XmlService")
Line 68... Line 69...
68
public class XmlServiceImpl implements XmlService {
69
public class XmlServiceImpl implements XmlService {
69
	private static final Logger logger = LogManager.getLogger();
70
 
70
 
71
 
71
	public String insertNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment)
72
	public String insertNodesFromFile(FileResource res, NamespaceListType nsList, String xpath, String xmlFragment)
Line 92... Line 93...
92
			StringWriter sw = new StringWriter();
93
			StringWriter sw = new StringWriter();
93
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
94
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
94
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
95
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
95
			document.serialize(writer);
96
			document.serialize(writer);
Line 96... Line 97...
96
 
97
 
97
			this.logger.trace(sw.getBuffer().toString());
98
			log.debug(sw.getBuffer().toString());
98
			return sw.getBuffer().toString();
99
			return sw.getBuffer().toString();
99
		} catch (JaxenException e) {
100
		} catch (JaxenException e) {
100
			e.printStackTrace();
101
			e.printStackTrace();
101
			throw new XServicesFault(e);
102
			throw new XServicesFault(e);
Line 132... Line 133...
132
			StringWriter sw = new StringWriter();
133
			StringWriter sw = new StringWriter();
133
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
134
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
134
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
135
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
135
			document.serialize(writer);
136
			document.serialize(writer);
Line 136... Line 137...
136
 
137
 
137
			this.logger.trace(sw.getBuffer().toString());
138
			log.debug(sw.getBuffer().toString());
138
			return sw.getBuffer().toString();
139
			return sw.getBuffer().toString();
139
		} catch (JaxenException e) {
140
		} catch (JaxenException e) {
140
			e.printStackTrace();
141
			e.printStackTrace();
141
			throw new XServicesFault(e);
142
			throw new XServicesFault(e);
Line 173... Line 174...
173
			StringWriter sw = new StringWriter();
174
			StringWriter sw = new StringWriter();
174
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
175
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
175
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
176
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
176
			document.serialize(writer);
177
			document.serialize(writer);
Line 177... Line 178...
177
 
178
 
178
			this.logger.trace(sw.getBuffer().toString());
179
			log.debug(sw.getBuffer().toString());
179
			return sw.getBuffer().toString();
180
			return sw.getBuffer().toString();
180
		} catch (JaxenException e) {
181
		} catch (JaxenException e) {
181
			e.printStackTrace();
182
			e.printStackTrace();
182
			throw new XServicesFault(e);
183
			throw new XServicesFault(e);
Line 214... Line 215...
214
			StringWriter sw = new StringWriter();
215
			StringWriter sw = new StringWriter();
215
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
216
			XMLOutputFactory xof = XMLOutputFactory.newInstance();
216
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
217
			XMLStreamWriter writer = xof.createXMLStreamWriter(sw);
217
			document.serialize(writer);
218
			document.serialize(writer);
Line 218... Line 219...
218
 
219
 
219
			this.logger.trace(sw.getBuffer().toString());
220
			log.debug(sw.getBuffer().toString());
220
			return sw.getBuffer().toString();
221
			return sw.getBuffer().toString();
221
		} catch (JaxenException e) {
222
		} catch (JaxenException e) {
222
			e.printStackTrace();
223
			e.printStackTrace();
223
			throw new XServicesFault(e);
224
			throw new XServicesFault(e);
Line 355... Line 356...
355
	private OMDocument insertNodes(OMDocument xmldocument, AXIOMXPath axp, OMDocument xmlfragment)
356
	private OMDocument insertNodes(OMDocument xmldocument, AXIOMXPath axp, OMDocument xmlfragment)
356
			throws XServicesFault {
357
			throws XServicesFault {
357
		List<?> olist = null;
358
		List<?> olist = null;
358
		try {
359
		try {
359
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
360
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
360
			this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
361
			log.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
361
			this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
362
			log.debug("XPath root expression is: '" + axp.debug() + "'.");
362
		} catch (JaxenException e) {
363
		} catch (JaxenException e) {
363
			throw new XServicesFault(e.getMessage(), e);
364
			throw new XServicesFault(e.getMessage(), e);
364
		}
365
		}
365
		if (olist.size() == 0)
366
		if (olist.size() == 0)
366
			throw new XServicesFault(Messages.getString("XmlService.no_match", new Object[] { axp.toString() }));
367
			throw new XServicesFault(Messages.getString("XmlService.no_match", new Object[] { axp.toString() }));
Line 378... Line 379...
378
				case OMNode.ELEMENT_NODE:
379
				case OMNode.ELEMENT_NODE:
379
					if ((o instanceof OMElement))
380
					if ((o instanceof OMElement))
380
						match = (OMElement) o;
381
						match = (OMElement) o;
381
					if ((o instanceof OMDocument))
382
					if ((o instanceof OMDocument))
382
						match = ((OMDocument) o).getOMDocumentElement();
383
						match = ((OMDocument) o).getOMDocumentElement();
383
					this.logger.debug(Messages.getString("XmlService.8"));
384
					log.debug(Messages.getString("XmlService.8"));
384
					break;
385
					break;
385
				case OMNode.TEXT_NODE:
386
				case OMNode.TEXT_NODE:
386
					match = ((OMText) o).getParent();
387
					match = ((OMText) o).getParent();
387
					this.logger.debug(Messages.getString("XmlService.9"));
388
					log.debug(Messages.getString("XmlService.9"));
388
					break;
389
					break;
389
				case OMNode.COMMENT_NODE:
390
				case OMNode.COMMENT_NODE:
390
					// match = node.getParent();
391
					// match = node.getParent();
391
					match = (OMContainer) node;
392
					match = (OMContainer) node;
392
					this.logger.debug(Messages.getString("XmlService.10"));
393
					log.debug(Messages.getString("XmlService.10"));
393
					break;
394
					break;
394
				default:
395
				default:
395
					this.logger
-
 
396
							.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
396
					log.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
397
					this.logger.error(Messages.getString("XmlService.11"));
397
					log.error(Messages.getString("XmlService.11"));
398
					throw new XServicesFault(Messages.getString("XmlService.12"));
398
					throw new XServicesFault(Messages.getString("XmlService.12"));
399
				}
399
				}
400
			} else {
400
			} else {
401
				this.logger.error("XPath matched " + o.getClass().getCanonicalName());
401
				log.error("XPath matched " + o.getClass().getCanonicalName());
402
				this.logger.error(Messages.getString("XmlService.11"));
402
				log.error(Messages.getString("XmlService.11"));
403
				throw new XServicesFault(Messages.getString("XmlService.12"));
403
				throw new XServicesFault(Messages.getString("XmlService.12"));
404
			}
404
			}
Line 405... Line 405...
405
 
405
 
406
			while (children.hasNext()) {
406
			while (children.hasNext()) {
Line 417... Line 417...
417
			throws XServicesFault {
417
			throws XServicesFault {
Line 418... Line 418...
418
 
418
 
419
		List<?> olist = null;
419
		List<?> olist = null;
420
		try {
420
		try {
421
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
421
			olist = axp.selectNodes(xmldocument.getOMDocumentElement());
422
			this.logger.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
422
			log.debug("XPath '" + axp.toString() + "' has " + olist.size() + " matches.");
423
			this.logger.trace("XPath root expression is: '" + axp.debug() + "'.");
423
			log.debug("XPath root expression is: '" + axp.debug() + "'.");
424
		} catch (JaxenException e) {
424
		} catch (JaxenException e) {
425
			throw new XServicesFault(e.getMessage(), e);
425
			throw new XServicesFault(e.getMessage(), e);
426
		}
426
		}
427
		if (olist.size() == 0)
427
		if (olist.size() == 0)
Line 440... Line 440...
440
				case OMNode.ELEMENT_NODE:
440
				case OMNode.ELEMENT_NODE:
441
					if ((o instanceof OMElement))
441
					if ((o instanceof OMElement))
442
						match = (OMElement) o;
442
						match = (OMElement) o;
443
					if ((o instanceof OMDocument))
443
					if ((o instanceof OMDocument))
444
						match = ((OMDocument) o).getOMDocumentElement();
444
						match = ((OMDocument) o).getOMDocumentElement();
445
					this.logger.debug(Messages.getString("XmlService.8"));
445
					log.debug(Messages.getString("XmlService.8"));
446
					break;
446
					break;
447
				default:
447
				default:
448
					this.logger
-
 
449
							.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
448
					log.error("XPath matched " + o.getClass().getCanonicalName() + " Node Type:" + node.getType());
450
					this.logger.error(Messages.getString("XmlService.11"));
449
					log.error(Messages.getString("XmlService.11"));
451
					throw new XServicesFault(Messages.getString("XmlService.12"));
450
					throw new XServicesFault(Messages.getString("XmlService.12"));
452
				}
451
				}
453
			} else {
452
			} else {
454
				this.logger.error("XPath matched " + o.getClass().getCanonicalName());
453
				log.error("XPath matched " + o.getClass().getCanonicalName());
455
				this.logger.error(Messages.getString("XmlService.11"));
454
				log.error(Messages.getString("XmlService.11"));
456
				throw new XServicesFault(Messages.getString("XmlService.12"));
455
				throw new XServicesFault(Messages.getString("XmlService.12"));
457
			}
456
			}
Line 458... Line 457...
458
 
457
 
459
			while (children.hasNext()) {
458
			while (children.hasNext()) {
Line 470... Line 469...
470
		// Initialize XPath context
469
		// Initialize XPath context
471
		SimpleNamespaceContext context = new SimpleNamespaceContext();
470
		SimpleNamespaceContext context = new SimpleNamespaceContext();
472
		if (nsList != null) {
471
		if (nsList != null) {
473
			for (NamespaceType ns : nsList.getNamespaces()) {
472
			for (NamespaceType ns : nsList.getNamespaces()) {
474
				context.addNamespace(ns.getPrefix(), ns.getUri().toString());
473
				context.addNamespace(ns.getPrefix(), ns.getUri().toString());
475
				this.logger.debug(
474
				log.debug(
476
						Messages.getString("XmlService.0") + ns.getPrefix() + "=\"" + ns.getUri().toString() + "\"'");
475
						Messages.getString("XmlService.0") + ns.getPrefix() + "=\"" + ns.getUri().toString() + "\"'");
477
			}
476
			}
478
		} else {
477
		} else {
479
			logger.debug("No namespaces defined.");
478
			log.debug("No namespaces defined.");
480
		}
479
		}
481
		return context;
480
		return context;
482
	}
481
	}
Line 483... Line 482...
483
 
482
 
Line 488... Line 487...
488
		try {
487
		try {
489
			Charset.isSupported(encoding);
488
			Charset.isSupported(encoding);
490
		} catch (IllegalCharsetNameException e) {
489
		} catch (IllegalCharsetNameException e) {
491
			throw new XServicesFault("Endcoding '" + encoding + "' is not supported by this JRE.");
490
			throw new XServicesFault("Endcoding '" + encoding + "' is not supported by this JRE.");
492
		}
491
		}
493
		logger.debug("Setting source xml string encoding to '" + encoding + "'");
492
		log.debug("Setting source xml string encoding to '" + encoding + "'");
494
		return encoding;
493
		return encoding;
495
	}
494
	}
Line 496... Line 495...
496
 
495