Search in sources :

Example 11 with SMPClient

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

the class MainSMPServiceGroupList 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 information
    final ServiceGroupType aServiceGroup = aClient.getServiceGroupOrNull(PARTICIPANT_ID);
    if (aServiceGroup == null)
        LOGGER.error("Failed to get service group infos for " + PARTICIPANT_ID);
    else
        LOGGER.info(SMPDebugHelper.getAsString(aServiceGroup));
    LOGGER.info("Done");
}
Also used : SMPClient(com.helger.smpclient.peppol.SMPClient) URI(java.net.URI) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 12 with SMPClient

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

the class MainSMPServiceRegistrationCreate 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();
    final IDocumentTypeIdentifier DOCUMENT_ID = MockSMPClientConfig.getDocumentTypeID();
    final IProcessIdentifier PROCESS_ID = MockSMPClientConfig.getProcessTypeID();
    final W3CEndpointReference START_AP_ENDPOINTREF = MockSMPClientConfig.getAPEndpointRef();
    final String AP_CERT_STRING = MockSMPClientConfig.getAPCert();
    final String AP_SERVICE_DESCRIPTION = MockSMPClientConfig.getAPServiceDescription();
    final String AP_CONTACT_URL = MockSMPClientConfig.getAPContact();
    final String AP_INFO_URL = MockSMPClientConfig.getAPInfo();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    // Create the service registration
    final ServiceInformationType aServiceInformation = new ServiceInformationType();
    {
        final ProcessListType aProcessList = new ProcessListType();
        {
            final ProcessType aProcess = new ProcessType();
            {
                final ServiceEndpointList aServiceEndpointList = new ServiceEndpointList();
                {
                    final EndpointType aEndpoint = new EndpointType();
                    aEndpoint.setEndpointReference(START_AP_ENDPOINTREF);
                    aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
                    aEndpoint.setCertificate(AP_CERT_STRING);
                    aEndpoint.setServiceActivationDate(PDTFactory.createXMLOffsetDateTime(2011, Month.JANUARY, 1));
                    aEndpoint.setServiceExpirationDate(PDTFactory.createXMLOffsetDateTime(2020, Month.DECEMBER, 31));
                    aEndpoint.setServiceDescription(AP_SERVICE_DESCRIPTION);
                    aEndpoint.setTechnicalContactUrl(AP_CONTACT_URL);
                    aEndpoint.setTechnicalInformationUrl(AP_INFO_URL);
                    aEndpoint.setMinimumAuthenticationLevel("1");
                    aEndpoint.setRequireBusinessLevelSignature(false);
                    aServiceEndpointList.getEndpoint().add(aEndpoint);
                }
                aProcess.setProcessIdentifier(new SimpleProcessIdentifier(PROCESS_ID));
                aProcess.setServiceEndpointList(aServiceEndpointList);
            }
            aProcessList.getProcess().add(aProcess);
        }
        aServiceInformation.setDocumentIdentifier(new SimpleDocumentTypeIdentifier(DOCUMENT_ID));
        aServiceInformation.setParticipantIdentifier(new SimpleParticipantIdentifier(PARTICIPANT_ID));
        aServiceInformation.setProcessList(aProcessList);
    }
    aClient.saveServiceInformation(aServiceInformation, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : SimpleDocumentTypeIdentifier(com.helger.peppolid.simple.doctype.SimpleDocumentTypeIdentifier) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) URI(java.net.URI) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) SimpleProcessIdentifier(com.helger.peppolid.simple.process.SimpleProcessIdentifier) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 13 with SMPClient

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

the class MainSMPServiceRegistrationDelete 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();
    final IDocumentTypeIdentifier DOCUMENT_ID = MockSMPClientConfig.getDocumentTypeID();
    // The main SMP client
    final SMPClient aClient = new SMPClient(SMP_URI);
    aClient.deleteServiceRegistration(PARTICIPANT_ID, DOCUMENT_ID, SMP_CREDENTIALS);
    LOGGER.info("Done");
}
Also used : BasicAuthClientCredentials(com.helger.http.basicauth.BasicAuthClientCredentials) SMPClient(com.helger.smpclient.peppol.SMPClient) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) URI(java.net.URI) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 14 with SMPClient

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

the class MainSMPServiceRegistrationList method main.

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

Example 15 with SMPClient

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

the class DropFolderUserMessage method _send.

