Search in sources :

Example 1 with Soap11Envelope

use of com.helger.phase4.soap11.Soap11Envelope in project phase4 by phax.

the class Ebms3ReaderBuilderTest method testSoap.

@Test
public void testSoap() {
    final CollectingValidationEventHandler aCVEH = new CollectingValidationEventHandler();
    final Soap11Envelope aEnv = Ebms3ReaderBuilder.soap11().setValidationEventHandler(aCVEH).read(new ClassPathResource("/soap11test/UserMessage.xml"));
    assertNotNull(aEnv);
    assertTrue(aCVEH.getErrorList().isEmpty());
    assertNotNull(aEnv.getHeader());
    assertEquals(1, aEnv.getHeader().getAnyCount());
    assertTrue(aEnv.getHeader().getAnyAtIndex(0) instanceof Element);
    final Ebms3Messaging aMessage = Ebms3ReaderBuilder.ebms3Messaging().setValidationEventHandler(aCVEH).read((Element) aEnv.getHeader().getAnyAtIndex(0));
    assertNotNull(aMessage);
    final String sReRead = Ebms3WriterBuilder.soap11().getAsString(aEnv);
    assertNotNull(sReRead);
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Just to recheck what was read: " + sReRead);
}
Also used : Soap11Envelope(com.helger.phase4.soap11.Soap11Envelope) CollectingValidationEventHandler(com.helger.jaxb.validation.CollectingValidationEventHandler) Element(org.w3c.dom.Element) Ebms3Messaging(com.helger.phase4.ebms3header.Ebms3Messaging) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 2 with Soap11Envelope

use of com.helger.phase4.soap11.Soap11Envelope in project phase4 by phax.

the class AbstractAS4Message method getAsSoapDocument.

@Nonnull
public final Document getAsSoapDocument(@Nullable final Node aPayload) {
    // Convert to DOM Node
    final Document aEbms3Document = Ebms3WriterBuilder.ebms3Messaging().getAsDocument(m_aMessaging);
    if (aEbms3Document == null)
        throw new IllegalStateException("Failed to write EBMS3 Messaging to XML");
    final Node aRealPayload = aPayload instanceof Document ? ((Document) aPayload).getDocumentElement() : aPayload;
    switch(m_eSoapVersion) {
        case SOAP_11:
            {
                // Creating SOAP 11 Envelope
                final Soap11Envelope aSoapEnv = new Soap11Envelope();
                aSoapEnv.setHeader(new Soap11Header());
                aSoapEnv.setBody(new Soap11Body());
                aSoapEnv.getHeader().addAny(aEbms3Document.getDocumentElement());
                if (aRealPayload != null)
                    aSoapEnv.getBody().addAny(aRealPayload);
                return Ebms3WriterBuilder.soap11().getAsDocument(aSoapEnv);
            }
        case SOAP_12:
            {
                // Creating SOAP 12 Envelope
                final Soap12Envelope aSoapEnv = new Soap12Envelope();
                aSoapEnv.setHeader(new Soap12Header());
                aSoapEnv.setBody(new Soap12Body());
                aSoapEnv.getHeader().addAny(aEbms3Document.getDocumentElement());
                if (aRealPayload != null)
                    aSoapEnv.getBody().addAny(aRealPayload);
                return Ebms3WriterBuilder.soap12().getAsDocument(aSoapEnv);
            }
        default:
            throw new IllegalStateException("Unsupported SOAP version " + m_eSoapVersion);
    }
}
Also used : Soap11Envelope(com.helger.phase4.soap11.Soap11Envelope) Soap12Envelope(com.helger.phase4.soap12.Soap12Envelope) Soap11Header(com.helger.phase4.soap11.Soap11Header) Node(org.w3c.dom.Node) Soap12Header(com.helger.phase4.soap12.Soap12Header) Soap11Body(com.helger.phase4.soap11.Soap11Body) Soap12Body(com.helger.phase4.soap12.Soap12Body) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Example 3 with Soap11Envelope

use of com.helger.phase4.soap11.Soap11Envelope in project phase4 by phax.

the class Ebms3ReaderBuilderTest method testUserMessageMessageInfoIDMissing.

