Search in sources :

Example 1 with RedirectType

use of com.helger.xsds.peppol.smp1.RedirectType in project phoss-smp by phax.

the class ServiceMetadataInterfaceTest method testCreateAndDeleteRedirectSMPClient.

@Test
public void testCreateAndDeleteRedirectSMPClient() throws SMPClientException {
    // Lower case
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
    // Upper case
    final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
    final IDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final RedirectType aRedir = _createRedirect();
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPRedirectManager aSRMgr = SMPMetaManager.getRedirectMgr();
    final SMPClient aSMPClient = new MockSMPClient();
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
    assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
    assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    try {
        // PUT ServiceGroup
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
        assertNotNull(aServiceGroup);
        final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
        assertEquals(aServiceGroup, aServiceGroup_UC);
        try {
            // PUT 1 ServiceInformation
            aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
            assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
            // PUT 2 ServiceInformation
            aSMPClient.saveServiceRedirect(aPI_LC, aDT, aRedir, CREDENTIALS);
            assertNotNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
            // DELETE 1 Redirect
            aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
            assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        } finally {
            // DELETE 2 Redirect
            try {
                aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
            } catch (final SMPClientNotFoundException ex) {
            // Expected
            }
            assertNull(aSRMgr.getSMPRedirectOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        }
        assertNotNull(aSGMgr.getSMPServiceGroupOfID(aPI_LC));
    } finally {
        // DELETE ServiceGroup
        try {
            aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        } catch (final SMPClientNotFoundException ex) {
        // Expected
        }
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    }
}
Also used : MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClientNotFoundException(com.helger.smpclient.exception.SMPClientNotFoundException) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) SMPClient(com.helger.smpclient.peppol.SMPClient) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) RedirectType(com.helger.xsds.peppol.smp1.RedirectType) Test(org.junit.Test)

Example 2 with RedirectType

use of com.helger.xsds.peppol.smp1.RedirectType in project phoss-smp by phax.

the class ServiceMetadataInterfaceTest method _createRedirect.

@Nonnull
private static RedirectType _createRedirect() {
    final RedirectType aRedir = new RedirectType();
    aRedir.setHref("http://other-smp.domain.xyz");
    aRedir.setCertificateUID("APP_0000000000000");
    return aRedir;
}
Also used : RedirectType(com.helger.xsds.peppol.smp1.RedirectType) Nonnull(javax.annotation.Nonnull)

Example 3 with RedirectType

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

the class SMPClientReadOnly method getServiceMetadata.

/**
 * Gets a signed service metadata object given by its service group id and its
 * document type. 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>.
 * @return A signed service metadata object. Never <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         A HTTP Forbidden was received, should not happen.
 * @throws SMPClientNotFoundException
 *         The service group id or document type did not exist.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #getServiceMetadataOrNull(IParticipantIdentifier,
 *      IDocumentTypeIdentifier)
 * @since v8.0.0
 */