private static void _send(@Nonnull final IAS4CryptoFactory aCF, final Path aSendFile, final Path aIncomingDir) {
    final StopWatch aSW = StopWatch.createdStarted();
    boolean bSuccess = false;
    LOGGER.info("Trying to send " + aSendFile.toString());
    try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper()) {
        // Read generic SBD
        final StandardBusinessDocument aSBD = SBDHReader.standardBusinessDocument().read(Files.newInputStream(aSendFile));
        if (aSBD == null) {
            LOGGER.error("Failed to read " + aSendFile.toString() + " as SBDH document!");
        } else {
            // Extract Peppol specific data
            final PeppolSBDHDocument aSBDH = new PeppolSBDHDocumentReader(IF).extractData(aSBD);
            final ISMPServiceMetadataProvider aSMPClient = new SMPClient(UP, aSBDH.getReceiverAsIdentifier(), ESML.DIGIT_TEST);
            final EndpointType aEndpoint = aSMPClient.getEndpoint(aSBDH.getReceiverAsIdentifier(), aSBDH.getDocumentTypeAsIdentifier(), aSBDH.getProcessAsIdentifier(), ESMPTransportProfile.TRANSPORT_PROFILE_BDXR_AS4);
            if (aEndpoint == null) {
                LOGGER.error("Found no endpoint for:\n  Receiver ID: " + aSBDH.getReceiverAsIdentifier().getURIEncoded() + "\n  Document type ID: " + aSBDH.getDocumentTypeAsIdentifier().getURIEncoded() + "\n  Process ID: " + aSBDH.getProcessAsIdentifier().getURIEncoded());
            } else {
                final KeyStore.PrivateKeyEntry aOurCert = aCF.getPrivateKeyEntry();
                final X509Certificate aTheirCert = CertificateHelper.convertStringToCertficate(aEndpoint.getCertificate());
                final AS4ClientUserMessage aClient = new AS4ClientUserMessage(aResHelper);
                aClient.setSoapVersion(ESoapVersion.SOAP_12);
                // Keystore data
                aClient.setAS4CryptoFactory(aCF);
                aClient.signingParams().setAlgorithmSign(ECryptoAlgorithmSign.RSA_SHA_512);
                aClient.signingParams().setAlgorithmSignDigest(ECryptoAlgorithmSignDigest.DIGEST_SHA_512);
                // FIXME Action, Service etc. are missing
                aClient.setAction("xxx");
                aClient.setServiceType("xxx");
                aClient.setServiceValue("xxx");
                aClient.setConversationID(MessageHelperMethods.createRandomConversationID());
                aClient.setAgreementRefValue("xxx");
                aClient.setFromRole(CAS4.DEFAULT_ROLE);
                aClient.setFromPartyID(PeppolCertificateHelper.getSubjectCN((X509Certificate) aOurCert.getCertificate()));
                aClient.setToRole(CAS4.DEFAULT_ROLE);
                aClient.setToPartyID(PeppolCertificateHelper.getSubjectCN(aTheirCert));
                aClient.ebms3Properties().setAll(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, aSBDH.getSenderScheme(), aSBDH.getSenderValue()), MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, aSBDH.getReceiverScheme(), aSBDH.getReceiverValue()));
                aClient.setPayload(SBDHWriter.standardBusinessDocument().getAsDocument(aSBD));
                final IAS4ClientBuildMessageCallback aCallback = null;
                final IAS4OutgoingDumper aOutgoingDumper = null;
                final IAS4RetryCallback aRetryCallback = null;
                final AS4ClientSentMessage<byte[]> aResponseEntity = aClient.sendMessageWithRetries(W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference()), new ResponseHandlerByteArray(), aCallback, aOutgoingDumper, aRetryCallback);
                LOGGER.info("Successfully transmitted document with message ID '" + aResponseEntity.getMessageID() + "' for '" + aSBDH.getReceiverAsIdentifier().getURIEncoded() + "' to '" + W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference()) + "' in " + aSW.stopAndGetMillis() + " ms");
                if (aResponseEntity.hasResponse()) {
                    final String sMessageID = aResponseEntity.getMessageID();
                    final String sFilename = FilenameHelper.getAsSecureValidASCIIFilename(sMessageID) + "-response.xml";
                    final File aResponseFile = aIncomingDir.resolve(sFilename).toFile();
                    if (SimpleFileIO.writeFile(aResponseFile, aResponseEntity.getResponse()).isSuccess())
                        LOGGER.info("Response file was written to '" + aResponseFile.getAbsolutePath() + "'");
                    else
                        LOGGER.error("Error writing response file to '" + aResponseFile.getAbsolutePath() + "'");
                }
                bSuccess = true;
            }
        }
    } catch (final Exception ex) {
        LOGGER.error("Error sending " + aSendFile.toString(), ex);
    }
    // After the exception handler!
    {
        // Move to done or error directory?
        final Path aDest = aSendFile.resolveSibling(bSuccess ? PATH_DONE : PATH_ERROR).resolve(aSendFile.getFileName());
        try {
            Files.move(aSendFile, aDest);
        } catch (final IOException ex) {
            LOGGER.error("Error moving from '" + aSendFile.toString() + "' to '" + aDest + "'", ex);
        }
    }
}
Also used : Path(java.nio.file.Path) IAS4ClientBuildMessageCallback(com.helger.phase4.client.IAS4ClientBuildMessageCallback) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) ISMPServiceMetadataProvider(com.helger.smpclient.peppol.ISMPServiceMetadataProvider) StandardBusinessDocument(org.unece.cefact.namespaces.sbdh.StandardBusinessDocument) ResponseHandlerByteArray(com.helger.httpclient.response.ResponseHandlerByteArray) IAS4RetryCallback(com.helger.phase4.client.IAS4RetryCallback) PeppolSBDHDocumentReader(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StopWatch(com.helger.commons.timing.StopWatch) SMPClient(com.helger.smpclient.peppol.SMPClient) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) AS4ClientUserMessage(com.helger.phase4.client.AS4ClientUserMessage) AS4ResourceHelper(com.helger.phase4.util.AS4ResourceHelper) File(java.io.File)

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