Search in sources :

Example 6 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class SMPMarshallerSignedServiceMetadataTypeTest method testIssue121.

@Test
public void testIssue121() {
    final String s = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" + "<SignedServiceMetadata\r\n" + "  xmlns=\"http://busdox.org/serviceMetadata/publishing/1.0/\"\r\n" + "  xmlns:id=\"http://busdox.org/transport/identifiers/1.0/\"\r\n " + "  xmlns:ds=\"http://www.w3.org/2000/09/xmldsig#\">\r\n" + "  <ServiceMetadata>\r\n" + "    <ServiceInformation>\r\n" + "      <id:ParticipantIdentifier scheme=\"iso6523-actorid-upis\">0106:{KvK}</id:ParticipantIdentifier>\r\n" + "      <id:DocumentIdentifier scheme=\"busdox-docid-qns\">urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0:extended:urn:www.peppol.eu:bis:peppol4a:ver1.0::2.0</id:DocumentIdentifier>\r\n" + "      <ProcessList>\r\n" + "        <Process>\r\n" + "          <id:ProcessIdentifier scheme=\"cenbii-procid-ubl\">urn:www.cenbii.eu:profile:bii04:ver1.0</id:ProcessIdentifier>\r\n" + "          <ServiceEndpointList>\r\n" + "            <Endpoint transportProfile=\"busdox-transport-as2-ver1p0\">\r\n" + "              <EndpointReference xmlns=\"http://www.w3.org/2005/08/addressing\"><Address>https://example.org/as2</Address></EndpointReference>\r\n" + "              <RequireBusinessLevelSignature>true</RequireBusinessLevelSignature>\r\n" + "                <ServiceActivationDate>\r\n" + "                  2019-01-16T01:00:00.000+01:00\r\n" + "                </ServiceActivationDate>\r\n" + "                <ServiceExpirationDate>\r\n" + "                  2026-03-15T01:00:00.000+01:00\r\n" + "                </ServiceExpirationDate>\r\n" + "              <Certificate>{Certificate}</Certificate>\r\n" + "              <ServiceDescription>test</ServiceDescription>\r\n" + "              <TechnicalContactUrl>https://sitename.com</TechnicalContactUrl>\r\n" + "              <TechnicalInformationUrl>https://sitename.com</TechnicalInformationUrl>\r\n" + "            </Endpoint>\r\n" + "          </ServiceEndpointList>\r\n" + "        </Process>\r\n" + "      </ProcessList>\r\n" + "    </ServiceInformation>\r\n" + "  </ServiceMetadata>\r\n" + // Parsing would fail in Signature
    "  <ds:Signature/>\r\n" + "</SignedServiceMetadata>";
    SignedServiceMetadataType aObj = new SMPMarshallerSignedServiceMetadataType(false).read(s);
    assertNotNull(aObj);
    for (final String sFilename : new String[] { "signed-service-metadata1.xml", "signed-service-metadata2.xml", "signed-service-metadata3-c14n-inclusive.xml" }) {
        final IReadableResource aRes = new ClassPathResource("smp/" + sFilename);
        assertTrue(aRes.exists());
        aObj = new SMPMarshallerSignedServiceMetadataType(true).read(aRes);
        assertNotNull("Error in " + sFilename, aObj);
    }
}
Also used : IReadableResource(com.helger.commons.io.resource.IReadableResource) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 7 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class BDXRClientReadOnlyTest method testReadConnectivityTest.

@Test
@Ignore("Because it may take long to execute")
@IgnoredNaptrTest
public void testReadConnectivityTest() throws SMPDNSResolutionException, SMPClientException {
    final IParticipantIdentifier aPI = SimpleIdentifierFactory.INSTANCE.createParticipantIdentifier("connectivity-partid-qns", "dynceftest1party59gw");
    final IDocumentTypeIdentifier aDocTypeID = SimpleIdentifierFactory.INSTANCE.createDocumentTypeIdentifier("connectivity-docid-qns", "doc_id1");
    // TOOP SML
    final ISMLInfo aSMLInfo = new SMLInfo("cef-connectivity", "CEF ConnectivityTest", "connectivitytest.acc.edelivery.tech.ec.europa.eu.", "https://acc.edelivery.tech.ec.europa.eu/edelivery-sml", true);
    // PEPPOL URL provider
    final BDXRClientReadOnly aBDXRClient = new BDXRClientReadOnly(BDXLURLProvider.INSTANCE, aPI, aSMLInfo);
    // We don't have the truststore at hand - ignore it
    aBDXRClient.setVerifySignature(false);
    assertEquals("https://gateway-edelivery.westeurope.cloudapp.azure.com:444/", aBDXRClient.getSMPHostURI());
    final SignedServiceMetadataType aMetadata = aBDXRClient.getServiceMetadata(aPI, aDocTypeID);
    assertNotNull(aMetadata);
}
Also used : ISMLInfo(com.helger.peppol.sml.ISMLInfo) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) SMLInfo(com.helger.peppol.sml.SMLInfo) ISMLInfo(com.helger.peppol.sml.ISMLInfo) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) IgnoredNaptrTest(com.helger.smpclient.IgnoredNaptrTest) Test(org.junit.Test)

Example 8 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project phoss-smp by phax.

the class BDXR1ServerAPI method getServiceRegistration.