@Nonnull
public SignedServiceMetadataType getServiceMetadata(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    final String sURI = getSMPHostURI() + aServiceGroupID.getURIPercentEncoded() + "/" + URL_PART_SERVICES + "/" + aDocumentTypeID.getURIPercentEncoded();
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("SMPClient getServiceRegistration@" + sURI);
    final boolean bXSDValidation = isXMLSchemaValidation();
    final boolean bVerifySignature = isVerifySignature();
    final KeyStore aTrustStore = getTrustStore();
    HttpGet aRequest = new HttpGet(sURI);
    SMPMarshallerSignedServiceMetadataType aMarshaller = new SMPMarshallerSignedServiceMetadataType(bXSDValidation);
    customizeMarshaller(aMarshaller);
    SignedServiceMetadataType aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(aMarshaller, aTrustStore).setVerifySignature(bVerifySignature));
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Received response: " + aMetadata);
    // If the Redirect element is present, then follow 1 redirect.
    if (isFollowSMPRedirects()) {
        if (aMetadata.getServiceMetadata() != null && aMetadata.getServiceMetadata().getRedirect() != null) {
            final RedirectType aRedirect = aMetadata.getServiceMetadata().getRedirect();
            // Follow the redirect
            if (LOGGER.isInfoEnabled())
                LOGGER.info("Following a redirect from '" + sURI + "' to '" + aRedirect.getHref() + "'");
            aRequest = new HttpGet(aRedirect.getHref());
            // Create a new Marshaller to ensure customization is simple
            aMarshaller = new SMPMarshallerSignedServiceMetadataType(bXSDValidation);
            customizeMarshaller(aMarshaller);
            aMetadata = executeGenericRequest(aRequest, new SMPHttpResponseHandlerSigned<>(aMarshaller, aTrustStore).setVerifySignature(bVerifySignature));
            // Check that the certificateUID is correct.
            boolean bCertificateSubjectFound = false;
            for (final Object aObj : aMetadata.getSignature().getKeyInfo().getContent()) {
                final Object aInfoValue = ((JAXBElement<?>) aObj).getValue();
                if (aInfoValue instanceof X509DataType) {
                    final X509DataType aX509Data = (X509DataType) aInfoValue;
                    if (containsRedirectSubject(aX509Data, aRedirect.getCertificateUID())) {
                        bCertificateSubjectFound = true;
                        break;
                    }
                }
            }
            if (!bCertificateSubjectFound)
                throw new SMPClientException("The X509 certificate did not contain a certificate subject.");
        }
    } else {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug("Following SMP redirects is disabled");
    }
    return aMetadata;
}
Also used : SMPHttpResponseHandlerSigned(com.helger.smpclient.httpclient.SMPHttpResponseHandlerSigned) X509DataType(com.helger.xsds.xmldsig.X509DataType) HttpGet(org.apache.http.client.methods.HttpGet) SignedServiceMetadataType(com.helger.xsds.peppol.smp1.SignedServiceMetadataType) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) JAXBElement(javax.xml.bind.JAXBElement) KeyStore(java.security.KeyStore) RedirectType(com.helger.xsds.peppol.smp1.RedirectType) SMPClientException(com.helger.smpclient.exception.SMPClientException) SMPMarshallerSignedServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerSignedServiceMetadataType) Nonnull(javax.annotation.Nonnull)

Example 4 with RedirectType

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

the class SMPDebugHelper method getAsString.

@Nonnull
public static String getAsString(@Nonnull final ServiceMetadataType aServiceMetadata) {
    final StringBuilder aSB = new StringBuilder();
    aSB.append("Service meta data:\n");
    final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
    if (aServiceInformation != null) {
        aSB.append("  Service information:\n");
        aSB.append("    Participant: ").append(CIdentifier.getURIEncoded(aServiceInformation.getParticipantIdentifier())).append('\n');
        aSB.append("    Document type: ").append(CIdentifier.getURIEncoded(aServiceInformation.getDocumentIdentifier())).append('\n');
        for (final ProcessType aProcess : aServiceInformation.getProcessList().getProcess()) {
            aSB.append("      Process: ").append(CIdentifier.getURIEncoded(aProcess.getProcessIdentifier())).append('\n');
            for (final EndpointType aEndpoint : aProcess.getServiceEndpointList().getEndpoint()) {
                aSB.append("        Endpoint: ").append(W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference())).append('\n');
                aSB.append("        Transport profile: ").append(aEndpoint.getTransportProfile()).append('\n');
                aSB.append("        Business level signature: ").append(aEndpoint.isRequireBusinessLevelSignature()).append('\n');
                aSB.append("        Min auth level: ").append(aEndpoint.getMinimumAuthenticationLevel()).append('\n');
                if (aEndpoint.getServiceActivationDate() != null)
                    aSB.append("        Valid from: ").append(aEndpoint.getServiceActivationDate()).append('\n');
                if (aEndpoint.getServiceExpirationDate() != null)
                    aSB.append("        Valid to: ").append(aEndpoint.getServiceExpirationDate()).append('\n');
                aSB.append("        Certficiate string: ").append(aEndpoint.getCertificate()).append('\n');
                aSB.append("        Service description: ").append(aEndpoint.getServiceDescription()).append('\n');
                aSB.append("        Contact URL: ").append(aEndpoint.getTechnicalContactUrl()).append('\n');
                aSB.append("        Info URL: ").append(aEndpoint.getTechnicalInformationUrl()).append('\n');
            }
        }
    }
    final RedirectType aRedirect = aServiceMetadata.getRedirect();
    if (aRedirect != null) {
        aSB.append("  Service redirect:\n");
        aSB.append("    Certificate UID: ").append(aRedirect.getCertificateUID()).append('\n');
        aSB.append("    Href: ").append(aRedirect.getHref()).append('\n');
    }
    return aSB.toString();
}
Also used : ProcessType(com.helger.xsds.peppol.smp1.ProcessType) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) RedirectType(com.helger.xsds.peppol.smp1.RedirectType) Nonnull(javax.annotation.Nonnull)

