-
Notifications
You must be signed in to change notification settings - Fork 43
Submodule as2‐servlet
A stand alone servlet that takes AS2 requests.
Incoming messages are internally handled via a AS2ServletReceiverModule
that MUST be configured in the Configuration file.
Since v4.6.4 it also contains a Servlet to receive asynchronous MDNs.
This sub-project is licensed under the Apache 2 License.
To use this project you have to do the following - all described in more detail below:
- Add the
as2-servlet
project as a dependency to your project - e.g. via Maven - Modify your
WEB-INF/web.xml
file so that it references thecom.helger.as2servlet.AS2ReceiveServlet
. - Create an AS2 configuration file and store it in a folder that is fully writable to your project. The details of the configuration files are described below.
- Create a key store file (e.g.) called
server-certs.p12
located in the same folder as the configuration file. The keystore type must bePKCS12
. It must at least contain your private key. The path and the password of the keystore must be set in the AS2 configuration file.
Example WEB-INF/web.xml
configuration for the AS2 receive servlet:
<servlet>
<servlet-name>AS2ReceiveServlet</servlet-name>
<servlet-class>com.helger.as2servlet.AS2ReceiveServlet</servlet-class>
<init-param>
<param-name>as2-servlet-config-filename</param-name>
<param-value>as2-server-data/as2-server-config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>AS2ReceiveServlet</servlet-name>
<url-pattern>/as2/*</url-pattern>
</servlet-mapping>
As you can see, a configuration file called as2-server-data/as2-server-config.xml
is referenced as an init-param
of the servlet. The name of the init-param
must be as2-servlet-config-filename
. Please make sure to insert the correct absolute path to the configuration file inside the param-value
element.
In this example the servlet is mapped to the path /as2
meaning that messages must be targeted to this URL (e.g. https://myserver/as2
).
To not use the servlet with the file based configuration follow these steps:
- Create a new subclass of
AbstractAS2ReceiveXServletHandler
and overwritecreateAS2Session
to return theAS2Session
that uses the keystore you like. An example can be found in https://github.com/phax/as2-lib/blob/master/as2-servlet/src/test/java/com/helger/as2servlet/example/AS2ReceiveXServletHandlerCodeConfig.java - Copy the
AS2ReceiveServlet
to a new class and replace the instantiation ofAS2ReceiveXServletHandlerFileBasedConfig
with the instance of your handler - Reference the new servlet in the
WEB-INF/web.xml
file
Note: this feature is introduced in v4.6.4
Example WEB-INF/web.xml
configuration for the AS2 MDN receive servlet:
<servlet>
<servlet-name>AS2MDNReceiveServlet</servlet-name>
<servlet-class>com.helger.as2servlet.mdn.AS2MDNReceiveServlet</servlet-class>
<init-param>
<param-name>as2-servlet-config-filename</param-name>
<param-value>config/config.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>AS2MDNReceiveServlet</servlet-name>
<url-pattern>/as2mdn</url-pattern>
</servlet-mapping>
As you can see, a configuration file called as2-server-data/as2-server-config.xml
is referenced as an init-param
of the servlet. The name of the init-param
must be as2-servlet-config-filename
. Please make sure to insert the correct absolute path to the configuration file inside the param-value
element. This is the same file as for the main /as2
servlet
In this example the servlet is mapped to the path /as2mdn
meaning that messages must be targeted to this URL (e.g. https://myserver/as2mdn
).