Search in sources :

Example 11 with StopWatch

use of com.helger.commons.timing.StopWatch in project phoss-smp by phax.

the class MainReadFromFilePeppol method main.

public static void main(final String[] args) throws Throwable {
    final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-xml-peppol.properties").getAbsolutePath());
    aRule.before();
    try {
        final String sServerBasePath = aRule.getFullURL();
        final StopWatch aSWOverall = StopWatch.createdStarted();
        // These values must match the values in the test file
        final IParticipantIdentifier aParticipantID = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
        final IDocumentTypeIdentifier aDocTypeID = PeppolIdentifierFactory.INSTANCE.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1");
        // Delete existing ServiceGroup (if exists)
        {
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("delete-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
            _testResponseJerseyClient(aResponseMsg, 200, 404);
        }
        {
            // Create a new ServiceGroup
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).queryParam("create-in-sml", Boolean.FALSE).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-group.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add endpoint
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path(aParticipantID.getURIEncoded()).path("services").path(aDocTypeID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-service-metadata.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        {
            // Add Business Card
            final Response aResponseMsg = ClientBuilder.newClient().target(sServerBasePath).path("businesscard").path(aParticipantID.getURIEncoded()).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(new File("src/test/resources/rest-files/peppol-business-card-v3.xml")));
            _testResponseJerseyClient(aResponseMsg, 200);
        }
        aSWOverall.stop();
        LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
    } finally {
        aRule.after();
    }
}
Also used : Response(javax.ws.rs.core.Response) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) File(java.io.File) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier)

Example 12 with StopWatch

use of com.helger.commons.timing.StopWatch in project phoss-smp by phax.

the class MainCreate1MillionEndpoints method main.

