Search in sources :

Example 1 with EndpointType

use of com.helger.xsds.peppol.smp1.EndpointType in project phoss-smp by phax.

the class ServiceMetadataInterfaceTest method testCreateAndDeleteServiceInformationSMPClient.

@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
    // Lower case
    final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:xxx");
    // Upper case
    final IParticipantIdentifier aPI_UC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:XXX");
    final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
    final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
    final ServiceGroupType aSG = new ServiceGroupType();
    aSG.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    aSG.setServiceMetadataReferenceCollection(new ServiceMetadataReferenceCollectionType());
    final ServiceInformationType aSI = new ServiceInformationType();
    aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
    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);
    }
    final ISMPServiceGroupManager aSGMgr = SMPMetaManager.getServiceGroupMgr();
    final ISMPServiceInformationManager aSIMgr = SMPMetaManager.getServiceInformationMgr();
    final SMPClient aSMPClient = new MockSMPClient();
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
    assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
    assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
    assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    try {
        // PUT ServiceGroup
        aSMPClient.saveServiceGroup(aSG, CREDENTIALS);
        // Read both
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNotNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertTrue(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
        final ISMPServiceGroup aServiceGroup = aSGMgr.getSMPServiceGroupOfID(aPI_LC);
        assertNotNull(aServiceGroup);
        final ISMPServiceGroup aServiceGroup_UC = aSGMgr.getSMPServiceGroupOfID(aPI_UC);
        assertEquals(aServiceGroup, aServiceGroup_UC);
        try {
            // PUT 1 ServiceInformation
            aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
            assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
            // PUT 2 ServiceInformation
            aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
            assertNotNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
            // DELETE 1 ServiceInformation
            aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
            assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        } finally {
            // DELETE 2 ServiceInformation
            try {
                aSMPClient.deleteServiceRegistration(aPI_LC, aDT, CREDENTIALS);
            } catch (final SMPClientNotFoundException ex) {
            // Expected
            }
            assertNull(aSIMgr.getSMPServiceInformationOfServiceGroupAndDocumentType(aServiceGroup, aDT));
        }
        assertNotNull(aSMPClient.getServiceGroup(aPI_LC));
    } finally {
        // DELETE ServiceGroup
        try {
            aSMPClient.deleteServiceGroup(aPI_LC, CREDENTIALS);
        } catch (final SMPClientNotFoundException ex) {
        // Expected
        }
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_LC));
        assertNull(aSMPClient.getServiceGroupOrNull(aPI_UC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_LC));
        assertFalse(aSGMgr.containsSMPServiceGroupWithID(aPI_UC));
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ServiceMetadataReferenceCollectionType(com.helger.xsds.peppol.smp1.ServiceMetadataReferenceCollectionType) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) PeppolProcessIdentifier(com.helger.peppolid.peppol.process.PeppolProcessIdentifier) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClientNotFoundException(com.helger.smpclient.exception.SMPClientNotFoundException) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) SMPClient(com.helger.smpclient.peppol.SMPClient) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) PeppolDocumentTypeIdentifier(com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceGroupType(com.helger.xsds.peppol.smp1.ServiceGroupType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 2 with EndpointType

use of com.helger.xsds.peppol.smp1.EndpointType in project phoss-smp by phax.

the class ServiceMetadataInterfaceFillDBTest method testCreateAndDeleteServiceInformationSMPClient.

@Test
public void testCreateAndDeleteServiceInformationSMPClient() throws SMPClientException {
    final SMPClient aSMPClient = new MockSMPClient();
    final StopWatch aSW = StopWatch.createdStarted();
    int nEndpoints = 0;
    try (final WebScoped aWS = new WebScoped(new MockHttpServletRequest())) {
        final int nCount = 2_000;
        for (int i = 0; i < nCount; ++i) {
            final IParticipantIdentifier aPI_LC = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme(PID_PREFIX_9999_PHOSS + StringHelper.getLeadingZero(i, 4));
            final PeppolDocumentTypeIdentifier aDT = EPredefinedDocumentTypeIdentifier.INVOICE_EN16931_PEPPOL_V30.getAsDocumentTypeIdentifier();
            final PeppolProcessIdentifier aProcID = EPredefinedProcessIdentifier.BIS3_BILLING.getAsProcessIdentifier();
            for (final ESMPTransportProfile eTP : new ESMPTransportProfile[] { ESMPTransportProfile.TRANSPORT_PROFILE_AS2, ESMPTransportProfile.TRANSPORT_PROFILE_PEPPOL_AS4_V2 }) {
                final ServiceInformationType aSI = new ServiceInformationType();
                aSI.setParticipantIdentifier(new SimpleParticipantIdentifier(aPI_LC));
                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/" + eTP.getID()));
                    aEndpoint.setRequireBusinessLevelSignature(false);
                    aEndpoint.setCertificate("blacert");
                    aEndpoint.setServiceDescription("Unit test service");
                    aEndpoint.setTechnicalContactUrl("https://github.com/phax/phoss-smp");
                    aEndpoint.setTransportProfile(eTP.getID());
                    aSEL.addEndpoint(aEndpoint);
                    aProcess.setServiceEndpointList(aSEL);
                    aPL.addProcess(aProcess);
                    aSI.setProcessList(aPL);
                }
                aSMPClient.saveServiceInformation(aSI, CREDENTIALS);
                ++nEndpoints;
            }
        }
    }
    aSW.stop();
    LOGGER.info("Created " + nEndpoints + " ServiceInformation in " + aSW.getDuration() + " (= " + (aSW.getMillis() / nEndpoints) + " ms/entry)");
}
Also used : WebScoped(com.helger.web.scope.mgr.WebScoped) MockHttpServletRequest(com.helger.servlet.mock.MockHttpServletRequest) ESMPTransportProfile(com.helger.peppol.smp.ESMPTransportProfile) PeppolProcessIdentifier(com.helger.peppolid.peppol.process.PeppolProcessIdentifier) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) SimpleParticipantIdentifier(com.helger.peppolid.simple.participant.SimpleParticipantIdentifier) StopWatch(com.helger.commons.timing.StopWatch) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) MockSMPClient(com.helger.phoss.smp.mock.MockSMPClient) SMPClient(com.helger.smpclient.peppol.SMPClient) PeppolDocumentTypeIdentifier(com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) ServiceEndpointList(com.helger.xsds.peppol.smp1.ServiceEndpointList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Example 3 with EndpointType

use of com.helger.xsds.peppol.smp1.EndpointType 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 4 with EndpointType

use of com.helger.xsds.peppol.smp1.EndpointType in project phase4 by phax.

the class Phase4PeppolServletMessageProcessorSPI method processAS4UserMessage.

@Nonnull
public AS4MessageProcessorResult processAS4UserMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IPMode aSrcPMode, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
    if (LOGGER.isDebugEnabled())
        LOGGER.debug("Invoking processAS4UserMessage");
    final String sMessageID = aUserMessage.getMessageInfo().getMessageId();
    final String sService = aUserMessage.getCollaborationInfo().getServiceValue();
    final String sAction = aUserMessage.getCollaborationInfo().getAction();
    final String sConversationID = aUserMessage.getCollaborationInfo().getConversationId();
    final String sLogPrefix = "[" + sMessageID + "] ";
    final Locale aDisplayLocale = aState.getLocale();
    // Debug log
    if (LOGGER.isDebugEnabled()) {
        if (aSrcPMode == null)
            LOGGER.debug(sLogPrefix + "  No Source PMode present");
        else
            LOGGER.debug(sLogPrefix + "  Source PMode = " + aSrcPMode.getID());
        LOGGER.debug(sLogPrefix + "  AS4 Message ID = '" + sMessageID + "'");
        LOGGER.debug(sLogPrefix + "  AS4 Service = '" + sService + "'");
        LOGGER.debug(sLogPrefix + "  AS4 Action = '" + sAction + "'");
        LOGGER.debug(sLogPrefix + "  AS4 ConversationId = '" + sConversationID + "'");
        // Log source properties
        if (aUserMessage.getMessageProperties() != null && aUserMessage.getMessageProperties().hasPropertyEntries()) {
            LOGGER.debug(sLogPrefix + "  AS4 MessageProperties:");
            for (final Ebms3Property p : aUserMessage.getMessageProperties().getProperty()) LOGGER.debug(sLogPrefix + "    [" + p.getName() + "] = [" + p.getValue() + "]");
        } else
            LOGGER.debug(sLogPrefix + "  No AS4 Mesage Properties present");
        if (aPayload == null)
            LOGGER.debug(sLogPrefix + "  No SOAP Body Payload present");
        else
            LOGGER.debug(sLogPrefix + "  SOAP Body Payload = " + XMLWriter.getNodeAsString(aPayload));
    }
    // Read all attachments
    final ICommonsList<ReadAttachment> aReadAttachments = new CommonsArrayList<>();
    if (aIncomingAttachments != null) {
        int nAttachmentIndex = 0;
        for (final IAS4Attachment aIncomingAttachment : aIncomingAttachments) {
            final ReadAttachment a = new ReadAttachment();
            a.m_sID = aIncomingAttachment.getId();
            a.m_sMimeType = aIncomingAttachment.getMimeType();
            a.m_sUncompressedMimeType = aIncomingAttachment.getUncompressedMimeType();
            a.m_aCharset = aIncomingAttachment.getCharset();
            a.m_eCompressionMode = aIncomingAttachment.getCompressionMode();
            try (final InputStream aSIS = aIncomingAttachment.getSourceStream()) {
                final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream();
                if (StreamHelper.copyInputStreamToOutputStreamAndCloseOS(aSIS, aBAOS).isSuccess()) {
                    a.m_aPayloadBytes = aBAOS.getBufferOrCopy();
                }
            } catch (final IOException | AS4DecompressException ex) {
            // Fall through
            }
            if (a.m_aPayloadBytes == null) {
                LOGGER.error(sLogPrefix + "Failed to decompress the payload");
                aProcessingErrorMessages.add(EEbmsError.EBMS_DECOMPRESSION_FAILURE.getAsEbms3Error(aDisplayLocale, aState.getMessageID()));
                return AS4MessageProcessorResult.createFailure(null);
            }
            // Read data as SBDH
            // Hint for production systems: this may take a huge amount of memory,
            // if the payload is large
            final ErrorList aSBDHErrors = new ErrorList();
            a.m_aSBDH = SBDHReader.standardBusinessDocument().setValidationEventHandler(new WrappedCollectingValidationEventHandler(aSBDHErrors)).read(a.m_aPayloadBytes);
            if (a.m_aSBDH == null) {
                if (aSBDHErrors.isEmpty()) {
                    final String sMsg = "Failed to read the provided SBDH document";
                    LOGGER.error(sLogPrefix + sMsg);
                    aProcessingErrorMessages.add(EEbmsError.EBMS_OTHER.getAsEbms3Error(aDisplayLocale, aState.getMessageID(), sMsg));
                } else {
                    for (final IError aError : aSBDHErrors) {
                        final String sMsg = "Peppol SBDH Issue: " + aError.getAsString(aDisplayLocale);
                        LOGGER.error(sLogPrefix + sMsg);
                        aProcessingErrorMessages.add(EEbmsError.EBMS_OTHER.getAsEbms3Error(aDisplayLocale, aState.getMessageID(), sMsg));
                    }
                }
                return AS4MessageProcessorResult.createFailure(null);
            }
            aReadAttachments.add(a);
            if (LOGGER.isDebugEnabled())
                LOGGER.debug(sLogPrefix + "AS4 Attachment " + nAttachmentIndex + " with ID [" + a.m_sID + "] uses [" + a.m_sMimeType + (a.m_sUncompressedMimeType == null ? null : " - uncompressed " + a.m_sUncompressedMimeType) + "] and [" + StringHelper.getToString(a.m_aCharset, "no charset") + "] and length is " + (a.m_aPayloadBytes == null ? "<error>" : Integer.toString(a.m_aPayloadBytes.length)) + " bytes" + (a.m_eCompressionMode == null ? "" : " of compressed payload"));
            nAttachmentIndex++;
        }
    }
    if (aReadAttachments.size() != 1) {
        // In Peppol there must be exactly one payload
        final String sMsg = "In Peppol exactly one payload attachment is expected. This request has " + aReadAttachments.size() + " attachments";
        LOGGER.error(sLogPrefix + sMsg);
        return AS4MessageProcessorResult.createFailure(sMsg);
    }
    // The one and only
    final ReadAttachment aReadAttachment = aReadAttachments.getFirst();
    // Extract Peppol values from SBD
    final PeppolSBDHDocument aPeppolSBD;
    try {
        if (LOGGER.isDebugEnabled())
            LOGGER.debug(sLogPrefix + "Now evaluating the SBDH against Peppol rules");
        final boolean bPerformValueChecks = Phase4PeppolServletConfiguration.isPerformSBDHValueChecks();
        aPeppolSBD = new PeppolSBDHDocumentReader(SimpleIdentifierFactory.INSTANCE).setPerformValueChecks(bPerformValueChecks).extractData(aReadAttachment.standardBusinessDocument());
        if (LOGGER.isDebugEnabled())
            LOGGER.debug(sLogPrefix + "The provided SBDH is valid according to Peppol rules, with value checks being " + (bPerformValueChecks ? "enabled" : "disabled"));
    } catch (final PeppolSBDHDocumentReadException ex) {
        final String sMsg = "Failed to extract the Peppol data from SBDH. Technical details: " + ex.getClass().getName() + " - " + ex.getMessage();
        LOGGER.error(sLogPrefix + sMsg);
        return AS4MessageProcessorResult.createFailure(sMsg);
    }
    if (m_aHandlers.isEmpty()) {
        LOGGER.error(sLogPrefix + "No SPI handler is present - the message is unhandled and discarded");
    } else {
        // Start consistency checks?
        final Phase4PeppolReceiverCheckData aReceiverCheckData = m_aReceiverCheckData != null ? m_aReceiverCheckData : Phase4PeppolServletConfiguration.getAsReceiverCheckData();
        if (aReceiverCheckData != null) {
            if (LOGGER.isDebugEnabled())
                LOGGER.debug("Performing check if the provided data is registered in our SMP");
            try {
                // Get the endpoint information required from the recipient
                // Check if an endpoint is registered
                final IParticipantIdentifier aReceiverID = aPeppolSBD.getReceiverAsIdentifier();
                final IDocumentTypeIdentifier aDocTypeID = aPeppolSBD.getDocumentTypeAsIdentifier();
                final IProcessIdentifier aProcessID = aPeppolSBD.getProcessAsIdentifier();
                final EndpointType aReceiverEndpoint = _getReceiverEndpoint(sLogPrefix, aReceiverCheckData.getSMPClient(), aReceiverID, aDocTypeID, aProcessID);
                if (aReceiverEndpoint == null) {
                    final String sMsg = "Failed to resolve SMP endpoint for provided receiver ID (" + (aReceiverID == null ? "null" : aReceiverID.getURIEncoded()) + ")/documentType ID (" + (aDocTypeID == null ? "null" : aDocTypeID.getURIEncoded()) + ")/process ID (" + (aProcessID == null ? "null" : aProcessID.getURIEncoded()) + ")/transport profile (" + m_aTransportProfile.getID() + ") - not handling incoming AS4 document";
                    LOGGER.error(sLogPrefix + sMsg);
                    return AS4MessageProcessorResult.createFailure(sMsg);
                }
                // Check if the message is for us
                _checkIfReceiverEndpointURLMatches(sLogPrefix, aReceiverCheckData.getAS4EndpointURL(), aReceiverEndpoint);
                // Get the recipient certificate from the SMP
                _checkIfEndpointCertificateMatches(sLogPrefix, aReceiverCheckData.getAPCertificate(), aReceiverEndpoint);
            } catch (final Phase4Exception ex) {
                final String sMsg = "The addressing data contained in the SBDH could not be verified. Technical details: " + ex.getClass().getName() + " - " + ex.getMessage();
                LOGGER.error(sLogPrefix + sMsg);
                return AS4MessageProcessorResult.createFailure(sMsg);
            }
        } else {
            LOGGER.info(sLogPrefix + "Endpoint checks for incoming AS4 messages are disabled");
        }
        for (final IPhase4PeppolIncomingSBDHandlerSPI aHandler : m_aHandlers) {
            try {
                if (LOGGER.isDebugEnabled())
                    LOGGER.debug(sLogPrefix + "Invoking Peppol handler " + aHandler);
                aHandler.handleIncomingSBD(aMessageMetadata, aHttpHeaders.getClone(), aUserMessage.clone(), aReadAttachment.payloadBytes(), aReadAttachment.standardBusinessDocument(), aPeppolSBD, aState);
            } catch (final Exception ex) {
                LOGGER.error(sLogPrefix + "Error invoking Peppol handler " + aHandler, ex);
                if (aHandler.exceptionTranslatesToAS4Error()) {
                    final String sMsg = "The incoming Peppol message could not be processed. Technical details: " + ex.getClass().getName() + " - " + ex.getMessage();
                    LOGGER.error(sLogPrefix + sMsg);
                    return AS4MessageProcessorResult.createFailure(sMsg);
                }
            }
        }
    }
    return AS4MessageProcessorResult.createSuccess();
}
Also used : Locale(java.util.Locale) AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) IAS4Attachment(com.helger.phase4.attachment.IAS4Attachment) WrappedCollectingValidationEventHandler(com.helger.jaxb.validation.WrappedCollectingValidationEventHandler) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) IProcessIdentifier(com.helger.peppolid.IProcessIdentifier) Phase4Exception(com.helger.phase4.util.Phase4Exception) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) PeppolSBDHDocumentReadException(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReadException) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) InputStream(java.io.InputStream) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) PeppolSBDHDocumentReader(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader) IOException(java.io.IOException) IError(com.helger.commons.error.IError) AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) PeppolSBDHDocumentReadException(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReadException) Phase4Exception(com.helger.phase4.util.Phase4Exception) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ErrorList(com.helger.commons.error.list.ErrorList) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Nonnull(javax.annotation.Nonnull)

