Search in sources :

Example 1 with SMPDNSResolutionException

use of com.helger.smpclient.url.SMPDNSResolutionException in project phoss-directory by phax.

the class SMPBusinessCardProvider method getBusinessCard.

@Nullable
public PDExtendedBusinessCard getBusinessCard(@Nonnull final IParticipantIdentifier aParticipantID) {
    final HttpClientSettings aHCS = new HttpClientSettings().setProxyHost(_getHttpProxy()).setProxyCredentials(_getHttpProxyCredentials());
    PDExtendedBusinessCard aBC;
    if (m_aSMPURI != null) {
        // Use a preselected SMP URI
        switch(m_eSMPMode) {
            case PEPPOL:
                {
                    final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            case OASIS_BDXR_V1:
                {
                    final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            case OASIS_BDXR_V2:
                {
                    final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aSMPURI);
                    _configureSMPClient(aSMPClient);
                    aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
                    break;
                }
            default:
                throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
        }
    } else {
        // SML auto detect
        aBC = null;
        for (final ISMLInfo aSML : m_aSMLInfoProvider.get()) {
            // Create SMP client and query SMP
            switch(m_eSMPMode) {
                case PEPPOL:
                    {
                        try {
                            final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                case OASIS_BDXR_V1:
                    {
                        try {
                            final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                case OASIS_BDXR_V2:
                    {
                        try {
                            final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aURLProvider, aParticipantID, aSML);
                            _configureSMPClient(aSMPClient);
                            aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
                        } catch (final SMPDNSResolutionException ex) {
                        // Happens if a non-existing URL is queried
                        }
                        break;
                    }
                default:
                    throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
            }
            // Found one?
            if (aBC != null)
                break;
        }
    }
    if (aBC != null)
        LOGGER.info("Found BusinessCard for '" + aParticipantID.getURIEncoded() + "' with " + aBC.getBusinessCard().businessEntities().size() + " entities and " + aBC.getDocumentTypeCount() + " document types");
    return aBC;
}
Also used : BDXR2ClientReadOnly(com.helger.smpclient.bdxr2.BDXR2ClientReadOnly) SMPClientReadOnly(com.helger.smpclient.peppol.SMPClientReadOnly) ISMLInfo(com.helger.peppol.sml.ISMLInfo) HttpClientSettings(com.helger.httpclient.HttpClientSettings) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) Nullable(javax.annotation.Nullable)

Example 2 with SMPDNSResolutionException

use of com.helger.smpclient.url.SMPDNSResolutionException in project phoss-smp by phax.

the class SMPRestDataProvider method _getDynamicParticipantURLHostName.

@Nonnull
private String _getDynamicParticipantURLHostName() {
    String ret = null;
    final ISMPURLProvider aURLProvider = SMPMetaManager.getSMPURLProvider();
    try {
        if (aURLProvider instanceof IPeppolURLProvider)
            ret = ((IPeppolURLProvider) aURLProvider).getDNSNameOfParticipant(m_aParticipantID, m_sSMLZoneName);
        else if (aURLProvider instanceof IBDXLURLProvider) {
            // Fallback by not resolving the NAPTR
            ret = ((IBDXLURLProvider) aURLProvider).getDNSNameOfParticipant(m_aParticipantID, m_sSMLZoneName);
        }
    } catch (final SMPDNSResolutionException ex) {
    // Ignore
    }
    if (ret == null)
        throw new IllegalStateException("Failed to resolve host name for '" + m_aParticipantID.getURIEncoded() + "' and SML zone name '" + m_sSMLZoneName + "'");
    return ret;
}
Also used : ISMPURLProvider(com.helger.smpclient.url.ISMPURLProvider) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) IPeppolURLProvider(com.helger.smpclient.url.IPeppolURLProvider) IBDXLURLProvider(com.helger.smpclient.url.IBDXLURLProvider) Nonnull(javax.annotation.Nonnull)

Example 3 with SMPDNSResolutionException

use of com.helger.smpclient.url.SMPDNSResolutionException in project phoss-directory by phax.

the class AbstractPageSecureReIndex method showSelectedObject.

@Override
protected void showSelectedObject(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final IReIndexWorkItem aSelectedObject) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final Locale aDisplayLocale = aWPEC.getDisplayLocale();
    final ISMPURLProvider aURLProvider = PDServerConfiguration.getURLProvider();
    final IIndexerWorkItem aWorkItem = aSelectedObject.getWorkItem();
    final IParticipantIdentifier aParticipantID = aWorkItem.getParticipantID();
    final BootstrapViewForm aViewForm = aNodeList.addAndReturnChild(new BootstrapViewForm());
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Creation datetime").setCtrl(PDTToString.getAsString(aWorkItem.getCreationDateTime(), aDisplayLocale)));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Participant ID").setCtrl(aParticipantID.getURIEncoded()));
    final String sBCSuffix = "/businesscard/" + aParticipantID.getURIPercentEncoded();
    {
        final HCNodeList aURLs = new HCNodeList();
        for (final ISMLInfo aSMLInfo : PDPMetaManager.getSMLInfoMgr().getAll()) {
            if (aURLs.hasChildren())
                aURLs.addChild(div("or"));
            try {
                aURLs.addChild(div(HCA.createLinkedWebsite(aURLProvider.getSMPURIOfParticipant(aParticipantID, aSMLInfo).toString() + sBCSuffix)));
            } catch (final SMPDNSResolutionException ex) {
                // Non existing participant!
                aURLs.addChild(div(aParticipantID.getURIPercentEncoded() + " on " + aSMLInfo.getDisplayName() + " @ " + sBCSuffix + " [" + ex.getMessage() + "]"));
            }
        }
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Business Card URL").setCtrl(aURLs));
    }
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Action type").setCtrl(aWorkItem.getType().getDisplayName()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Owner").setCtrl(aWorkItem.getOwnerID()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Requesting host").setCtrl(aWorkItem.getRequestingHost()));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Retries so far").setCtrl(Integer.toString(aSelectedObject.getRetryCount())));
    if (aSelectedObject.hasPreviousRetryDT())
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Previous retry").setCtrl(PDTToString.getAsString(aSelectedObject.getPreviousRetryDT(), aDisplayLocale)));
    if (!m_bDeadIndex)
        aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Next retry").setCtrl(PDTToString.getAsString(aSelectedObject.getNextRetryDT(), aDisplayLocale)));
    aViewForm.addFormGroup(new BootstrapFormGroup().setLabel("Last retry").setCtrl(PDTToString.getAsString(aSelectedObject.getMaxRetryDT(), aDisplayLocale)));
}
Also used : Locale(java.util.Locale) IIndexerWorkItem(com.helger.pd.indexer.index.IIndexerWorkItem) HCNodeList(com.helger.html.hc.impl.HCNodeList) ISMLInfo(com.helger.peppol.sml.ISMLInfo) ISMPURLProvider(com.helger.smpclient.url.ISMPURLProvider) BootstrapViewForm(com.helger.photon.bootstrap4.form.BootstrapViewForm) PDTToString(com.helger.commons.datetime.PDTToString) BootstrapFormGroup(com.helger.photon.bootstrap4.form.BootstrapFormGroup) SMPDNSResolutionException(com.helger.smpclient.url.SMPDNSResolutionException) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Aggregations

SMPDNSResolutionException (com.helger.smpclient.url.SMPDNSResolutionException)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)2 ISMPURLProvider (com.helger.smpclient.url.ISMPURLProvider)2 PDTToString (com.helger.commons.datetime.PDTToString)1 HCNodeList (com.helger.html.hc.impl.HCNodeList)1 HttpClientSettings (com.helger.httpclient.HttpClientSettings)1 IIndexerWorkItem (com.helger.pd.indexer.index.IIndexerWorkItem)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 BootstrapFormGroup (com.helger.photon.bootstrap4.form.BootstrapFormGroup)1 BootstrapViewForm (com.helger.photon.bootstrap4.form.BootstrapViewForm)1 BDXRClientReadOnly (com.helger.smpclient.bdxr1.BDXRClientReadOnly)1 BDXR2ClientReadOnly (com.helger.smpclient.bdxr2.BDXR2ClientReadOnly)1 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)1 IBDXLURLProvider (com.helger.smpclient.url.IBDXLURLProvider)1 IPeppolURLProvider (com.helger.smpclient.url.IPeppolURLProvider)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1