@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
    final String sAction = "getServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
        if (aPathDocTypeID == null) {
            throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // First check for redirection, then for actual service
        final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
        final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
        final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
        if (aRedirect != null) {
            aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectBDXR1());
        } else {
            // Get as regular service information
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
            final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectBDXR1();
            if (aSM != null) {
                aSignedServiceMetadata.setServiceMetadata(aSM);
            } else {
                // Neither nor is present, or no endpoint is available
                throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
            }
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aSignedServiceMetadata;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SignedServiceMetadataType(com.helger.xsds.bdxr.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.bdxr.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 9 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project phoss-smp by phax.

the class SMPServerAPI method getServiceRegistration.

@Nonnull
public SignedServiceMetadataType getServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocTypeID) throws SMPServerException {
    final String sLog = LOG_PREFIX + "GET /" + sPathServiceGroupID + "/services/" + sPathDocTypeID;
    final String sAction = "getServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final ISMPServiceGroup aPathServiceGroup = SMPMetaManager.getServiceGroupMgr().getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            throw new SMPNotFoundException("No such Service Group '" + sPathServiceGroupID + "'", m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocTypeID);
        if (aPathDocTypeID == null) {
            throw SMPBadRequestException.failedToParseDocType(sPathDocTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // First check for redirection, then for actual service
        final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
        final ISMPRedirect aRedirect = aRedirectMgr.getSMPRedirectOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
        final SignedServiceMetadataType aSignedServiceMetadata = new SignedServiceMetadataType();
        if (aRedirect != null) {
            aSignedServiceMetadata.setServiceMetadata(aRedirect.getAsJAXBObjectPeppol());
        } else {
            // Get as regular service information
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final ISMPServiceInformation aServiceInfo = aServiceInfoMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aPathServiceGroup, aPathDocTypeID);
            final ServiceMetadataType aSM = aServiceInfo == null ? null : aServiceInfo.getAsJAXBObjectPeppol();
            if (aSM != null) {
                aSignedServiceMetadata.setServiceMetadata(aSM);
            } else {
                // Neither nor is present, or no endpoint is available
                throw new SMPNotFoundException("service(" + sPathServiceGroupID + "," + sPathDocTypeID + ")", m_aAPIDataProvider.getCurrentURI());
            }
        }
        if (LOGGER.isInfoEnabled())
            LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return aSignedServiceMetadata;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ISMPRedirect(com.helger.phoss.smp.domain.redirect.ISMPRedirect) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Example 10 with SignedServiceMetadataType

use of com.helger.xsds.bdxr.smp1.SignedServiceMetadataType in project peppol-commons by phax.

the class ISMPServiceMetadataProvider method getEndpoint.

/**
 * Retrieve the service metadata from the provided service group ID and
 * document type ID. Than find the matching endpoint from the process ID and
 * transport profile.<br>
 * This is a specification compliant method.
 *
 * @param aServiceGroupID
 *        The service group id of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aDocumentTypeID
 *        The document type of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aProcessID
 *        The process ID of the service metadata to get. May not be
 *        <code>null</code>.
 * @param aTransportProfile
 *        The transport profile of the service metadata to get. May not be
 *        <code>null</code>.
 * @return The endpoint from the signed service metadata object or
 *         <code>null</code> if no such registration is present.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceMetadataOrNull(IParticipantIdentifier,IDocumentTypeIdentifier)
 */
@Nullable
default EndpointType getEndpoint(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID, @Nonnull final IProcessIdentifier aProcessID, @Nonnull final ISMPTransportProfile aTransportProfile) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aProcessID, "ProcessID");
    ValueEnforcer.notNull(aTransportProfile, "TransportProfile");
    // Get meta data for participant/documentType
    final SignedServiceMetadataType aSignedServiceMetadata = getServiceMetadataOrNull(aServiceGroupID, aDocumentTypeID);
    return aSignedServiceMetadata == null ? null : SMPClientReadOnly.getEndpoint(aSignedServiceMetadata, aProcessID, aTransportProfile);
}
Also used : SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) Nullable(javax.annotation.Nullable)

Aggregations

SignedServiceMetadataType (com.helger.xsds.peppol.smp1.SignedServiceMetadataType)13 Test (org.junit.Test)13 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)11 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)10 SignedServiceMetadataType (com.helger.xsds.bdxr.smp1.SignedServiceMetadataType)7 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)4 IgnoredNaptrTest (com.helger.smpclient.IgnoredNaptrTest)4 SMPMarshallerSignedServiceMetadataType (com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType)4 Nonnull (javax.annotation.Nonnull)4 Ignore (org.junit.Ignore)4 ESuccess (com.helger.commons.state.ESuccess)3 LoggingValidationEventHandler (com.helger.jaxb.validation.LoggingValidationEventHandler)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)3 SMLInfo (com.helger.peppol.sml.SMLInfo)3 TrustStoreBasedX509KeySelector (com.helger.smpclient.security.TrustStoreBasedX509KeySelector)3 KeyStore (java.security.KeyStore)3 Document (org.w3c.dom.Document)3 IIdentifierFactory (com.helger.peppolid.factory.IIdentifierFactory)2 ISMPRedirect (com.helger.phoss.smp.domain.redirect.ISMPRedirect)2 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)2