Example 5 with EndpointType

use of com.helger.xsds.peppol.smp1.EndpointType in project phoss-smp by phax.

the class SMPServerAPI method saveServiceRegistration.

@Nonnull
public ESuccess saveServiceRegistration(@Nonnull final String sPathServiceGroupID, @Nonnull final String sPathDocumentTypeID, @Nonnull final ServiceMetadataType aServiceMetadata, @Nonnull final BasicAuthClientCredentials aCredentials) throws SMPServerException {
    final String sLog = LOG_PREFIX + "PUT /" + sPathServiceGroupID + "/services/" + sPathDocumentTypeID;
    final String sAction = "saveServiceRegistration";
    if (LOGGER.isInfoEnabled())
        LOGGER.info(sLog + " ==> " + aServiceMetadata);
    STATS_COUNTER_INVOCATION.increment(sAction);
    try {
        // Parse provided identifiers
        final IIdentifierFactory aIdentifierFactory = SMPMetaManager.getIdentifierFactory();
        final IParticipantIdentifier aPathServiceGroupID = aIdentifierFactory.parseParticipantIdentifier(sPathServiceGroupID);
        if (aPathServiceGroupID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseSG(sPathServiceGroupID, m_aAPIDataProvider.getCurrentURI());
        }
        final IDocumentTypeIdentifier aPathDocTypeID = aIdentifierFactory.parseDocumentTypeIdentifier(sPathDocumentTypeID);
        if (aPathDocTypeID == null) {
            // Invalid identifier
            throw SMPBadRequestException.failedToParseDocType(sPathDocumentTypeID, m_aAPIDataProvider.getCurrentURI());
        }
        // May be null for a Redirect!
        final ServiceInformationType aServiceInformation = aServiceMetadata.getServiceInformation();
        if (aServiceInformation != null) {
            // metadata (body) must equal path
            if (aServiceInformation.getParticipantIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata has inconsistent values.\n" + "Service Information Participant ID: <none>\n" + "URL Parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IParticipantIdentifier aPayloadServiceGroupID;
            if (aServiceInformation.getParticipantIdentifier() == null) {
                // Can happen when tampering with the input data
                aPayloadServiceGroupID = null;
            } else {
                aPayloadServiceGroupID = aIdentifierFactory.createParticipantIdentifier(aServiceInformation.getParticipantIdentifier().getScheme(), aServiceInformation.getParticipantIdentifier().getValue());
            }
            if (!aPathServiceGroupID.hasSameContent(aPayloadServiceGroupID)) {
                // Participant ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Infoformation Participant ID: " + (aPayloadServiceGroupID == null ? "<none>" : "'" + aPayloadServiceGroupID.getURIEncoded() + "'") + "\n" + "URL parameter value: '" + aPathServiceGroupID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            if (aServiceInformation.getDocumentIdentifier() == null) {
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: <none>\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
            final IDocumentTypeIdentifier aPayloadDocTypeID = aIdentifierFactory.createDocumentTypeIdentifier(aServiceInformation.getDocumentIdentifier().getScheme(), aServiceInformation.getDocumentIdentifier().getValue());
            if (!aPathDocTypeID.hasSameContent(aPayloadDocTypeID)) {
                // Document type ID in URL must match the one in XML structure
                throw new SMPBadRequestException("Save Service Metadata was called with inconsistent values.\n" + "Service Information Document Type ID: '" + aPayloadDocTypeID.getURIEncoded() + "'\n" + "URL parameter value: '" + aPathDocTypeID.getURIEncoded() + "'", m_aAPIDataProvider.getCurrentURI());
            }
        }
        // Main save
        final IUser aDataUser = SMPUserManagerPhoton.validateUserCredentials(aCredentials);
        SMPUserManagerPhoton.verifyOwnership(aPathServiceGroupID, aDataUser);
        final ISMPServiceGroupManager aServiceGroupMgr = SMPMetaManager.getServiceGroupMgr();
        final ISMPServiceGroup aPathServiceGroup = aServiceGroupMgr.getSMPServiceGroupOfID(aPathServiceGroupID);
        if (aPathServiceGroup == null) {
            // Service group not found
            throw new SMPNotFoundException("Service Group '" + sPathServiceGroupID + "' is not on this SMP", m_aAPIDataProvider.getCurrentURI());
        }
        if (aServiceMetadata.getRedirect() != null) {
            // Handle redirect
            final ISMPRedirectManager aRedirectMgr = SMPMetaManager.getRedirectMgr();
            // not available in Peppol mode
            final X509Certificate aCertificate = null;
            if (aRedirectMgr.createOrUpdateSMPRedirect(aPathServiceGroup, aPathDocTypeID, aServiceMetadata.getRedirect().getHref(), aServiceMetadata.getRedirect().getCertificateUID(), aCertificate, SMPExtensionConverter.convertToString(aServiceMetadata.getRedirect().getExtension())) == null) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - Redirect");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - Redirect");
        } else if (aServiceInformation != null) {
            // Handle service information
            final ProcessListType aJAXBProcesses = aServiceInformation.getProcessList();
            final ICommonsList<SMPProcess> aProcesses = new CommonsArrayList<>();
            for (final ProcessType aJAXBProcess : aJAXBProcesses.getProcess()) {
                final ICommonsList<SMPEndpoint> aEndpoints = new CommonsArrayList<>();
                for (final EndpointType aJAXBEndpoint : aJAXBProcess.getServiceEndpointList().getEndpoint()) {
                    final SMPEndpoint aEndpoint = new SMPEndpoint(aJAXBEndpoint.getTransportProfile(), W3CEndpointReferenceHelper.getAddress(aJAXBEndpoint.getEndpointReference()), aJAXBEndpoint.isRequireBusinessLevelSignature(), aJAXBEndpoint.getMinimumAuthenticationLevel(), aJAXBEndpoint.getServiceActivationDate(), aJAXBEndpoint.getServiceExpirationDate(), aJAXBEndpoint.getCertificate(), aJAXBEndpoint.getServiceDescription(), aJAXBEndpoint.getTechnicalContactUrl(), aJAXBEndpoint.getTechnicalInformationUrl(), SMPExtensionConverter.convertToString(aJAXBEndpoint.getExtension()));
                    aEndpoints.add(aEndpoint);
                }
                final SMPProcess aProcess = new SMPProcess(SimpleProcessIdentifier.wrap(aJAXBProcess.getProcessIdentifier()), aEndpoints, SMPExtensionConverter.convertToString(aJAXBProcess.getExtension()));
                aProcesses.add(aProcess);
            }
            final ISMPServiceInformationManager aServiceInfoMgr = SMPMetaManager.getServiceInformationMgr();
            final String sExtensionXML = SMPExtensionConverter.convertToString(aServiceInformation.getExtension());
            if (aServiceInfoMgr.mergeSMPServiceInformation(new SMPServiceInformation(aPathServiceGroup, aPathDocTypeID, aProcesses, sExtensionXML)).isFailure()) {
                if (LOGGER.isErrorEnabled())
                    LOGGER.error(sLog + " - ERROR - ServiceInformation");
                STATS_COUNTER_ERROR.increment(sAction);
                return ESuccess.FAILURE;
            }
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS - ServiceInformation");
        } else {
            throw new SMPBadRequestException("Save Service Metadata was called with neither a Redirect nor a ServiceInformation", m_aAPIDataProvider.getCurrentURI());
        }
        if (false)
            if (LOGGER.isInfoEnabled())
                LOGGER.info(sLog + " SUCCESS");
        STATS_COUNTER_SUCCESS.increment(sAction);
        return ESuccess.SUCCESS;
    } catch (final SMPServerException ex) {
        if (LOGGER.isWarnEnabled())
            LOGGER.warn(sLog + " ERROR - " + ex.getMessage());
        STATS_COUNTER_ERROR.increment(sAction);
        throw ex;
    }
}
Also used : ISMPServiceGroupManager(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager) ICommonsList(com.helger.commons.collection.impl.ICommonsList) SMPBadRequestException(com.helger.phoss.smp.exception.SMPBadRequestException) ISMPServiceInformationManager(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager) ISMPServiceGroup(com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup) SMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.SMPServiceInformation) ISMPServiceInformation(com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformation) IDocumentTypeIdentifier(com.helger.peppolid.IDocumentTypeIdentifier) SMPEndpoint(com.helger.phoss.smp.domain.serviceinfo.SMPEndpoint) ServiceInformationType(com.helger.xsds.peppol.smp1.ServiceInformationType) X509Certificate(java.security.cert.X509Certificate) ISMPRedirectManager(com.helger.phoss.smp.domain.redirect.ISMPRedirectManager) SMPProcess(com.helger.phoss.smp.domain.serviceinfo.SMPProcess) SMPNotFoundException(com.helger.phoss.smp.exception.SMPNotFoundException) ProcessType(com.helger.xsds.peppol.smp1.ProcessType) EndpointType(com.helger.xsds.peppol.smp1.EndpointType) IUser(com.helger.photon.security.user.IUser) ProcessListType(com.helger.xsds.peppol.smp1.ProcessListType) IIdentifierFactory(com.helger.peppolid.factory.IIdentifierFactory) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) SMPServerException(com.helger.phoss.smp.exception.SMPServerException) Nonnull(javax.annotation.Nonnull)

