Search in sources :

Example 11 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-commons by phax.

the class SMLFuncTest method testMigrate.

@Test
public void testMigrate() throws Exception {
    final ManageParticipantIdentifierServiceCaller aPIClientOld = new ManageParticipantIdentifierServiceCaller(SML_INFO);
    aPIClientOld.setSSLSocketFactory(createConfiguredSSLSocketFactory(SML_INFO, false));
    final ManageServiceMetadataServiceCaller aClient2 = new ManageServiceMetadataServiceCaller(SML_INFO);
    aClient2.setSSLSocketFactory(createConfiguredSSLSocketFactory(SML_INFO, false));
    try {
        aClient2.delete(SMP_ID2);
    } catch (final NotFoundFault e) {
    // This is fine, since we are just cleaning
    }
    _createSMPData(aClient2, SMP_ID2);
    final ManageParticipantIdentifierServiceCaller aPIClientNew = new ManageParticipantIdentifierServiceCaller(SML_INFO);
    aPIClientNew.setSSLSocketFactory(createConfiguredSSLSocketFactory(SML_INFO, false));
    final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(TEST_BUSINESS_IDENTIFIER1);
    aPIClientOld.create(SMP_ID, aPI);
    final String sMigrationKey = aPIClientOld.prepareToMigrate(aPI, SMP_ID);
    assertNotNull(sMigrationKey);
    aPIClientNew.migrate(aPI, sMigrationKey, SMP_ID2);
    try {
        aPIClientOld.delete(SMP_ID, aPI);
        fail();
    } catch (final UnauthorizedFault e) {
    // This must happen.
    }
    // Should be able to delete, since New is now the owner
    aPIClientNew.delete(SMP_ID, aPI);
}
Also used : UnauthorizedFault(com.helger.peppol.smlclient.participant.UnauthorizedFault) ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) NotFoundFault(com.helger.peppol.smlclient.smp.NotFoundFault) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 12 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-commons by phax.

the class MainSetupSMLForSMPTests method main.

public static void main(final String[] args) throws Exception {
    final ManageServiceMetadataServiceCaller aSMClient = new ManageServiceMetadataServiceCaller(SML_INFO);
    aSMClient.setSSLSocketFactory(AbstractSMLClientTestCase.createConfiguredSSLSocketFactory(SML_INFO, false));
    final ManageParticipantIdentifierServiceCaller aParticipantClient = new ManageParticipantIdentifierServiceCaller(SML_INFO);
    aParticipantClient.setSSLSocketFactory(AbstractSMLClientTestCase.createConfiguredSSLSocketFactory(SML_INFO, false));
    try {
        aSMClient.create(SMP_ID1, "127.0.0.1", "http://localhost");
    } catch (final Exception e) {
        // ignore
        LOGGER.info(e.getMessage());
    }
    try {
        final IParticipantIdentifier serviceGroupId = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("0088:5798000000001");
        aParticipantClient.create(SMP_ID1, serviceGroupId);
    } catch (final Exception e) {
        // ignore
        LOGGER.info(e.getMessage());
    }
}
Also used : ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 13 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-commons by phax.

the class DNSRegistrationFuncTest method setupSMPBeforeTests.

@Before
public void setupSMPBeforeTests() throws Exception {
    LOGGER.info("Creating an SMP");
    try {
        final ManageServiceMetadataServiceCaller manageServiceMetaData = new ManageServiceMetadataServiceCaller(SML_INFO);
        manageServiceMetaData.create(SMP_ID, SMP_1_PHYSICAL_ADDRESS, SMP_1_LOGICAL_ADDRESS);
        LOGGER.info("Created an SMP");
    } catch (final Exception ex) {
        LOGGER.error("Failed: " + ex.getMessage());
        throw ex;
    }
}
Also used : ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) Before(org.junit.Before)

Example 14 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project peppol-commons by phax.

the class SMKFuncTest method testCreateAndDeletePublisher.

