Skip to content

Submodule as2‐servlet

Philip Helger edited this page Aug 9, 2021 · 5 revisions

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.

Usage

To use this project you have to do the following - all described in more detail below:

  1. Add the as2-servlet project as a dependency to your project - e.g. via Maven
  2. Modify your WEB-INF/web.xml file so that it references the com.helger.as2servlet.AS2ReceiveServlet.
  3. 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.
  4. Create a key store file (e.g.) called server-certs.p12 located in the same folder as the configuration file. The keystore type must be PKCS12. It must at least contain your private key. The path and the password of the keystore must be set in the AS2 configuration file.

WEB-INF/web.xml configuration for AS2 messages

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).

Using with an inline configuration instead of a file

To not use the servlet with the file based configuration follow these steps:

  1. Create a new subclass of AbstractAS2ReceiveXServletHandler and overwrite createAS2Session to return the AS2Session 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
  2. Copy the AS2ReceiveServlet to a new class and replace the instantiation of AS2ReceiveXServletHandlerFileBasedConfig with the instance of your handler
  3. Reference the new servlet in the WEB-INF/web.xml file

WEB-INF/web.xml configuration for AS2 asynchronous MDNs

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).