Aggregations

EndpointType (com.helger.xsds.peppol.smp1.EndpointType)8 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)6 ProcessListType (com.helger.xsds.peppol.smp1.ProcessListType)6 ProcessType (com.helger.xsds.peppol.smp1.ProcessType)6 ServiceInformationType (com.helger.xsds.peppol.smp1.ServiceInformationType)6 PeppolDocumentTypeIdentifier (com.helger.peppolid.peppol.doctype.PeppolDocumentTypeIdentifier)5 PeppolProcessIdentifier (com.helger.peppolid.peppol.process.PeppolProcessIdentifier)5 SimpleParticipantIdentifier (com.helger.peppolid.simple.participant.SimpleParticipantIdentifier)5 ServiceEndpointList (com.helger.xsds.peppol.smp1.ServiceEndpointList)5 StopWatch (com.helger.commons.timing.StopWatch)4 ISMPServiceGroup (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroup)4 ISMPServiceGroupManager (com.helger.phoss.smp.domain.servicegroup.ISMPServiceGroupManager)4 ISMPServiceInformationManager (com.helger.phoss.smp.domain.serviceinfo.ISMPServiceInformationManager)4 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)3 ServiceMetadataType (com.helger.xsds.peppol.smp1.ServiceMetadataType)3 X509Certificate (java.security.cert.X509Certificate)3 Nonnull (javax.annotation.Nonnull)3 Response (javax.ws.rs.core.Response)3 ICommonsList (com.helger.commons.collection.impl.ICommonsList)2 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)2