Search in sources :

Example 1 with Messaging

use of org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging 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 2 with Messaging

use of org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging in project Oxalis-AS4 by OxalisCommunity.

the class As4Interceptor method getMessaging.

private Messaging getMessaging(Message message) {
    SoapMessage soapMessage = (SoapMessage) message;
    Header header = soapMessage.getHeader(Constants.MESSAGING_QNAME);
    try {
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        return unmarshaller.unmarshal((Node) header.getObject(), Messaging.class).getValue();
    } catch (JAXBException e) {
        throw new Fault(e);
    }
}
Also used : Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) Messaging(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging) Fault(org.apache.cxf.interceptor.Fault) Unmarshaller(javax.xml.bind.Unmarshaller) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 3 with Messaging

use of org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging in project Oxalis-AS4 by OxalisCommunity.

the class AbstractSetPolicyInterceptor method getMessaging.

private Optional<Messaging> getMessaging(Message message) {
    SoapMessage soapMessage = (SoapMessage) message;
    Header header = soapMessage.getHeader(Constants.MESSAGING_QNAME);
    if (header == null) {
        return Optional.empty();
    }
    try {
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Messaging messaging = unmarshaller.unmarshal((Node) header.getObject(), Messaging.class).getValue();
        return Optional.of(messaging);
    } catch (JAXBException e) {
        throw new Fault(e);
    }
}
Also used : Header(org.apache.cxf.headers.Header) Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) Messaging(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging) Fault(org.apache.cxf.interceptor.Fault) Unmarshaller(javax.xml.bind.Unmarshaller) SoapMessage(org.apache.cxf.binding.soap.SoapMessage)

Example 4 with Messaging

use of org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging in project Oxalis-AS4 by OxalisCommunity.

the class AbstractSetPolicyInterceptor method handleMessage.

@Override
public void handleMessage(SoapMessage message) throws Fault {
    message.put(USE_ATTACHMENT_ENCRYPTION_CONTENT_ONLY_TRANSFORM, true);
    Optional<UserMessage> userMessage = getMessaging(message).map(Messaging::getUserMessage).map(Collection::stream).orElseGet(Stream::empty).findFirst();
    try {
        Policy policy = userMessage.isPresent() ? policyService.getPolicy(userMessage.get().getCollaborationInfo()) : policyService.getPolicy();
        message.put(PolicyConstants.POLICY_OVERRIDE, policy);
    } catch (Exception e) {
        throw new Fault(e);
    }
}
Also used : Policy(org.apache.neethi.Policy) Collection(java.util.Collection) UserMessage(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.UserMessage) Fault(org.apache.cxf.interceptor.Fault) JAXBException(javax.xml.bind.JAXBException)

Example 5 with Messaging

use of org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging in project Oxalis-AS4 by OxalisCommunity.

the class SOAPHeaderParser method getUserMessage.

public static UserMessage getUserMessage(SOAPHeader header) throws OxalisAs4Exception {
    Node messagingNode = header.getElementsByTagNameNS(NS_ALL, MESSAGING).item(0);
    try {
        Unmarshaller unmarshaller = JAXB_CONTEXT.createUnmarshaller();
        Messaging messaging = unmarshaller.unmarshal(messagingNode, Messaging.class).getValue();
        return messaging.getUserMessage().stream().findFirst().orElseThrow(() -> new OxalisAs4Exception("No UserMessage present in header"));
    } catch (JAXBException e) {
        throw new OxalisAs4Exception("Could not unmarshal Messaging node from header");
    }
}
Also used : Node(org.w3c.dom.Node) JAXBException(javax.xml.bind.JAXBException) Messaging(org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging) OxalisAs4Exception(network.oxalis.as4.lang.OxalisAs4Exception) Unmarshaller(javax.xml.bind.Unmarshaller)

Aggregations

Messaging (org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.Messaging)7 JAXBException (javax.xml.bind.JAXBException)5 Fault (org.apache.cxf.interceptor.Fault)5 Unmarshaller (javax.xml.bind.Unmarshaller)3 OxalisAs4Exception (network.oxalis.as4.lang.OxalisAs4Exception)3 UserMessage (org.oasis_open.docs.ebxml_msg.ebms.v3_0.ns.core._200704.UserMessage)3 Node (org.w3c.dom.Node)3 Collection (java.util.Collection)2 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)2 Header (org.apache.cxf.headers.Header)2 Attachment (org.apache.cxf.message.Attachment)2 Policy (org.apache.neethi.Policy)2 NoopTracerFactory (io.opentracing.noop.NoopTracerFactory)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 BigInteger (java.math.BigInteger)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 X509Certificate (java.security.cert.X509Certificate)1 java.util (java.util)1