Search in sources :

Example 6 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA10.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). Simulate the RMSH to not send receipts
 * (can be done by intercepting the receipts). SMSH tries to send an AS4 User
 * Message to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The SMSH retries to send the AS4 User Message (at least once).
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA10() throws Exception {
    final int nProxyPort = 8001;
    final IStringMap aSettings = new StringMap();
    aSettings.putIn(SETTINGS_SERVER_PROXY_ENABLED, true);
    aSettings.putIn(SETTINGS_SERVER_PROXY_ADDRESS, "localhost");
    aSettings.putIn(SETTINGS_SERVER_PROXY_PORT, nProxyPort);
    try (final ScopedConfig aSC = ScopedConfig.createTestConfig(aSettings)) {
        final HttpProxyServer aProxyServer = _startProxyServer(nProxyPort);
        try {
            // send message
            final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, createTestSignedUserMessage(m_eSoapVersion, m_aPayload, null, s_aResMgr), null);
            sendMimeMessage(new HttpMimeMessageEntity(aMsg), false, EEbmsError.EBMS_OTHER.getErrorCode());
        } finally {
            aProxyServer.stop();
        }
    }
}
Also used : StringMap(com.helger.commons.collection.attr.StringMap) IStringMap(com.helger.commons.collection.attr.IStringMap) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) IStringMap(com.helger.commons.collection.attr.IStringMap) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) ScopedConfig(com.helger.phase4.ScopedConfig) Test(org.junit.Test)

Example 7 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA11.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile (One-Way/Push MEP). Simulate the RMSH to not send receipts.
 * SMSH tries to send an AS4 User Message to the RMSH. Before a TIME_OUT is
 * reached network connection is restored (RMSH is able to send a
 * non-repudiation receipt).<br>
 * <br>
 * Predicate: <br>
 * The RMSH sends back an AS4 non-repudiation receipt to the SMSH and delivers
 * only one message to the consumer and the SMSH stops resending the original
 * AS4 User Message.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA11() throws Exception {
    final int nProxyPort = 8001;
    final IStringMap aSettings = new StringMap();
    aSettings.putIn(SETTINGS_SERVER_PROXY_ENABLED, true);
    aSettings.putIn(SETTINGS_SERVER_PROXY_ADDRESS, "localhost");
    aSettings.putIn(SETTINGS_SERVER_PROXY_PORT, nProxyPort);
    try (final ScopedConfig aSC = ScopedConfig.createTestConfig(aSettings)) {
        // Simulating a timeout with Thread.sleep but before it entirely triggers
        // let the program continue as if the Connection is back up again
        final HttpProxyServer aProxyServer = DefaultHttpProxyServer.bootstrap().withPort(nProxyPort).withFiltersSource(new HttpFiltersSourceAdapter() {

            @Override
            public HttpFilters filterRequest(final HttpRequest originalRequest, final ChannelHandlerContext ctx) {
                return new HttpFiltersAdapter(originalRequest) {

                    @Override
                    public HttpResponse clientToProxyRequest(final HttpObject httpObject) {
                        ThreadHelper.sleep(500);
                        return null;
                    }

                    @Override
                    public HttpObject serverToProxyResponse(final HttpObject httpObject) {
                        LOGGER.error("Forcing a timeout from retryhandler ");
                        return httpObject;
                    }
                };
            }
        }).start();
        try {
            // send message
            final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, createTestSignedUserMessage(m_eSoapVersion, m_aPayload, null, s_aResMgr), null);
            sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
        } finally {
            aProxyServer.stop();
        }
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) HttpFiltersAdapter(org.littleshoot.proxy.HttpFiltersAdapter) StringMap(com.helger.commons.collection.attr.StringMap) IStringMap(com.helger.commons.collection.attr.IStringMap) DefaultHttpProxyServer(org.littleshoot.proxy.impl.DefaultHttpProxyServer) HttpProxyServer(org.littleshoot.proxy.HttpProxyServer) HttpObject(io.netty.handler.codec.http.HttpObject) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpFiltersSourceAdapter(org.littleshoot.proxy.HttpFiltersSourceAdapter) IStringMap(com.helger.commons.collection.attr.IStringMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) ScopedConfig(com.helger.phase4.ScopedConfig) Test(org.junit.Test)

