phax / phase4

phase4 - AS4 client and server for integration into existing systems. Specific support for Peppol and CEF eDelivery built-in.
Apache License 2.0
154 stars 47 forks source link

Multi-Profile handling using Single Servlet different URL #274

Open duke-nuke opened 1 month ago

duke-nuke commented 1 month ago

Discussed in https://github.com/phax/phase4/discussions/273

Originally posted by **duke-nuke** September 17, 2024 Hi Philip Hope you are good, I am working on handling multiple profile in Phase4, i am using Spring-boot project as a starting point for this, followed your guide how to handle multi profile provided in the wiki , but getting errors, I have implemented the Interface using below code. `public class CustomHandler implements AS4XServletHandler.IHandlerCustomizer{ private AS4XServletHandler as4XServletHandler; public CustomHandler(AS4XServletHandler handler) { this.as4XServletHandler = handler; } @Override public void customizeBeforeHandling(@Nonnull IRequestWebScopeWithoutResponse iRequestWebScopeWithoutResponse, @Nonnull AS4UnifiedResponse as4UnifiedResponse, @Nonnull AS4RequestHandler as4RequestHandler) { try { if(iRequestWebScopeWithoutResponse.getRequestURIDecoded().startsWith("/as4")) { //IAS4CryptoFactory var3 = AS4CryptoFactoryProperties.getDefaultInstance(); //AS4CryptoFactoryProperties.createCrypto() AS4CryptoFactoryProperties properties = new AS4CryptoFactoryProperties(AS4CryptoFactoryProperties.readCryptoPropertiesFromFile("cef.properties")); Supplier supplier = () -> properties; this.as4XServletHandler.setCryptoFactorySignSupplier(supplier).setCryptoFactoryCryptSupplier(supplier); //MetaAS4Manager.getProfileMgr(); not sure how to set cef profile as4RequestHandler.handleRequest(iRequestWebScopeWithoutResponse, as4UnifiedResponse ); } else { as4RequestHandler.handleRequest(iRequestWebScopeWithoutResponse, as4UnifiedResponse); } }catch (Exception ex){ throw new RuntimeException(ex); } } } ` Set this in the ServletConfig class ` hdl.setHandlerCustomizer(new CustomHandler(hdl));` but when i am processing cef message i am getting on first request i get Private key not found for key , Look like the first request is picking up the keystore of peppol profile, but the next request i picking the certificate which i am using for cef but then it gives the following error `Caused by: com.helger.phase4.util.Phase4Exception: Error validating incoming AS4 UserMessage with the profile Peppol following errors are present: [PartyInfo/From[0]/@type must be 'urn:fdc:peppol.eu:2017:identifiers:ap' instead of 'urn:oasis:names:tc:ebcore:partyid-type:unregistered', PartyInfo/To[0]/@type must be 'urn:fdc:peppol.eu:2017:identifiers:ap' instead of 'urn:oasis:names:tc:ebcore:partyid-type:unregistered', CollaborationInfo/AgreementRef is missing] ` How can i select the profile based on the incoming message and also in the above custom implementation the values are set per request or for all the requests ? will there be any multi request issues ? if this is working at instace level? Also by doing this will it be possible to switch between two profiles on runtime ? e.g if peppol einvoice is coming it should use peppol profile and if cef einvoice is coming then it should use CEF profile. regards Khurram Shahzad