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);
}
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());
}
}
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;
}
}
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);
}
}
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));
}
Aggregations