Example 5 with RedirectType

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

the class SMPClient method saveServiceRedirect.

/**
 * Saves a redirect data object.
 *
 * @param aServiceGroupID
 *        The service group ID to use. May not be <code>null</code>.
 * @param aDocumentTypeID
 *        The document type ID to use. May not be <code>null</code>.
 * @param aRedirect
 *        The redirect to be saved. May not be <code>null</code>.
 * @param aCredentials
 *        The user name and password to use as credentials. May not be
 *        <code>null</code>.
 * @throws SMPClientException
 *         in case something goes wrong
 * @throws SMPClientUnauthorizedException
 *         The user name or password was not correct.
 * @throws SMPClientNotFoundException
 *         A HTTP Not Found was received. This can happen if the service was
 *         not found.
 * @throws SMPClientBadRequestException
 *         The request was not well formed.
 * @see #saveServiceInformation(ServiceInformationType,
 *      BasicAuthClientCredentials)
 */
public void saveServiceRedirect(@Nonnull final IParticipantIdentifier aServiceGroupID, @Nonnull final IDocumentTypeIdentifier aDocumentTypeID, @Nonnull final RedirectType aRedirect, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPClientException {
    ValueEnforcer.notNull(aServiceGroupID, "ServiceGroupID");
    ValueEnforcer.notNull(aDocumentTypeID, "DocumentTypeID");
    ValueEnforcer.notNull(aRedirect, "Redirect");
    ValueEnforcer.notNull(aCredentials, "Credentials");
    final ServiceMetadataType aServiceMetadata = new ServiceMetadataType();
    aServiceMetadata.setRedirect(aRedirect);
    _saveServiceInformation(aServiceGroupID, aDocumentTypeID, aServiceMetadata, aCredentials);
}
Also used : ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) SMPMarshallerServiceMetadataType(com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType)

Aggregations

RedirectType (com.helger.xsds.peppol.smp1.RedirectType)4 Nonnull (javax.annotation.Nonnull)4 SMPClientException (com.helger.smpclient.exception.SMPClientException)2 SMPHttpResponseHandlerSigned (com.helger.smpclient.httpclient.SMPHttpResponseHandlerSigned)2 SMPMarshallerServiceMetadataType (com.helger.smpclient.peppol.marshal.SMPMarshallerServiceMetadataType)2 ServiceMetadataType (com.helger.xsds.peppol.smp1.ServiceMetadataType)2 X509DataType (com.helger.xsds.xmldsig.X509DataType)2 KeyStore (java.security.KeyStore)2 JAXBElement (javax.xml.bind.JAXBElement)2 HttpGet (org.apache.http.client.methods.HttpGet)2 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)1 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)1 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)1 ISMPRedirectManager (com.helger.phoss.smp.domain.redirect.ISMPRedirectManager)1 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)1 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)1 MockSMPClient (com.helger.phoss.smp.mock.MockSMPClient)1 BDXR1MarshallerSignedServiceMetadataType (com.helger.smpclient.bdxr1.marshal.BDXR1MarshallerSignedServiceMetadataType)1 SMPClientNotFoundException (com.helger.smpclient.exception.SMPClientNotFoundException)1 SMPClient (com.helger.smpclient.peppol.SMPClient)1