Search in sources :

Example 1 with TransmissionRequest

use of network.oxalis.api.outbound.TransmissionRequest 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 TransmissionRequest

use of network.oxalis.api.outbound.TransmissionRequest in project Oxalis-AS4 by OxalisCommunity.

the class AbstractMessagingProviderTest method testCreateMessagingHeader.

@Test
public void testCreateMessagingHeader() throws Exception {
    TransmissionRequestFactory transmissionRequestFactory = new TransmissionRequestFactory(new NoopContentDetector(), new NoopContentWrapper(), new NoopTagGenerator(), new SbdhHeaderParser(), NoopTracerFactory.create());
    TransmissionMessage transmissionMessage;
    try (InputStream inputStream = getClass().getResourceAsStream(getPayloadPath())) {
        transmissionMessage = transmissionRequestFactory.newInstance(inputStream);
    }
    Assert.assertNotNull(transmissionMessage.getHeader());
    TransmissionRequest transmissionRequest = new DefaultTransmissionRequestFacade(transmissionMessage, Endpoint.of(TransportProfile.PEPPOL_AS2_2_0, null, receiverCert));
    HashMap<String, List<String>> headers = new HashMap<>();
    headers.put(Content_ID_KEY, Collections.singletonList(Content_ID_VALUE));
    headers.put(COMPRESSION_TYPE_KEY, Collections.singletonList(COMPRESSION_TYPE_VALUE));
    headers.put(MIME_TYPE_KEY, Collections.singletonList(MIME_TYPE_VALUE));
    Attachment attachment = AttachmentUtil.createAttachment(transmissionRequest.getPayload(), headers);
    Messaging messaging = messagingProvider.createMessagingHeader(transmissionRequest, new ArrayList<>(Collections.singletonList(attachment)));
    UserMessage userMessage = messaging.getUserMessage().get(0);
    // MessageInfo
    XMLGregorianCalendar timestamp = userMessage.getMessageInfo().getTimestamp();
    String messageId = userMessage.getMessageInfo().getMessageId();
    Assert.assertNotNull(timestamp);
    Assert.assertNotNull(messageId);
    // PartyInfo
    String to = userMessage.getPartyInfo().getTo().getPartyId().get(0).getValue();
    String toType = userMessage.getPartyInfo().getTo().getPartyId().get(0).getType();
    String toRole = userMessage.getPartyInfo().getTo().getRole();
    String from = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getValue();
    String fromType = userMessage.getPartyInfo().getFrom().getPartyId().get(0).getType();
    String fromRole = userMessage.getPartyInfo().getFrom().getRole();
    Assert.assertEquals(to, RECEIVER);
    Assert.assertEquals(toType, PARTY_TYPE);
    Assert.assertEquals(toRole, TO_ROLE);
    Assert.assertEquals(from, SENDER);
    Assert.assertEquals(fromType, PARTY_TYPE);
    Assert.assertEquals(fromRole, FROM_ROLE);
    // CollaborationInfo
    String action = userMessage.getCollaborationInfo().getAction();
    Service service = userMessage.getCollaborationInfo().getService();
    String conversationId = userMessage.getCollaborationInfo().getConversationId();
    Assert.assertEquals(action, ACTION);
    Assert.assertEquals(service.getType(), SERVICE_TYPE);
    Assert.assertEquals(service.getValue(), SERVICE_VALUE);
    Assert.assertNotNull(conversationId);
    // MessageProperties
    String finalRecipient = userMessage.getMessageProperties().getProperty().stream().filter(p -> "finalRecipient".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
    String originalSender = userMessage.getMessageProperties().getProperty().stream().filter(p -> "originalSender".equalsIgnoreCase(p.getName())).map(Property::getValue).findFirst().get();
    Assert.assertEquals(finalRecipient, FINAL_RECIPIENT);
    Assert.assertEquals(originalSender, ORIGINAL_SENDER);
    // PayloadInfo
    int payloadCount = userMessage.getPayloadInfo().getPartInfo().size();
    Assert.assertEquals(payloadCount, 1);
    List<Property> partInfo = userMessage.getPayloadInfo().getPartInfo().get(0).getPartProperties().getProperty();
    String compressionType = partInfo.stream().filter(pi -> COMPRESSION_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
    String mimeType = partInfo.stream().filter(pi -> MIME_TYPE_KEY.equalsIgnoreCase(pi.getName())).map(Property::getValue).findFirst().get();
    String contentID = userMessage.getPayloadInfo().getPartInfo().get(0).getHref();
    Assert.assertEquals(compressionType, COMPRESSION_TYPE_VALUE);
    Assert.assertEquals(mimeType, MIME_TYPE_VALUE);
    Assert.assertEquals(contentID, "cid:" + Content_ID_VALUE);
}
Also used : X509Certificate(java.security.cert.X509Certificate) KeyPair(java.security.KeyPair) DefaultTransmissionRequestFacade(network.oxalis.outbound.transmission.DefaultTransmissionRequestFacade) java.util(java.util) ContentSigner(org.bouncycastle.operator.ContentSigner) JcaX509CertificateConverter(org.bouncycastle.cert.jcajce.JcaX509CertificateConverter) JcaContentSignerBuilder(org.bouncycastle.operator.jcajce.JcaContentSignerBuilder) Test(org.testng.annotations.Test) Endpoint(network.oxalis.vefa.peppol.common.model.Endpoint) Attachment(org.apache.cxf.message.Attachment) X500Name(org.bouncycastle.asn1.x500.X500Name) Assert(org.testng.Assert) TransmissionRequestFactory(network.oxalis.outbound.transmission.TransmissionRequestFactory) BigInteger(java.math.BigInteger) TransmissionMessage(network.oxalis.api.outbound.TransmissionMessage) TransportProfile(network.oxalis.vefa.peppol.common.model.TransportProfile) KeyPairGenerator(java.security.KeyPairGenerator) NoopContentDetector(network.oxalis.commons.transformer.NoopContentDetector) NoopTracerFactory(io.opentracing.noop.NoopTracerFactory) JcaX509v3CertificateBuilder(org.bouncycastle.cert.jcajce.JcaX509v3CertificateBuilder) BeforeClass(org.testng.annotations.BeforeClass) TransmissionRequest(network.oxalis.api.outbound.TransmissionRequest) SbdhHeaderParser(network.oxalis.commons.header.SbdhHeaderParser) Messaging(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DefaultMessageIdGenerator(network.oxalis.as4.common.DefaultMessageIdGenerator) MessagingProviderFacade(network.oxalis.outbound.transmission.MessagingProviderFacade) NoopContentWrapper(network.oxalis.commons.transformer.NoopContentWrapper) AttachmentUtil(org.apache.cxf.attachment.AttachmentUtil) UserMessage(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.UserMessage) Property(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Property) Service(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Service) NoopTagGenerator(network.oxalis.commons.tag.NoopTagGenerator) PeppolConfiguration(network.oxalis.as4.util.PeppolConfiguration) InputStream(java.io.InputStream) TransmissionMessage(network.oxalis.api.outbound.TransmissionMessage) NoopTagGenerator(network.oxalis.commons.tag.NoopTagGenerator) InputStream(java.io.InputStream) Service(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Service) Attachment(org.apache.cxf.message.Attachment) UserMessage(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.UserMessage) SbdhHeaderParser(network.oxalis.commons.header.SbdhHeaderParser) Endpoint(network.oxalis.vefa.peppol.common.model.Endpoint) TransmissionRequest(network.oxalis.api.outbound.TransmissionRequest) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) NoopContentWrapper(network.oxalis.commons.transformer.NoopContentWrapper) Messaging(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging) NoopContentDetector(network.oxalis.commons.transformer.NoopContentDetector) Property(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Property) TransmissionRequestFactory(network.oxalis.outbound.transmission.TransmissionRequestFactory) DefaultTransmissionRequestFacade(network.oxalis.outbound.transmission.DefaultTransmissionRequestFacade) Test(org.testng.annotations.Test)

Example 3 with TransmissionRequest

use of network.oxalis.api.outbound.TransmissionRequest in project Oxalis-AS4 by OxalisCommunity.

the class MessagingProvider method createPayloadInfo.

private PayloadInfo createPayloadInfo(TransmissionRequest request, Collection<Attachment> attachments) {
    ArrayList<PartInfo> partInfos = Lists.newArrayList();
    for (Attachment attachment : attachments) {
        PartProperties.Builder<Void> partProperties = PartProperties.builder();
        String cid = "cid:" + AttachmentUtil.cleanContentId(attachment.getId());
        iteratorToStreamOfUnknownSize(attachment.getHeaderNames(), Spliterator.ORDERED, false).filter(header -> !"Content-ID".equals(header)).map(header -> Property.builder().withName(header).withValue(attachment.getHeader(header)).build()).forEach(partProperties::addProperty);
        if (request instanceof As4TransmissionRequest) {
            As4TransmissionRequest as4TransmissionRequest = (As4TransmissionRequest) request;
            if (null != as4TransmissionRequest.getPayloadCharset()) {
                partProperties.addProperty(Property.builder().withName("CharacterSet").withValue(as4TransmissionRequest.getPayloadCharset().name().toLowerCase()).build());
            }
            if (null != as4TransmissionRequest.getCompressionType()) {
                partProperties.addProperty(Property.builder().withName("CompressionType").withValue(as4TransmissionRequest.getCompressionType()).build());
            }
        }
        PartInfo partInfo = PartInfo.builder().withHref(cid).withPartProperties(partProperties.build()).build();
        partInfos.add(partInfo);
    }
    return PayloadInfo.builder().withPartInfo(partInfos).build();
}
Also used : X509Certificate(java.security.cert.X509Certificate) As4MessageProperties(network.oxalis.as4.common.As4MessageProperties) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Inject(com.google.inject.Inject) MessageIdGenerator(network.oxalis.as4.api.MessageIdGenerator) CertificateUtils(network.oxalis.commons.security.CertificateUtils) LocalDateTime(java.time.LocalDateTime) TEST_ACTION(network.oxalis.as4.util.Constants.TEST_ACTION) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayList(java.util.ArrayList) Attachment(org.apache.cxf.message.Attachment) Lists(com.google.common.collect.Lists) GeneralUtils.iteratorToStreamOfUnknownSize(network.oxalis.as4.util.GeneralUtils.iteratorToStreamOfUnknownSize) TransmissionRequestUtil(network.oxalis.as4.util.TransmissionRequestUtil) GregorianCalendar(java.util.GregorianCalendar) Collection(java.util.Collection) TransmissionRequest(network.oxalis.api.outbound.TransmissionRequest) org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) TEST_SERVICE(network.oxalis.as4.util.Constants.TEST_SERVICE) AttachmentUtil(org.apache.cxf.attachment.AttachmentUtil) Spliterator(java.util.Spliterator) PeppolConfiguration(network.oxalis.as4.util.PeppolConfiguration) ProcessIdentifier(network.oxalis.vefa.peppol.common.model.ProcessIdentifier) Attachment(org.apache.cxf.message.Attachment)

Aggregations

TransmissionRequest (network.oxalis.api.outbound.TransmissionRequest)3 PeppolConfiguration (network.oxalis.as4.util.PeppolConfiguration)3 X509Certificate (java.security.cert.X509Certificate)2 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)2 AttachmentUtil (org.apache.cxf.attachment.AttachmentUtil)2 Attachment (org.apache.cxf.message.Attachment)2 Test (org.testng.annotations.Test)2 Lists (com.google.common.collect.Lists)1 Inject (com.google.inject.Inject)1 NoopTracerFactory (io.opentracing.noop.NoopTracerFactory)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 LocalDateTime (java.time.LocalDateTime)1 ZoneId (java.time.ZoneId)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 GregorianCalendar (java.util.GregorianCalendar)1