1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Appserver\ServletEngine\DependencyInjection\DeploymentDescriptorParser |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Tim Wagner <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/appserver |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Appserver\ServletEngine\DependencyInjection; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Psr\Di\ObjectManagerInterface; |
24
|
|
|
use AppserverIo\Appserver\Core\Api\Node\WebAppNode; |
25
|
|
|
use AppserverIo\Appserver\DependencyInjectionContainer\AbstractDeploymentDescriptorParser; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Parser implementation to parse a web application deployment descriptor (WEB-INF/web.xml). |
29
|
|
|
* |
30
|
|
|
* @author Tim Wagner <[email protected]> |
31
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
33
|
|
|
* @link https://github.com/appserver-io/appserver |
34
|
|
|
* @link http://www.appserver.io |
35
|
|
|
*/ |
36
|
|
|
class DeploymentDescriptorParser extends AbstractDeploymentDescriptorParser |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Parses the servlet context's deployment descriptor file for servlets |
41
|
|
|
* that has to be registered in the object manager. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function parse() |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
// load the deployment descriptors that has to be parsed |
49
|
|
|
$deploymentDescriptors = $this->loadDeploymentDescriptors(); |
50
|
|
|
|
51
|
|
|
// parse the deployment descriptors from the conf.d and the application's META-INF directory |
52
|
|
|
foreach ($deploymentDescriptors as $deploymentDescriptor) { |
53
|
|
|
// query whether we found epb.xml deployment descriptor file |
54
|
|
|
if (file_exists($deploymentDescriptor) === false) { |
55
|
|
|
continue; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// validate the passed configuration file |
59
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ |
60
|
|
|
$configurationService = $this->getApplication()->newService('AppserverIo\Appserver\Core\Api\ConfigurationService'); |
|
|
|
|
61
|
|
|
$configurationService->validateFile($deploymentDescriptor, null, true); |
62
|
|
|
|
63
|
|
|
// load the object manager instance |
64
|
|
|
/** @var \AppserverIo\Psr\Di\ObjectManagerInterface $objectManager */ |
65
|
|
|
$objectManager = $this->getApplication()->search(ObjectManagerInterface::IDENTIFIER); |
66
|
|
|
|
67
|
|
|
// prepare and initialize the configuration node |
68
|
|
|
$webAppNode = new WebAppNode(); |
69
|
|
|
$webAppNode->initFromFile($deploymentDescriptor); |
|
|
|
|
70
|
|
|
|
71
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\Node\ServletNode $servletNode */ |
72
|
|
|
foreach ($webAppNode->getServlets() as $servletNode) { |
73
|
|
|
// iterate over all configured descriptors and try to load object description |
74
|
|
|
/** \AppserverIo\Appserver\Core\Api\Node\DescriptorNode $descriptor */ |
75
|
|
|
foreach ($this->getDescriptors() as $descriptor) { |
76
|
|
|
try { |
77
|
|
|
// load the descriptor class |
78
|
|
|
$descriptorClass = $descriptor->getNodeValue()->getValue(); |
79
|
|
|
|
80
|
|
|
// load the object descriptor, initialize the servlet mappings and add it to the object manager |
81
|
|
|
/** \AppserverIo\Psr\Deployment\DescriptorInterface $objectDescriptor */ |
82
|
|
|
if ($objectDescriptor = $descriptorClass::newDescriptorInstance()->fromConfiguration($servletNode)) { |
83
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\Node\ServletMappingNode $servletMappingNode */ |
84
|
|
|
foreach ($webAppNode->getServletMappings() as $servletMappingNode) { |
85
|
|
|
// query whether or not we've to add the URL pattern for the servlet |
86
|
|
|
if ((string) $servletNode->getServletName() === (string) $servletMappingNode->getServletName()) { |
87
|
|
|
$objectDescriptor->addUrlPattern((string) $servletMappingNode->getUrlPattern()); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
// add the object descriptor for the servlet |
92
|
|
|
$objectManager->addObjectDescriptor($objectDescriptor, true); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// proceed with the next descriptor |
96
|
|
|
continue; |
97
|
|
|
|
98
|
|
|
// if class can not be reflected continue with next class |
99
|
|
|
} catch (\Exception $e) { |
100
|
|
|
// log an error message |
101
|
|
|
$this->getApplication()->getInitialContext()->getSystemLogger()->error($e->__toString()); |
|
|
|
|
102
|
|
|
|
103
|
|
|
// proceed with the next descriptor |
104
|
|
|
continue; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// initialize the session configuration if available |
110
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\Node\SessionConfigNode $sessionConfig */ |
111
|
|
|
if ($sessionConfig = $webAppNode->getSessionConfig()) { |
112
|
|
|
foreach ($sessionConfig->toArray() as $key => $value) { |
113
|
|
|
$this->getManager()->addSessionParameter($key, $value); |
|
|
|
|
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// initialize the error page configuration if available |
118
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\Node\ErrorPageNode $errorPageNode */ |
119
|
|
|
foreach ($webAppNode->getErrorPages() as $errorPageNode) { |
120
|
|
|
$this->getManager()->addErrorPage((string) $errorPageNode->getErrorCodePattern(), (string) $errorPageNode->getErrorLocation()); |
|
|
|
|
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// initialize the context with the context parameters |
124
|
|
|
/** @var \AppserverIo\Appserver\Core\Api\Node\ContextParamNode $contextParamNode */ |
125
|
|
|
foreach ($webAppNode->getContextParams() as $contextParamNode) { |
126
|
|
|
$this->getManager()->addInitParameter((string) $contextParamNode->getParamName(), (string) $contextParamNode->getParamValue()); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|