Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Profile handling using Single Servlet different URL #274

Open
duke-nuke opened this issue Sep 17, 2024 Discussed in #273 · 0 comments
Open

Multi-Profile handling using Single Servlet different URL #274

duke-nuke opened this issue Sep 17, 2024 Discussed in #273 · 0 comments

Comments

@duke-nuke
Copy link

duke-nuke commented Sep 17, 2024

Discussed in #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<IAS4CryptoFactory> 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant