Search in sources :

Example 1 with SMPClient

use of com.helger.smpclient.peppol.SMPClient in project peppol-commons by phax.

the class MainCheckIfSMPIsWorking method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Ensure that the service group does not exist
    LOGGER.info("Ensuring that the service group is not existing!");
    if (aClient.getServiceGroupOrNull(PARTICIPANT_ID) != null) {
        LOGGER.info("Deleting existing service group for init");
        aClient.deleteServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
        LOGGER.info("Finished deletion of service group");
    }
    // Create, read and delete the service group
    LOGGER.info("Creating the new service group");
    aClient.saveServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
    LOGGER.info("Retrieving the service group");
    final ServiceGroupType aSGT = aClient.getServiceGroup(PARTICIPANT_ID);
    if (!SimpleParticipantIdentifier.wrap(aSGT.getParticipantIdentifier()).equals(PARTICIPANT_ID))
        throw new IllegalStateException("Participant identifiers are not equal!");
    LOGGER.info("Deleting the service group again");
    aClient.deleteServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
    LOGGER.info("Checking if the service group is really deleted");
    if (aClient.getServiceGroupOrNull(PARTICIPANT_ID) != null)
        throw new IllegalStateException("Deletion of the service group failed!");
    LOGGER.info("Seems like the SMP is working as expected!");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 2 with SMPClient

use of com.helger.smpclient.peppol.SMPClient in project peppol-commons by phax.

the class MainSMPServiceGroupCompleteList method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Get the service group reference list
    final CompleteServiceGroupType aCompleteServiceGroup = aClient.getCompleteServiceGroupOrNull(PARTICIPANT_ID);
    if (aCompleteServiceGroup == null)
        LOGGER.error("Failed to get complete service group for " + PARTICIPANT_ID);
    else {
        LOGGER.info(SMPDebugHelper.getAsString(aCompleteServiceGroup.getServiceGroup()));
        for (final ServiceMetadataType aServiceMetadata : aCompleteServiceGroup.getServiceMetadata()) LOGGER.info(SMPDebugHelper.getAsString(aServiceMetadata));
    }
    LOGGER.info("Done");
}
Also used : CompleteServiceGroupType(com.helger.xsds.peppol.smp1.CompleteServiceGroupType) SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 3 with SMPClient

use of com.helger.smpclient.peppol.SMPClient in project peppol-commons by phax.

the class MainSMPServiceGroupDelete method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final IParticipantIdentifier PARTICIPANT_ID = MockSMPClientConfig.getParticipantID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Delete the service group
    aClient.deleteServiceGroup(PARTICIPANT_ID, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 4 with SMPClient

use of com.helger.smpclient.peppol.SMPClient in project peppol-commons by phax.

the class MainSMPServiceGroupReferenceList method main.

public static void main(final String[] args) throws Exception {
    final URI SMP_URI = MockSMPClientConfig.getSMPURI();
    final BasicAuthClientCredentials SMP_CREDENTIALS = MockSMPClientConfig.getSMPCredentials();
    final String SMP_USERNAME = MockSMPClientConfig.getSMPUserName();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Get the service group reference list
    final ServiceGroupReferenceListType aServiceGroupReferenceList = aClient.getServiceGroupReferenceListOrNull(SMP_USERNAME, SMP_CREDENTIALS);
    if (aServiceGroupReferenceList == null)
        LOGGER.error("Failed to get complete service group for " + SMP_USERNAME);
    else {
        LOGGER.info("All service groups owned by " + SMP_USERNAME + ":");
        for (final ServiceGroupReferenceType aServiceGroupReference : aServiceGroupReferenceList.getServiceGroupReference()) LOGGER.info("  " + aServiceGroupReference.getHref());
    }
    LOGGER.info("Done");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) ServiceGroupReferenceListType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceListType) ServiceGroupReferenceType(com.helger.xsds.peppol.smp1.ServiceGroupReferenceType) URI(java.net.URI)

Example 5 with SMPClient

use of com.helger.smpclient.peppol.SMPClient in project phoss-smp by phax.

the class ServiceGroupInterfaceTest method testCreateAndDeleteServiceGroupSMPClient.

@Test
public void testCreateAndDeleteServiceGroupSMPClient() throws SMPClientException {
    // Lower case version
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:de203827312");
    // Upper case version
    final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:DE203827312");
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final SMPClient aSMPClient = new MockSMPClient();
    // GET
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
    try {
        // PUT 1 - create
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        // Both regular and upper case must work
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // PUT 2 - overwrite
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        // Both regular and upper case must work
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // DELETE 1
        aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        // Both must be deleted
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    } finally {
        // DELETE 2
        try {
            aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        } catch (final SMPClientNotFoundException ex) {
        // Expected
        }
        // Both must be deleted
        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) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClient(com.helger.smpclient.peppol.SMPClient) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

SMPClient (com.helger.smpclient.peppol.SMPClient)15 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)13 URI (java.net.URI)9 BasicAuthClientCredentials (com.helger.http.basicauth.BasicAuthClientCredentials)6 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)6 ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)6 MockSMPClient (com.helger.phoss.smp.mock.MockSMPClient)5 Test (org.junit.Test)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)4 EndpointType (com.helger.xsds.peppol.smp1.EndpointType)4 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)4 StopWatch (com.helger.commons.timing.StopWatch)3 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)3 SMPClientNotFoundException (com.helger.smpclient.exception.SMPClientNotFoundException)3 ProcessListType (com.helger.xsds.peppol.smp1.ProcessListType)3 ProcessType (com.helger.xsds.peppol.smp1.ProcessType)3 ServiceEndpointList (com.helger.xsds.peppol.smp1.ServiceEndpointList)3 ServiceInformationType (com.helger.xsds.peppol.smp1.ServiceInformationType)3 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)2 PeppolProcessIdentifier (com.helger.peppolid.peppol.process.PeppolProcessIdentifier)2