@Test
public void testCreateAndDeletePublisher() throws Exception {
    WSHelper.enableSoapLogging(true);
    try {
        // Create client
        final ManageServiceMetadataServiceCaller aSMPClient = new ManageServiceMetadataServiceCaller(SML_INFO);
        aSMPClient.setSSLSocketFactory(createConfiguredSSLSocketFactory(SML_INFO, false));
        final ManageParticipantIdentifierServiceCaller aPIClient = new ManageParticipantIdentifierServiceCaller(SML_INFO);
        aPIClient.setSSLSocketFactory(aSMPClient.getSSLSocketFactory());
        // Create SMP - with network logging
        LOGGER.info("CREATE SMP");
        _createSMPData(aSMPClient, SMP_ID);
        try {
            LOGGER.info("CREATE PARTICIPANT");
            aPIClient.create(SMP_ID, PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:philip"));
            try {
            } finally {
                LOGGER.info("DELETE PARTICIPANT");
                // The version with SMP_ID is required for SMK 3.0
                aPIClient.delete(SMP_ID, PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:philip"));
            }
        } finally {
            // Delete SMP
            LOGGER.info("DELETE SMP");
            aSMPClient.delete(SMP_ID);
        }
    } finally {
        WSHelper.enableSoapLogging(false);
    }
}
Also used : ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) ManageParticipantIdentifierServiceCaller(com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller) Test(org.junit.Test)

Example 15 with ManageServiceMetadataServiceCaller

use of com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller in project phoss-smp by phax.

the class PageSecureSMLRegistration method _updateSMPatSML.

private void _updateSMPatSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
    final HCNodeList aNodeList = aWPEC.getNodeList();
    final ESMPRESTType eRESTType = SMPServerConfiguration.getRESTType();
    final boolean bUsePeppolConstraints = eRESTType.isPeppol();
    final boolean bUsePathConstraints = eRESTType.isPathConstraint();
    final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
    final ISMLInfo aSMLInfo = SMPMetaManager.getSMLInfoMgr().getSMLInfoOfID(sSMLID);
    final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
    final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
    if (aSMLInfo == null)
        aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
    if (StringHelper.hasNoText(sPhysicalAddress))
        aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "A physical address must be provided!");
    else if (!RegExHelper.stringMatchesPattern(IPV4Addr.PATTERN_IPV4, sPhysicalAddress))
        aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided physical address does not seem to be an IPv4 address!");
    else {
        final String[] aParts = StringHelper.getExplodedArray('.', sPhysicalAddress, 4);
        final byte[] aBytes = new byte[] { (byte) StringParser.parseInt(aParts[0], -1), (byte) StringParser.parseInt(aParts[1], -1), (byte) StringParser.parseInt(aParts[2], -1), (byte) StringParser.parseInt(aParts[3], -1) };
        try {
            InetAddress.getByAddress(aBytes);
        } catch (final UnknownHostException ex) {
            aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + SMPCommonUI.getTechnicalDetailsString(ex));
        }
    }
    if (StringHelper.hasNoText(sLogicalAddress))
        aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "A logical address must be provided in the form 'http://smp.example.org'!");
    else {
        final URL aURL = URLHelper.getAsURL(sLogicalAddress);
        if (aURL == null)
            aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address seems not be a URL! Please use the form 'http://smp.example.org'");
        else {
            if (!"http".equals(aURL.getProtocol())) {
                if (bUsePeppolConstraints || !"https".equals(aURL.getProtocol()))
                    aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http'" + (bUsePeppolConstraints ? "" : " or the 'https'") + " protocol and may not use the '" + aURL.getProtocol() + "' protocol." + (bUsePeppolConstraints ? " According to the Peppol SMP specification, no other protocols than 'http' are allowed!" : ""));
            }
            if (bUsePeppolConstraints) {
                // -1 means default port
                if (aURL.getPort() != 80 && aURL.getPort() != -1)
                    aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the default http port 80 and not port " + aURL.getPort() + ". According to the Peppol SMP specification, no other ports are allowed!");
            }
            if (bUsePathConstraints) {
                if (StringHelper.hasText(aURL.getPath()) && !"/".equals(aURL.getPath()))
                    aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address may not contain a path (" + aURL.getPath() + ") because according to the SMP specifications it must run in the root (/) path!");
            }
        }
    }
    if (aFormErrors.isEmpty()) {
        final String sSMPID = SMPServerConfiguration.getSMLSMPID();
        try {
            final SSLSocketFactory aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
            final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo, aSocketFactory);
            aCaller.update(sSMPID, sPhysicalAddress, sLogicalAddress);
            final String sMsg = "Successfully updated SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' at the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
            LOGGER.info(sMsg);
            aNodeList.addChild(success(sMsg));
            AuditHelper.onAuditExecuteSuccess("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL());
        } catch (final Exception ex) {
            final String sMsg = "Error updating SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
            aNodeList.addChild(error(sMsg).addChild(SMPCommonUI.getTechnicalDetailsUI(ex)));
            AuditHelper.onAuditExecuteFailure("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
        }
    } else
        aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Also used : HCNodeList(com.helger.html.hc.impl.HCNodeList) ManageServiceMetadataServiceCaller(com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller) UnknownHostException(java.net.UnknownHostException) ESMPRESTType(com.helger.phoss.smp.ESMPRESTType) ISMLInfo(com.helger.peppol.sml.ISMLInfo) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) URL(java.net.URL) UnknownHostException(java.net.UnknownHostException)

Aggregations

ManageServiceMetadataServiceCaller (com.helger.peppol.smlclient.ManageServiceMetadataServiceCaller)18 HCNodeList (com.helger.html.hc.impl.HCNodeList)6 UnknownHostException (java.net.UnknownHostException)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 NotFoundFault (com.helger.peppol.smlclient.smp.NotFoundFault)5 ManageParticipantIdentifierServiceCaller (com.helger.peppol.smlclient.ManageParticipantIdentifierServiceCaller)4 URL (java.net.URL)4 Test (org.junit.Test)4 PDTFromString (com.helger.commons.datetime.PDTFromString)3 PDTToString (com.helger.commons.datetime.PDTToString)3 ISMLConfigurationManager (com.helger.peppol.app.mgr.ISMLConfigurationManager)3 ISMLConfiguration (com.helger.peppol.domain.ISMLConfiguration)3 ISMLInfo (com.helger.peppol.sml.ISMLInfo)3 IFileItem (com.helger.web.fileupload.IFileItem)3 ClientTransportException (com.sun.xml.ws.client.ClientTransportException)3 CertificateExpiredException (java.security.cert.CertificateExpiredException)3 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)3 Locale (java.util.Locale)3 Nonnull (javax.annotation.Nonnull)3 Before (org.junit.Before)3