public static void main(final String[] args) throws Throwable {
    final SMPServerRESTTestRule aRule = new SMPServerRESTTestRule(ClassPathResource.getAsFile("test-smp-server-mongodb.properties").getAbsolutePath());
    aRule.before();
    try {
        // Set the special PhotonSecurityManager factory
        PhotonSecurityManager.setFactory(new PhotonSecurityManagerFactoryMongoDB());
        final ObjectFactory aObjFactory = new ObjectFactory();
        final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
        final String sDT = aDT.getURIEncoded();
        final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
        final StopWatch aSWOverall = StopWatch.createdStarted();
        for (int i = 639276; i < 1_000_000; ++i) {
            final StopWatch aSW = StopWatch.createdStarted();
            final PeppolParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9999:test-philip-" + StringHelper.getLeadingZero(i, 7));
            final String sPI = aPI.getURIEncoded();
            final ServiceMetadataType aSM = new ServiceMetadataType();
            final ServiceInformationType aSI = new ServiceInformationType();
            aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI));
            aSI.setDocumentIdentifier(aDT);
            {
                final ProcessListType aPL = new ProcessListType();
                final ProcessType aProcess = new ProcessType();
                aProcess.setProcessIdentifier(aProcID);
                final ServiceEndpointList aSEL = new ServiceEndpointList();
                final EndpointType aEndpoint = new EndpointType();
                aEndpoint.setEndpointReference(W3CEndpointReferenceHelper.createEndpointReference("http://test.smpserver/as2"));
                aEndpoint.setRequireBusinessLevelSignature(false);
                aEndpoint.setCertificate("blacert");
                aEndpoint.setServiceDescription("Unit test service");
                aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
                aEndpoint.setTransportProfile(ESMPTransportProfile.TRANSPORT_PROFILE_AS2.getID());
                aSEL.addEndpoint(aEndpoint);
                aProcess.setServiceEndpointList(aSEL);
                aPL.addProcess(aProcess);
                aSI.setProcessList(aPL);
            }
            aSM.setServiceInformation(aSI);
            try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
                // Delete old - don't care about the result
                if (false)
                    ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).delete();
                // Create a new
                final Response aResponseMsg = ClientBuilder.newClient().target(aRule.getFullURL()).path(sPI).path("services").path(sDT).request().header(CHttpHeader.AUTHORIZATION, CREDENTIALS.getRequestValue()).put(Entity.xml(aObjFactory.createServiceMetadata(aSM)));
                _testResponseJerseyClient(aResponseMsg, 200);
            }
            aSW.stop();
            LOGGER.info(sPI + " took " + aSW.getMillis() + " ms");
        }
        aSWOverall.stop();
        LOGGER.info("Overall process took " + aSWOverall.getMillis() + " ms or " + aSWOverall.getDuration());
    } finally {
        aRule.after();
    }
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) PhotonSecurityManagerFactoryMongoDB(com.helger.phoss.smp.backend.mongodb.PhotonSecurityManagerFactoryMongoDB) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) PeppolProcessIdentifier(com.helger.peppolid.peppol.process.PeppolProcessIdentifier) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) SMPServerRESTTestRule(com.helger.phoss.smp.mock.SMPServerRESTTestRule) StopWatch(com.helger.commons.timing.StopWatch) PeppolParticipantIdentifier(com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier) Response(javax.ws.rs.core.Response) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) ObjectFactory(com.helger.xsds.peppol.smp1.ObjectFactory) PeppolDocumentTypeIdentifier(com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceMetadataType(com.helger.xsds.peppol.smp1.ServiceMetadataType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList)

Example 13 with StopWatch

use of com.helger.commons.timing.StopWatch in project ph-schematron by phax.

the class Issue099Test method _validateAndProduceSVRL.

private static void _validateAndProduceSVRL(@Nonnull final File aSchematron, @Nonnull final File aXML) throws Exception {
    SchematronDebug.setSaveIntermediateXSLTFiles(true);
    final StopWatch aSW = StopWatch.createdStarted();
    LOGGER.info("Start");
    final ISchematronResource aSCH = SchematronResourcePure.fromFile(aSchematron);
    if (aSCH instanceof SchematronResourcePure)
        ((SchematronResourcePure) aSCH).setCustomValidationHandler(new LoggingPSValidationHandler());
    // Perform validation
    final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL(new FileSystemResource(aXML));
    assertNotNull(aSVRL);
    aSW.stop();
    LOGGER.info("Took " + aSW.getDuration());
    LOGGER.info("SVRL:\n" + new SVRLMarshaller().getAsString(aSVRL));
    assertTrue(SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(aSVRL).isEmpty());
}
Also used : SchematronOutputType(com.helger.schematron.svrl.jaxb.SchematronOutputType) ISchematronResource(com.helger.schematron.ISchematronResource) SVRLMarshaller(com.helger.schematron.svrl.SVRLMarshaller) LoggingPSValidationHandler(com.helger.schematron.pure.validation.LoggingPSValidationHandler) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) SchematronResourcePure(com.helger.schematron.pure.SchematronResourcePure) StopWatch(com.helger.commons.timing.StopWatch)

Example 14 with StopWatch

use of com.helger.commons.timing.StopWatch in project phoss-directory by phax.

the class ExportAllDataJob method exportAllBusinessCards.

