Package com.helger.smpclient.httpclient
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final org.apache.hc.core5.http.ContentTypestatic final booleanstatic final boolean -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractGenericSMPClient(URI aSMPHost, boolean bPeppolLimitationsActive) Constructor with a direct SMP URL.
Remember: must be HTTP and using port 80 only! -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancontainsRedirectSubject(com.helger.xsds.xmldsig.X509DataType aX509Data, String sRedirectCertificateUID) protected org.apache.hc.client5.http.protocol.HttpClientContextprotected final voidcustomizeMarshaller(com.helger.jaxb.GenericJAXBMarshaller<?> aMarshaller) Customize the JAXB marshaller, e.g. to add error handler etc.<T> TexecuteGenericRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase aRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> aResponseHandler) Execute a generic request on the SMP.<T> TexecuteRequest(org.apache.hc.client5.http.classic.methods.HttpUriRequestBase aRequest, org.apache.hc.core5.http.io.HttpClientResponseHandler<T> aResponseHandler) Execute a generic request on the SMP.static SMPClientExceptionConvert the passed generic HTTP exception into a more specific exception.final Consumer<? super com.helger.jaxb.GenericJAXBMarshaller<?>> final Stringfinal KeyStorefinal SMPHttpClientSettingsfinal booleanfinal booleanfinal booleanfinal booleanfinal IMPLTYPEsetFollowSMPRedirects(boolean bFollowSMPRedirects) Should the SMP client follow the SMP redirects that can be found in service registrations.final IMPLTYPEsetMarshallerCustomizer(Consumer<? super com.helger.jaxb.GenericJAXBMarshaller<?>> a) Set the JAXB Marshaller Customizerfinal IMPLTYPEsetSecureValidation(boolean bSecureValidation) Enable or disable the usage of secure XMLDsig validation.final IMPLTYPEsetTrustStore(KeyStore aTrustStore) Set the trust store to be used.final IMPLTYPEsetVerifySignature(boolean bVerifySignature) Check the certificate retrieved from a signed SMP response?final IMPLTYPEsetXMLSchemaValidation(boolean bXMLSchemaValidation) Should the SMP client perform XML Schema validation or not.toString()final IMPLTYPEwithHttpClientSettings(Consumer<? super SMPHttpClientSettings> aConsumer) Special version to modify the httpClientSettings but with a chainable API.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.helger.commons.traits.IGenericImplTrait
thisAsT
-
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
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.orgbPeppolLimitationsActive-trueif the Peppol limitations (Port 80, http only, in root context) should be complained about or not.
-
-
Method Details
-
getSMPHostURI
- Returns:
- The SMP host URI string we're operating on. Never
null. Always has a trailing "/".
-
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:
trueif SMP client response certificate checking is enabled,falseif it is disabled. By default this check is enabled (seeSMPHttpResponseHandlerSigned.DEFAULT_VERIFY_SIGNATURE).- Since:
- 8.0.3
-
setVerifySignature
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-trueto enable SMP response checking (on by default) orfalseto disable it.- Returns:
- this for chaining
- Since:
- 8.0.3
-
isSecureValidation
public final boolean isSecureValidation()- Returns:
trueif SMP client response certificate checking should use secure validation,falseif validation also allows deprecated algorithms. By default this check is enabled (seeSMPHttpResponseHandlerSigned.DEFAULT_SECURE_VALIDATION).- Since:
- 9.0.5
-
setSecureValidation
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-trueto enable SMP secure certificate validation (enabled by default) orfalseto disable it.- Returns:
- this for chaining
- Since:
- 9.0.5
-
getTrustStore
- Returns:
- The trust store to be used for verifying the signature. May be
nullif an invalid trust store is configured. - Since:
- 8.1.1
-
setTrustStore
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 benull.- Returns:
- this for chaining
- Since:
- 8.1.1
-
isFollowSMPRedirects
public final boolean isFollowSMPRedirects()- Returns:
trueif SMP redirects should be followed,falseif not. By default this check is enabled (seeDEFAULT_FOLLOW_REDIRECTS).- Since:
- 7.0.6
-
setFollowSMPRedirects
Should the SMP client follow the SMP redirects that can be found in service registrations. Enabled by default.- Parameters:
bFollowSMPRedirects-trueto follow SMP redirects (on by default) orfalseto disable it.- Returns:
- this for chaining
- Since:
- 7.0.6
-
isXMLSchemaValidation
public final boolean isXMLSchemaValidation()- Returns:
trueif responses should be checked against the XML Schemas,falseif not. By default this check is enabled (seeDEFAULT_XML_SCHEMA_VALIDATION).- Since:
- 8.0.5
-
setXMLSchemaValidation
Should the SMP client perform XML Schema validation or not. Enabled by default.- Parameters:
bXMLSchemaValidation-trueto perform XML Schema validation,falseto 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 toexecuteGenericRequest(HttpUriRequestBase, HttpClientResponseHandler)this method does NOT convert theIOExceptionfrom HTTP communication problems toIOException.- 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 benull.- 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 toexecuteRequest(HttpUriRequestBase, HttpClientResponseHandler)but includes the conversion of Exceptions toSMPClientExceptionobjects.- 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 benull.- Returns:
- The return value of the response handler.
- Throws:
SMPClientException- One of the converted exceptions- See Also:
-
getConvertedException
Convert the passed generic HTTP exception into a more specific exception.- Parameters:
ex- The generic exception. May not benull.- 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- Nevernull.- 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 benull.- Returns:
- this for chaining
- Since:
- 8.6.3
-
toString
-
containsRedirectSubject
public static boolean containsRedirectSubject(@Nonnull com.helger.xsds.xmldsig.X509DataType aX509Data, @Nonnull String sRedirectCertificateUID) throws SMPClientException - Throws:
SMPClientException
-