@Test
public void testUserMessageMessageInfoIDMissing() {
    final CollectingValidationEventHandler aCVEH = new CollectingValidationEventHandler();
    final Soap11Envelope aEnv = Ebms3ReaderBuilder.soap11().setValidationEventHandler(aCVEH).read(new ClassPathResource("/soap11test/MessageInfoIDMissing.xml"));
    assertNotNull(aEnv);
    assertTrue(aCVEH.getErrorList().isEmpty());
    assertNotNull(aEnv.getHeader());
    assertEquals(1, aEnv.getHeader().getAnyCount());
    assertTrue(aEnv.getHeader().getAnyAtIndex(0) instanceof Element);
    final Ebms3Messaging aMessage = Ebms3ReaderBuilder.ebms3Messaging().setValidationEventHandler(aCVEH).read((Element) aEnv.getHeader().getAnyAtIndex(0));
    assertTrue(aCVEH.getErrorList().containsAtLeastOneError());
    assertNull(aMessage);
}
Also used : Soap11Envelope(com.helger.phase4.soap11.Soap11Envelope) CollectingValidationEventHandler(com.helger.jaxb.validation.CollectingValidationEventHandler) Element(org.w3c.dom.Element) Ebms3Messaging(com.helger.phase4.ebms3header.Ebms3Messaging) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 4 with Soap11Envelope

use of com.helger.phase4.soap11.Soap11Envelope in project phase4 by phax.

the class Ebms3ReaderBuilderTest method testUserMessageMessageInfoMissing.

@Test
public void testUserMessageMessageInfoMissing() {
    final CollectingValidationEventHandler aCVEH = new CollectingValidationEventHandler();
    final Soap11Envelope aEnv = Ebms3ReaderBuilder.soap11().setValidationEventHandler(aCVEH).read(new ClassPathResource("/soap11test/MessageInfoMissing.xml"));
    assertNotNull(aEnv);
    assertTrue(aCVEH.getErrorList().isEmpty());
    assertNotNull(aEnv.getHeader());
    assertEquals(1, aEnv.getHeader().getAnyCount());
    assertTrue(aEnv.getHeader().getAnyAtIndex(0) instanceof Element);
    final Ebms3Messaging aMessage = Ebms3ReaderBuilder.ebms3Messaging().setValidationEventHandler(aCVEH).read((Element) aEnv.getHeader().getAnyAtIndex(0));
    assertTrue(aCVEH.getErrorList().containsAtLeastOneError());
    assertNull(aMessage);
}
Also used : Soap11Envelope(com.helger.phase4.soap11.Soap11Envelope) CollectingValidationEventHandler(com.helger.jaxb.validation.CollectingValidationEventHandler) Element(org.w3c.dom.Element) Ebms3Messaging(com.helger.phase4.ebms3header.Ebms3Messaging) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 5 with Soap11Envelope

use of com.helger.phase4.soap11.Soap11Envelope in project phase4 by phax.

the class Ebms3ReaderBuilderTest method testExpectSoap11ButFileIsSoap12.

@Test
public void testExpectSoap11ButFileIsSoap12() {
    final CollectingValidationEventHandler aCVEH = new CollectingValidationEventHandler();
    final Soap11Envelope aEnv = Ebms3ReaderBuilder.soap11().setValidationEventHandler(aCVEH).read(new ClassPathResource("/soap12test/UserMessage12.xml"));
    assertNull(aEnv);
    assertFalse(aCVEH.getErrorList().isEmpty());
}
Also used : Soap11Envelope(com.helger.phase4.soap11.Soap11Envelope) CollectingValidationEventHandler(com.helger.jaxb.validation.CollectingValidationEventHandler) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Aggregations

Soap11Envelope (com.helger.phase4.soap11.Soap11Envelope)5 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)4 CollectingValidationEventHandler (com.helger.jaxb.validation.CollectingValidationEventHandler)4 Test (org.junit.Test)4 Ebms3Messaging (com.helger.phase4.ebms3header.Ebms3Messaging)3 Element (org.w3c.dom.Element)3 Soap11Body (com.helger.phase4.soap11.Soap11Body)1 Soap11Header (com.helger.phase4.soap11.Soap11Header)1 Soap12Body (com.helger.phase4.soap12.Soap12Body)1 Soap12Envelope (com.helger.phase4.soap12.Soap12Envelope)1 Soap12Header (com.helger.phase4.soap12.Soap12Header)1 Nonnull (javax.annotation.Nonnull)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1