public static void exportAllBusinessCards() throws IOException {
    // Avoid running it in parallel
    if (!EXPORT_RUNNING.getAndSet(true)) {
        EXPORT_START_DT = PDTFactory.getCurrentLocalDateTime();
        final StopWatch aSW = StopWatch.createdStarted();
        try {
            LOGGER.info("Start exporting business cards as XML (full)");
            try {
                ExportAllManager.writeFileBusinessCardXMLFull(EQueryMode.NON_DELETED_ONLY);
            } finally {
                LOGGER.info("Finished exporting business cards as XML (full) after " + aSW.stopAndGetMillis() + " milliseconds");
            }
            aSW.restart();
            LOGGER.info("Start exporting business cards as XML (no doc types)");
            try {
                ExportAllManager.writeFileBusinessCardXMLNoDocTypes(EQueryMode.NON_DELETED_ONLY);
            } finally {
                LOGGER.info("Finished exporting business cards as XML (no doc types) after " + aSW.stopAndGetMillis() + " milliseconds");
            }
            if (CPDPublisher.EXPORT_BUSINESS_CARDS_EXCEL) {
                aSW.restart();
                LOGGER.info("Start exporting business cards as Excel");
                try {
                    ExportAllManager.writeFileBusinessCardExcel(EQueryMode.NON_DELETED_ONLY);
                } finally {
                    LOGGER.info("Finished exporting business cards as Excel after " + aSW.stopAndGetMillis() + " milliseconds");
                }
            }
            if (CPDPublisher.EXPORT_BUSINESS_CARDS_CSV) {
                aSW.restart();
                LOGGER.info("Start exporting business cards as CSV");
                try {
                    ExportAllManager.writeFileBusinessCardCSV(EQueryMode.NON_DELETED_ONLY);
                } finally {
                    LOGGER.info("Finished exporting business cards as CSV after " + aSW.stopAndGetMillis() + " milliseconds");
                }
            }
            if (CPDPublisher.EXPORT_PARTICIPANTS_XML) {
                aSW.restart();
                LOGGER.info("Start exporting participants as XML");
                try {
                    ExportAllManager.writeFileParticipantXML(EQueryMode.NON_DELETED_ONLY);
                } finally {
                    LOGGER.info("Finished exporting participants as XML after " + aSW.stopAndGetMillis() + " milliseconds");
                }
            }
            if (CPDPublisher.EXPORT_PARTICIPANTS_JSON) {
                aSW.restart();
                LOGGER.info("Start exporting participants as JSON");
                try {
                    ExportAllManager.writeFileParticipantJSON(EQueryMode.NON_DELETED_ONLY);
                } finally {
                    LOGGER.info("Finished exporting participants as JSON after " + aSW.stopAndGetMillis() + " milliseconds");
                }
            }
            if (CPDPublisher.EXPORT_PARTICIPANTS_CSV) {
                aSW.restart();
                LOGGER.info("Start exporting participants as CSV");
                try {
                    ExportAllManager.writeFileParticipantCSV(EQueryMode.NON_DELETED_ONLY);
                } finally {
                    LOGGER.info("Finished exporting participants as CSV after " + aSW.stopAndGetMillis() + " milliseconds");
                }
            }
        } finally {
            EXPORT_START_DT = null;
            EXPORT_RUNNING.set(false);
        }
    } else {
        LOGGER.info("Export is already running, so avoiding a parallel run");
    }
}
Also used : StopWatch(com.helger.commons.timing.StopWatch)

Example 15 with StopWatch

use of com.helger.commons.timing.StopWatch in project phase4 by phax.

the class BasicHttpPoster method sendGenericMessage.

/**
 * Send an arbitrary HTTP POST message to the provided URL, using the
 * contained HttpClientFactory as well as the customizer. Additionally the AS4
 * HTTP debugging is invoked in here.<br>
 * This method does NOT retry
 *
 * @param <T>
 *        Response data type
 * @param sURL
 *        The URL to send to. May neither be <code>null</code> nor empty.
 * @param aCustomHttpHeaders
 *        An optional http header map that should be applied. May be
 *        <code>null</code>.
 * @param aHttpEntity
 *        The HTTP entity to be send. May not be <code>null</code>.
 * @param aResponseHandler
 *        The Http response handler that should be used to convert the HTTP
 *        response to a domain object.
 * @return The HTTP response. May be <code>null</code>.
 * @throws IOException
 *         In case of IO error
 */