Example 8 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA01.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile: One-Way/Push MEP. SMSH sends an AS4 User message to the
 * RMSH. <br>
 * <br>
 * Predicate:<br>
 * The RMSH returns a non-repudiation receipt within a HTTP response with
 * status code 2XX (for more details on http response codes please refer to
 * https://issues.oasis-open.org/browse/EBXMLMSG-57?jql=project%20%3D%20EBXMLMSG).
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA01() throws Exception {
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, createTestSignedUserMessage(m_eSoapVersion, m_aPayload, null, s_aResMgr), null);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) Test(org.junit.Test)

Example 9 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA07.

/**
 * Prerequisite:<br>
 * eSENS_TA06<br>
 * SMSH sends an AS4 message to the RMSH. <br>
 * <br>
 * Predicate: <br>
 * The RMSH successfully processes the AS4 message and sends a non-repudiation
 * receipt to the SMSH.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA07() throws Exception {
    // same stuff as TA05 only one step further
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_TEST_IMG_JPG)).mimeType(CMimeType.IMAGE_JPG).compressionGZIP().build(), s_aResMgr));
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML2_XML)).mimeTypeXML().compressionGZIP().build(), s_aResMgr));
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, createTestSignedUserMessage(m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr), aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Example 10 with HttpMimeMessageEntity

use of com.helger.phase4.http.HttpMimeMessageEntity in project phase4 by phax.

the class AS4eSENSCEFOneWayFuncTest method testEsens_TA04.

/**
 * Prerequisite:<br>
 * SMSH and RMSH are configured to exchange AS4 messages according to the
 * e-SENS profile. (One-Way/Push MEP) SMSH is simulated to produce
 * uncompressed payloads. The SMSH sends the AS4 message to the RMSH.<br>
 * <br>
 * Predicate: <br>
 * The RMSH returns a non-repudiation receipt and delivers the message to the
 * consumer. <br>
 * <br>
 * k Goal: Do not throw an error if a uncompressed payload gets sent, also
 * check if compressed payloads are acceptable aswell.
 *
 * @throws Exception
 *         In case of error
 */
@Test
public void testEsens_TA04() throws Exception {
    final ICommonsList<WSS4JAttachment> aAttachments = new CommonsArrayList<>();
    aAttachments.add(WSS4JAttachment.createOutgoingFileAttachment(Phase4OutgoingAttachment.builder().data(ClassPathResource.getAsFile(AS4TestConstants.ATTACHMENT_SHORTXML_XML)).mimeTypeXML().build(), s_aResMgr));
    final AS4MimeMessage aMsg = MimeMessageCreator.generateMimeMessage(m_eSoapVersion, createTestSignedUserMessage(m_eSoapVersion, m_aPayload, aAttachments, s_aResMgr), aAttachments);
    final String sResponse = sendMimeMessage(new HttpMimeMessageEntity(aMsg), true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
Also used : AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) Test(org.junit.Test)

Aggregations

HttpMimeMessageEntity (com.helger.phase4.http.HttpMimeMessageEntity)43 AS4MimeMessage (com.helger.phase4.messaging.mime.AS4MimeMessage)43 Test (org.junit.Test)41 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)36 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)36 Document (org.w3c.dom.Document)20 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)16 IStringMap (com.helger.commons.collection.attr.IStringMap)3 StringMap (com.helger.commons.collection.attr.StringMap)3 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)3 ScopedConfig (com.helger.phase4.ScopedConfig)3 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)3 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)3 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)3 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)3 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)3 HttpProxyServer (org.littleshoot.proxy.HttpProxyServer)3 DefaultHttpProxyServer (org.littleshoot.proxy.impl.DefaultHttpProxyServer)3 Node (org.w3c.dom.Node)3 IAS4CryptoFactory (com.helger.phase4.crypto.IAS4CryptoFactory)2