Search in sources :

Example 1 with VisibleForTesting

use of com.helger.commons.annotation.VisibleForTesting in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCardPeppolSMP.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardPeppolSMP(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final SMPClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from Peppol SMP '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup;
    try {
        aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
    } catch (final SMPClientException ex) {
        LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    // If the service group is present, try querying the business card
    final PDBusinessCard aBusinessCard;
    try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
        // Use the optional business card API
        final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
        aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
    } catch (final IOException ex) {
        if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
            LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
        } else
            LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    if (aBusinessCard == null) {
        // No extension present - no need to try again
        LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
        return null;
    }
    // Query all document types
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = SMPClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
    return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 2 with VisibleForTesting

use of com.helger.commons.annotation.VisibleForTesting in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCardBDXR2.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR2(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXR2ClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v2 '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.bdxr.smp2.ServiceGroupType aServiceGroup;
    try {
        aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
    } catch (final SMPClientException ex) {
        LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    // If the service group is present, try querying the business card
    final PDBusinessCard aBusinessCard;
    try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
        // Use the optional business card API
        // TODO is the path "bdxr-smp-2" needed? Well, the PD is not yet
        // specified for this SMP type....
        final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
        aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
    } catch (final IOException ex) {
        if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
            LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
        } else
            LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    if (aBusinessCard == null) {
        // No extension present - no need to try again
        LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
        return null;
    }
    // Query all document types
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = BDXR2ClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory);
    return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Example 3 with VisibleForTesting

use of com.helger.commons.annotation.VisibleForTesting in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCardBDXR1.

@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardBDXR1(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final BDXRClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
    LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from OASIS BDXR SMP v1 '" + aSMPClient.getSMPHostURI() + "'");
    // First query the service group
    com.helger.xsds.bdxr.smp1.ServiceGroupType aServiceGroup;
    try {
        aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
    } catch (final SMPClientException ex) {
        LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    // If the service group is present, try querying the business card
    final PDBusinessCard aBusinessCard;
    try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
        // Use the optional business card API
        final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
        aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
    } catch (final IOException ex) {
        if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
            LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
        } else
            LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
        return null;
    }
    if (aBusinessCard == null) {
        // No extension present - no need to try again
        LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
        return null;
    }
    // Query all document types
    final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
    final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = BDXRClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
    return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
Also used : PDBusinessCard(com.helger.pd.businesscard.generic.PDBusinessCard) UnknownHostException(java.net.UnknownHostException) HttpGet(org.apache.http.client.methods.HttpGet) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) HttpResponseException(org.apache.http.client.HttpResponseException) IOException(java.io.IOException) HttpClientManager(com.helger.httpclient.HttpClientManager) SMPClientException(com.helger.smpclient.exception.SMPClientException) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) VisibleForTesting(com.helger.commons.annotation.VisibleForTesting) Nullable(javax.annotation.Nullable)

Aggregations

VisibleForTesting (com.helger.commons.annotation.VisibleForTesting)3 HttpClientManager (com.helger.httpclient.HttpClientManager)3 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)3 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)3 SMPClientException (com.helger.smpclient.exception.SMPClientException)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Nullable (javax.annotation.Nullable)3 HttpResponseException (org.apache.http.client.HttpResponseException)3 HttpGet (org.apache.http.client.methods.HttpGet)3