Search in sources :

Example 1 with PeppolConfiguration

use of network.oxalis.as4.util.PeppolConfiguration in project Oxalis-AS4 by OxalisCommunity.

the class SendReceiveTest method full.

@Test
public void full() throws Exception {
    MessageSender messageSender = injector.getInstance(Key.get(MessageSender.class, Names.named("oxalis-as4")));
    TransmissionResponse firstResponse = messageSender.send(new TransmissionRequest() {

        @Override
        public Endpoint getEndpoint() {
            return Endpoint.of(TransportProfile.AS4, URI.create("http://localhost:8080/as4"), injector.getInstance(X509Certificate.class));
        }

        @Override
        public Header getHeader() {
            return Header.newInstance().sender(ParticipantIdentifier.of("0007:5567125082")).receiver(ParticipantIdentifier.of("0007:4455454480")).documentType(DocumentTypeIdentifier.of("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0:#urn:www.peppol.eu:bis:peppol4a:ver1.0::2.0")).process(ProcessIdentifier.of("urn:www.cenbii.eu:profile:bii04:ver1.0"));
        }

        @Override
        public InputStream getPayload() {
            return new ByteArrayInputStream(firstPayload);
        }

        @Override
        public Tag getTag() {
            return new PeppolConfiguration() {

                @Override
                public List<String> getActions() {
                    return super.getActions();
                }

                @Override
                public String getPartyIDType() {
                    return "TestPartyIdType";
                }

                @Override
                public String getAgreementRef() {
                    return "TestAgreementRef";
                }

                @Override
                public String getFromRole() {
                    return "TestFromRole";
                }

                @Override
                public String getToRole() {
                    return "TestToRole";
                }

                @Override
                public String getIdentifier() {
                    return super.getIdentifier();
                }
            };
        }
    });
    Assert.assertNotNull(firstResponse);
    Assert.assertEquals(TransportProfile.AS4, firstResponse.getProtocol());
    Assert.assertEquals(temporaryFilePersister.size(), 1);
    Map<TemporaryFilePersister.Types, Object> dataFromFirstTransmission = temporaryFilePersister.getPersistedData(firstResponse.getTransmissionIdentifier());
    Assert.assertNotNull(dataFromFirstTransmission);
    Assert.assertEquals(firstResponse.getTransmissionIdentifier(), dataFromFirstTransmission.get(TemporaryFilePersister.Types.ID));
    Assert.assertNotNull(dataFromFirstTransmission.get(TemporaryFilePersister.Types.HEADER));
    Assert.assertEquals(firstPayload, (byte[]) dataFromFirstTransmission.get(TemporaryFilePersister.Types.PAYLOAD));
    // Perform a second transmission
    TransmissionResponse secondResponse = messageSender.send(new TransmissionRequest() {

        @Override
        public Endpoint getEndpoint() {
            return Endpoint.of(TransportProfile.AS4, URI.create("http://localhost:8080/as4"), injector.getInstance(X509Certificate.class));
        }

        @Override
        public Header getHeader() {
            return Header.newInstance().sender(ParticipantIdentifier.of("9908:991825827")).receiver(ParticipantIdentifier.of("9908:991825827")).documentType(DocumentTypeIdentifier.of("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:www.cenbii.eu:transaction:biicoretrdm010:ver1.0:#urn:test.com:bis:something_else:ver1.0::2.0", Scheme.of("TestSchema"))).process(ProcessIdentifier.of("urn:www.cenbii.eu:profile:something_else:ver1.0", Scheme.of("TestSchema")));
        }

        @Override
        public InputStream getPayload() {
            return new ByteArrayInputStream(secondPayload);
        }
    });
    Assert.assertNotNull(secondResponse);
    Assert.assertEquals(TransportProfile.AS4, secondResponse.getProtocol());
    Assert.assertNotEquals(secondResponse.getTransmissionIdentifier(), firstResponse.getTransmissionIdentifier());
    Assert.assertEquals(temporaryFilePersister.size(), 2);
    Map<TemporaryFilePersister.Types, Object> dataFromSecondTransmission = temporaryFilePersister.getPersistedData(secondResponse.getTransmissionIdentifier());
    Assert.assertNotNull(dataFromSecondTransmission);
    Assert.assertEquals(secondResponse.getTransmissionIdentifier(), dataFromSecondTransmission.get(TemporaryFilePersister.Types.ID));
    Assert.assertNotNull(dataFromSecondTransmission.get(TemporaryFilePersister.Types.HEADER));
    Assert.assertEquals(secondPayload, (byte[]) dataFromSecondTransmission.get(TemporaryFilePersister.Types.PAYLOAD));
}
Also used : MessageSender(network.oxalis.api.outbound.MessageSender) TransmissionRequest(network.oxalis.api.outbound.TransmissionRequest) PeppolConfiguration(network.oxalis.as4.util.PeppolConfiguration) TransmissionResponse(network.oxalis.api.outbound.TransmissionResponse) Tag(network.oxalis.api.tag.Tag) AbstractJettyServerTest(network.oxalis.test.jetty.AbstractJettyServerTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with PeppolConfiguration

use of network.oxalis.as4.util.PeppolConfiguration in project Oxalis-AS4 by OxalisCommunity.

the class MessagingProvider method createPartyInfo.

private PartyInfo createPartyInfo(TransmissionRequest request) {
    String fromName = CertificateUtils.extractCommonName(certificate);
    String toName = CertificateUtils.extractCommonName(request.getEndpoint().getCertificate());
    PeppolConfiguration outboundConfiguration = request.getTag() instanceof PeppolConfiguration ? (PeppolConfiguration) request.getTag() : defaultOutboundConfiguration;
    return PartyInfo.builder().withFrom(From.builder().withPartyId(PartyId.builder().withType(outboundConfiguration.getPartyIDType()).withValue(fromName).build()).withRole(outboundConfiguration.getFromRole()).build()).withTo(To.builder().withPartyId(PartyId.builder().withType(outboundConfiguration.getPartyIDType()).withValue(toName).build()).withRole(outboundConfiguration.getToRole()).build()).build();
}
Also used : PeppolConfiguration(network.oxalis.as4.util.PeppolConfiguration)

Aggregations

PeppolConfiguration (network.oxalis.as4.util.PeppolConfiguration)2 MessageSender (network.oxalis.api.outbound.MessageSender)1 TransmissionRequest (network.oxalis.api.outbound.TransmissionRequest)1 TransmissionResponse (network.oxalis.api.outbound.TransmissionResponse)1 Tag (network.oxalis.api.tag.Tag)1 AbstractJettyServerTest (network.oxalis.test.jetty.AbstractJettyServerTest)1 BeforeTest (org.testng.annotations.BeforeTest)1 Test (org.testng.annotations.Test)1