Search in sources :

Example 1 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phase4 by phax.

the class MainPhase4CEFSenderToop method main.

public static void main(final String[] args) {
    WebScopeManager.onGlobalBegin(MockServletContext.create());
    // Dump (for debugging purpose only)
    AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
    AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
    try (final WebScoped w = new WebScoped()) {
        final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
        if (aPayloadBytes == null)
            throw new IllegalStateException();
        // Start configuring here
        final IParticipantIdentifier aReceiverID = Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9915:tooptest");
        final IAS4ClientBuildMessageCallback aBuildMessageCallback = new IAS4ClientBuildMessageCallback() {

            public void onAS4Message(final AbstractAS4Message<?> aMsg) {
                final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
                LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
                LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
            }
        };
        if (Phase4CEFSender.builder().documentTypeID(Phase4CEFSender.IF.createDocumentTypeIdentifier("toop-doctypeid-qns", "urn:eu:toop:ns:dataexchange-1p40::Response##urn:eu.toop.response.registeredorganization::1.40")).processID(Phase4CEFSender.IF.createProcessIdentifier("toop-procid-agreement", "urn:eu.toop.process.datarequestresponse")).senderParticipantID(Phase4CEFSender.IF.createParticipantIdentifier("iso6523-actorid-upis", "9914:phase4-test-sender")).receiverParticipantID(aReceiverID).fromPartyID(new SimpleParticipantIdentifier("type", "POP000306")).fromRole("http://www.toop.eu/edelivery/gateway").toPartyID(new SimpleParticipantIdentifier("type", "POP000306")).toRole("http://www.toop.eu/edelivery/gateway").payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).mimeTypeXML()).smpClient(new BDXRClientReadOnly(Phase4CEFSender.URL_PROVIDER, aReceiverID, SML_TOOP)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).buildMessageCallback(aBuildMessageCallback).sendMessage().isSuccess()) {
            LOGGER.info("Successfully sent CEF message via AS4");
        } else {
            LOGGER.error("Failed to send CEF message via AS4");
        }
    } catch (final Exception ex) {
        LOGGER.error("Error sending CEF message via AS4", ex);
    } finally {
        WebScopeManager.onGlobalEnd();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) BDXRClientReadOnly(com.helger.smpclient.bdxr1.BDXRClientReadOnly) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) AbstractAS4Message(com.helger.phase4.messaging.domain.AbstractAS4Message) AS4IncomingDumperFileBased(com.helger.phase4.dump.AS4IncomingDumperFileBased) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) AS4RawResponseConsumerWriteToFile(com.helger.phase4.dump.AS4RawResponseConsumerWriteToFile) File(java.io.File) AS4OutgoingDumperFileBased(com.helger.phase4.dump.AS4OutgoingDumperFileBased) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 2 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.

the class SMPServiceGroupManagerJDBC method getAllSMPServiceGroups.

@Nonnull
@ReturnsMutableCopy
public ICommonsList<ISMPServiceGroup> getAllSMPServiceGroups() {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("getAllSMPServiceGroups()");
    final ICommonsList<DBResultRow> aDBResult = newExecutor().queryAll("SELECT sg.businessIdentifierScheme, sg.businessIdentifier, sg.extension, so.username" + " FROM smp_service_group sg, smp_ownership so" + " WHERE so.businessIdentifierScheme=sg.businessIdentifierScheme AND so.businessIdentifier=sg.businessIdentifier");
    final ICommonsList<ISMPServiceGroup> ret = new CommonsArrayList<>();
    if (aDBResult != null)
        for (final DBResultRow aRow : aDBResult) ret.add(new SMPServiceGroup(aRow.getAsString(3), new SimpleParticipantIdentifier(aRow.getAsString(0), aRow.getAsString(1)), aRow.getAsString(2)));
    return ret;
}
Also used : DBResultRow(com.helger.db.jdbc.executor.DBResultRow) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ReturnsMutableCopy(com.helger.commons.annotation.ReturnsMutableCopy) Nonnull(javax.annotation.Nonnull)

Example 3 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier 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)

Example 4 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier in project phoss-smp by phax.

the class ServiceGroupInterfaceTest method testCreateAndDeleteServiceGroupJerseyClient.

@Test
public void testCreateAndDeleteServiceGroupJerseyClient() {
    // Lower case version
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:de203827312");
    final String sPI_LC = aPI_LC.getURIEncoded();
    // Upper case version
    final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9930:DE203827312");
    final String sPI_UC = aPI_UC.getURIEncoded();
    final ServiceGroupType aSG_LC = new ServiceGroupType();
    aSG_LC.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG_LC.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ServiceGroupType aSG_UC = new ServiceGroupType();
    aSG_UC.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_UC));
    aSG_UC.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final WebTarget aTarget = ClientBuilder.newClient().target(m_aRule.getFullURL());
    Response aResponseMsg;
    // GET
    _testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
    _testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
    try {
        // PUT 1 - create
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_LC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // PUT 2 - upper case - already present
        aResponseMsg = _addCredentials(aTarget.path(sPI_UC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_UC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Both regular and upper case must work
        assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
        assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // PUT 2 - overwrite
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_LC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        aResponseMsg = _addCredentials(aTarget.path(sPI_UC).request()).put(Entity.xml(m_aObjFactory.createServiceGroup(aSG_UC)));
        _testResponseJerseyClient(aResponseMsg, 200);
        // Both regular and upper case must work
        assertNotNull(aTarget.path(sPI_LC).request().get(ServiceGroupType.class));
        assertNotNull(aTarget.path(sPI_UC).request().get(ServiceGroupType.class));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        // DELETE 1
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200);
        // Both must be deleted
        _testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
        _testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    } finally {
        // DELETE 2
        aResponseMsg = _addCredentials(aTarget.path(sPI_LC).request()).delete();
        _testResponseJerseyClient(aResponseMsg, 200, 404);
        // Both must be deleted
        _testResponseJerseyClient(aTarget.path(sPI_LC).request().get(), 404);
        _testResponseJerseyClient(aTarget.path(sPI_UC).request().get(), 404);
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    }
}
Also used : Response(javax.ws.rs.core.Response) ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) WebTarget(javax.ws.rs.client.WebTarget) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 5 with SimpleParticipantIdentifier

use of com.helger.peppolid.simple.participant.SimpleParticipantIdentifier 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)

Aggregations

SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)48 Test (org.junit.Test)26 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)25 ServiceGroupType (com.helger.xsds.peppol.smp1.ServiceGroupType)12 ServiceMetadataReferenceCollectionType (com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType)12 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)11 Nonnull (javax.annotation.Nonnull)11 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)10 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)9 Response (javax.ws.rs.core.Response)9 SimpleDocumentTypeIdentifier (com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier)8 EndpointType (com.helger.xsds.peppol.smp1.EndpointType)7 ProcessListType (com.helger.xsds.peppol.smp1.ProcessListType)7 ProcessType (com.helger.xsds.peppol.smp1.ProcessType)7 ServiceEndpointList (com.helger.xsds.peppol.smp1.ServiceEndpointList)7 ServiceInformationType (com.helger.xsds.peppol.smp1.ServiceInformationType)7 WebTarget (javax.ws.rs.client.WebTarget)7 SMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.SMPServiceGroup)6 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)5 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)5