Class AbstractGenericSMPClient<IMPLTYPE extends AbstractGenericSMPClient<IMPLTYPE>>

java.lang.Object
com.helger.smpclient.httpclient.AbstractGenericSMPClient<IMPLTYPE>
Type Parameters:
IMPLTYPE - Real implementation class
All Implemented Interfaces:
com.helger.commons.traits.IGenericImplTrait<IMPLTYPE>
Direct Known Subclasses:
BDXR2ClientReadOnly, BDXRClientReadOnly, SMPClientReadOnly

public abstract class AbstractGenericSMPClient<IMPLTYPE extends AbstractGenericSMPClient<IMPLTYPE>> extends Object implements com.helger.commons.traits.IGenericImplTrait<IMPLTYPE>
Abstract base class for SMP clients - wraps all the HTTP stuff

Note: this class is also licensed under Apache 2 license, as it was not part of the original implementation

Author:
Philip Helger
  • Field Details

    • DEFAULT_FOLLOW_REDIRECTS

      public static final boolean DEFAULT_FOLLOW_REDIRECTS
      See Also:
    • DEFAULT_XML_SCHEMA_VALIDATION

      public static final boolean DEFAULT_XML_SCHEMA_VALIDATION
      See Also:
    • CONTENT_TYPE_TEXT_XML

      public static final org.apache.hc.core5.http.ContentType CONTENT_TYPE_TEXT_XML
  • Constructor Details

    • AbstractGenericSMPClient

      protected AbstractGenericSMPClient(@Nonnull URI aSMPHost, boolean bPeppolLimitationsActive)
      Constructor with a direct SMP URL.
      Remember: must be HTTP and using port 80 only!
      Parameters:
      aSMPHost - The address of the SMP service. Must be port 80 and basic http only (no https!). Example: http://smpcompany.company.org
      bPeppolLimitationsActive - true if the Peppol limitations (Port 80, http only, in root context) should be complained about or not.
  • Method Details

    • getSMPHostURI

      @Nonnull public final String getSMPHostURI()
      Returns:
      The SMP host URI string we're operating on. Never null . Always has a trailing "/".
    • httpClientSettings

      @Nonnull @ReturnsMutableObject public final SMPHttpClientSettings httpClientSettings()
      Returns:
      The HTTP client settings to be configured. Never null.
      Since:
      8.0.1
    • withHttpClientSettings

      @Nonnull public final IMPLTYPE withHttpClientSettings(@Nonnull Consumer<? super SMPHttpClientSettings> aConsumer)
      Special version to modify the httpClientSettings but with a chainable API.
      Parameters:
      aConsumer - The consumer that deals with the SMPHttpClientSettings
      Returns:
      this for chaining
      Since:
      9.0.9
    • isVerifySignature

      public final boolean isVerifySignature()
      Returns:
      true if SMP client response certificate checking is enabled, false if it is disabled. By default this check is enabled (see SMPHttpResponseHandlerSigned.DEFAULT_VERIFY_SIGNATURE).
      Since:
      8.0.3
    • setVerifySignature

      @Nonnull public final IMPLTYPE setVerifySignature(boolean bVerifySignature)
      Check the certificate retrieved from a signed SMP response? This may be helpful for debugging and testing of SMP client connections!
      Uses the trust store configured in the SMP client configuration.
      Parameters:
      bVerifySignature - true to enable SMP response checking (on by default) or false to disable it.
      Returns:
      this for chaining
      Since:
      8.0.3
    • isSecureValidation

      public final boolean isSecureValidation()
      Returns:
      true if SMP client response certificate checking should use secure validation, false if validation also allows deprecated algorithms. By default this check is enabled (see SMPHttpResponseHandlerSigned.DEFAULT_SECURE_VALIDATION).
      Since:
      9.0.5
    • setSecureValidation

      @Nonnull public final IMPLTYPE setSecureValidation(boolean bSecureValidation)
      Enable or disable the usage of secure XMLDsig validation. By default secure validation is enabled. Java 17 disables the usage of SHA-1 in XMLDsig by default, as documented in https://bugs.openjdk.org/browse/JDK-8261246. Currently the Peppol SMP still uses SHA-1 so you might want to disable this for the sake of sanity.
      Parameters:
      bSecureValidation - true to enable SMP secure certificate validation (enabled by default) or false to disable it.
      Returns:
      this for chaining
      Since:
      9.0.5
    • getTrustStore

      @Nullable public final KeyStore getTrustStore()
      Returns:
      The trust store to be used for verifying the signature. May be null if an invalid trust store is configured.
      Since:
      8.1.1
    • setTrustStore

      @Nonnull public final IMPLTYPE setTrustStore(@Nullable KeyStore aTrustStore)
      Set the trust store to be used. The trust store must be used, if signature verification is enabled.
      Parameters:
      aTrustStore - The trust store to be used. May be null.
      Returns:
      this for chaining
      Since:
      8.1.1
    • isFollowSMPRedirects

      public final boolean isFollowSMPRedirects()
      Returns:
      true if SMP redirects should be followed, false if not. By default this check is enabled (see DEFAULT_FOLLOW_REDIRECTS).
      Since:
      7.0.6
    • setFollowSMPRedirects

      @Nonnull public final IMPLTYPE setFollowSMPRedirects(boolean bFollowSMPRedirects)
      Should the SMP client follow the SMP redirects that can be found in service registrations. Enabled by default.
      Parameters:
      bFollowSMPRedirects - true to follow SMP redirects (on by default) or false to disable it.
      Returns:
      this for chaining
      Since:
      7.0.6
    • isXMLSchemaValidation

      public final boolean isXMLSchemaValidation()
      Returns:
      true if responses should be checked against the XML Schemas, false if not. By default this check is enabled (see DEFAULT_XML_SCHEMA_VALIDATION).
      Since:
      8.0.5
    • setXMLSchemaValidation

      @Nonnull public final IMPLTYPE setXMLSchemaValidation(boolean bXMLSchemaValidation)
      Should the SMP client perform XML Schema validation or not. Enabled by default.
      Parameters:
      bXMLSchemaValidation - true to perform XML Schema validation, false to disable it.
      Returns:
      this for chaining
      Since:
      8.0.5
    • createHttpContext

      @Nonnull @OverrideOnDemand protected org.apache.hc.client5.http.protocol.HttpClientContext createHttpContext()
    • executeRequest

      @Nonnull public <T> T executeRequest(@Nonnull org.apache.hc.client5.http.classic.methods.HttpUriRequestBase aRequest, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<T> aResponseHandler) throws IOException
      Execute a generic request on the SMP. This is e.g. helpful for accessing the PEPPOL Directory BusinessCard API. Compared to executeGenericRequest(HttpUriRequestBase, HttpClientResponseHandler) this method does NOT convert the IOException from HTTP communication problems to IOException.
      Type Parameters:
      T - Expected response type
      Parameters:
      aRequest - The request to be executed. The proxy + connection and request timeout are set in this method.
      aResponseHandler - The response handler to be used. May not be null.
      Returns:
      The return value of the response handler.
      Throws:
      IOException - On HTTP communication error
      See Also:
    • executeGenericRequest

      @Nonnull public <T> T executeGenericRequest(@Nonnull org.apache.hc.client5.http.classic.methods.HttpUriRequestBase aRequest, @Nonnull org.apache.hc.core5.http.io.HttpClientResponseHandler<T> aResponseHandler) throws SMPClientException
      Execute a generic request on the SMP. This is e.g. helpful for accessing the PEPPOL Directory BusinessCard API. This is equivalent to executeRequest(HttpUriRequestBase, HttpClientResponseHandler) but includes the conversion of Exceptions to SMPClientException objects.
      Type Parameters:
      T - Expected response type
      Parameters:
      aRequest - The request to be executed. The proxy + connection and request timeout are set in this method.
      aResponseHandler - The response handler to be used. May not be null.
      Returns:
      The return value of the response handler.
      Throws:
      SMPClientException - One of the converted exceptions
      See Also:
    • getConvertedException

      @Nonnull public static SMPClientException getConvertedException(@Nonnull Exception ex)
      Convert the passed generic HTTP exception into a more specific exception.
      Parameters:
      ex - The generic exception. May not be null.
      Returns:
      A new SMP specific exception, using the passed exception as the cause.
    • customizeMarshaller

      protected final void customizeMarshaller(@Nonnull com.helger.jaxb.GenericJAXBMarshaller<?> aMarshaller)
      Customize the JAXB marshaller, e.g. to add error handler etc.
      Parameters:
      aMarshaller - Never null.
      Since:
      8.6.3
      See Also:
    • getMarshallerCustomizer

      @Nullable public final Consumer<? super com.helger.jaxb.GenericJAXBMarshaller<?>> getMarshallerCustomizer()
      Returns:
      The JAXB Marshaller Customizer. May be null.
      Since:
      8.6.3
    • setMarshallerCustomizer

      @Nonnull public final IMPLTYPE setMarshallerCustomizer(@Nullable Consumer<? super com.helger.jaxb.GenericJAXBMarshaller<?>> a)
      Set the JAXB Marshaller Customizer
      Parameters:
      a - The customizer to be used. May be null.
      Returns:
      this for chaining
      Since:
      8.6.3
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • containsRedirectSubject

      public static boolean containsRedirectSubject(@Nonnull com.helger.xsds.xmldsig.X509DataType aX509Data, @Nonnull String sRedirectCertificateUID) throws SMPClientException
      Throws:
      SMPClientException