@Nullable
public <T> T sendGenericMessage(@Nonnull @Nonempty final String sURL, @Nullable final HttpHeaderMap aCustomHttpHeaders, @Nonnull final HttpEntity aHttpEntity, @Nonnull final ResponseHandler<? extends T> aResponseHandler) throws IOException {
    ValueEnforcer.notEmpty(sURL, "URL");
    ValueEnforcer.notNull(aHttpEntity, "HttpEntity");
    final StopWatch aSW = StopWatch.createdStarted();
    if (LOGGER.isInfoEnabled())
        LOGGER.info("Starting to transmit AS4 Message to '" + sURL + "'");
    IOException aCaughtException = null;
    try (final HttpClientManager aClientMgr = new HttpClientManager(m_aHttpClientFactory)) {
        final HttpPost aPost = new HttpPost(sURL);
        if (aCustomHttpHeaders != null) {
            // Always unify line endings
            // By default quoting is disabled
            aCustomHttpHeaders.forEachSingleHeader(aPost::addHeader, true, m_bQuoteHttpHeaders);
        }
        aPost.setEntity(aHttpEntity);
        // Invoke optional customizer
        if (m_aHttpCustomizer != null)
            m_aHttpCustomizer.accept(aPost);
        // Debug sending
        AS4HttpDebug.debug(() -> {
            final StringBuilder ret = new StringBuilder("SEND-START to ").append(sURL).append("\n");
            try {
                for (final Header aHeader : aPost.getAllHeaders()) ret.append(aHeader.getName()).append(": ").append(aHeader.getValue()).append(CHttp.EOL);
                ret.append(CHttp.EOL);
                if (aHttpEntity.isRepeatable())
                    ret.append(EntityUtils.toString(aHttpEntity));
                else
                    ret.append("## The payload is marked as 'not repeatable' and is the therefore not printed in debugging");
            } catch (final Exception ex) {
                ret.append("## Exception listing payload: " + ex.getClass().getName() + " -- " + ex.getMessage()).append(CHttp.EOL);
                ret.append("## ").append(StackTraceHelper.getStackAsString(ex));
            }
            return ret.toString();
        });
        return aClientMgr.execute(aPost, aResponseHandler);
    } catch (final IOException ex) {
        aCaughtException = ex;
        throw ex;
    } finally {
        aSW.stop();
        if (LOGGER.isInfoEnabled())
            LOGGER.info((aCaughtException != null ? "Failed" : "Finished") + " transmitting AS4 Message to '" + sURL + "' after " + aSW.getMillis() + " ms");
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) HttpClientManager(com.helger.httpclient.HttpClientManager) Header(org.apache.http.Header) IOException(java.io.IOException) IOException(java.io.IOException) StopWatch(com.helger.commons.timing.StopWatch) Nullable(javax.annotation.Nullable)

Aggregations

StopWatch (com.helger.commons.timing.StopWatch)29 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)7 Response (javax.ws.rs.core.Response)7 MockHttpServletRequest (com.helger.servlet.mock.MockHttpServletRequest)6 WebScoped (com.helger.web.scope.mgr.WebScoped)6 AS2Exception (com.helger.as2lib.exception.AS2Exception)5 IJsonObject (com.helger.json.IJsonObject)5 PeppolParticipantIdentifier (com.helger.peppolid.peppol.participant.PeppolParticipantIdentifier)4 SMPServerRESTTestRule (com.helger.phoss.smp.mock.SMPServerRESTTestRule)4 EndpointType (com.helger.xsds.peppol.smp1.EndpointType)4 IOException (java.io.IOException)4 Nonnull (javax.annotation.Nonnull)4 WrappedAS2Exception (com.helger.as2lib.exception.WrappedAS2Exception)3 AS2Message (com.helger.as2lib.message.AS2Message)3 AS2NoModuleException (com.helger.as2lib.processor.AS2NoModuleException)3 HttpClientManager (com.helger.httpclient.HttpClientManager)3 ResponseHandlerByteArray (com.helger.httpclient.response.ResponseHandlerByteArray)3 JsonWriter (com.helger.json.serialize.JsonWriter)3 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)3 SMPBadRequestException (com.helger.phoss.smp.exception.SMPBadRequestException)3