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

AS2 Client - https #53

Closed
cairnechan opened this issue Aug 7, 2018 · 15 comments
Closed

AS2 Client - https #53

cairnechan opened this issue Aug 7, 2018 · 15 comments
Assignees
Labels

Comments

@cairnechan
Copy link

I see as2 client support https but cannot find any api, please advise any example thanks

v2.2.8 - 2016-05-09
Improved AS2 client https customization and API

@phax phax self-assigned this Aug 7, 2018
@phax phax added the question label Aug 7, 2018
@phax
Copy link
Owner

phax commented Aug 7, 2018

Version 2.2.8 was a long time ago :)
You are right, there are no explicit APIs for this.
This was a fix #20 where you are allowed to overload some stuff in the AbstractHttpSenderModule (namely createSSLContext () and createHostnameVerifier ()). That ,means you can create a sublcass of AS2SenderModule where you overload these methods, and than invoke as2Client.setAS2SenderModuleFactory (MyAS2SenderModule::new); to set the new factory.
hth

@cairnechan
Copy link
Author

@phax thanks, what's more, may I ask how to add https(ssl_protocol, ssl_keystore, ssl_keystore_password) on AS2ReceiverModule

@phax
Copy link
Owner

phax commented Aug 7, 2018

I don't fully understand your request.
You need a server-like component to request something - e.g. the standalone as2-server or an application server based solution using e.g. as2-servlet. The configuration on how to receive something via https depends on what you are using to receive something.
With the AS2Client directly, you can only get synchronous MDNs back. Asnychronous MDNs must be handled externally and cannot be dealt with by AS2Client.
hth

@cairnechan
Copy link
Author

@phax yes, I configure AS2ReceiverModule in standalone as2-server which can successfully handle as2(http) request. For https, I add these attributes(ssl_protocol, ssl_keystore, ssl_keystore_password) on AS2ReceiverModule but it does not works with as2(https)

@phax
Copy link
Owner

phax commented Aug 8, 2018

I must admit I have no idea.
I'm using https only on Tomcat, by adding an httpd in front, to perform the SSL handshake. I have no experience on how to perform this "standalone" :(

Closed by accident

@phax phax closed this as completed Aug 8, 2018
@phax phax reopened this Aug 8, 2018
@cairnechan
Copy link
Author

@phax I enable https service by using tomcat embed in spring-boot. But now I have trouble reusing AS2ReceiverHandler since it use socket io(I can retrieve ServletRequest and ServletResponse from sprint-boot controller). Could you please adivse, thanks

@phax
Copy link
Owner

phax commented Aug 9, 2018

Well okay, here are some questions:
a) are you using as2-servlet or are you using the as2-server?
b) Did you have a look at how this can be configured in Tomcat: (e.g. https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html for Tomcat 7)?

@cairnechan
Copy link
Author

cairnechan commented Aug 10, 2018

I use as2-server at the beginning, find it was using socket io. Shall I turn to as2-servlet?
Because I am using spring-boot, which contain a tomcat server inside and simplify the configuration, I follow this configuration to enable https (step2 https://drissamri.be/blog/java/enable-https-in-spring-boot ), it looks like

server.port=8443
server.ssl.key-store=keystore/client-certs.p12
server.ssl.key-store-password=mypassword
server.ssl.keyStoreType=PKCS12
server.ssl.keyAlias=fwks

@phax
Copy link
Owner

phax commented Aug 10, 2018

Yes, please switch to the as2-servlet. Spring boot obviously embedds Tomcat, and Tomcat can (to my knowledge) only handle Servlets.
If you can provide a wrapper around the as2-demo-webapp I'm also happy to publish it here....

@cairnechan
Copy link
Author

I turn to as2-servlet now, and regist AS2ReceiveServlet into spring-boot in this way

@Configuration
public class ServletConfiguration {

	@Bean
	public ServletRegistrationBean AS2ReceiveServlet() {
		ServletRegistrationBean register = new ServletRegistrationBean(new AS2ReceiveServlet(), "/as2");
		register.addInitParameter("as2-servlet-config-filename", "config/config.xml");
		return register;
	}
	
}

However it fail to initialze this servlet, and throw the following exception

......
Caused by: java.lang.IllegalStateException: No global scope object has been set!
	at com.helger.scope.mgr.ScopeManager.getGlobalScope(ScopeManager.java:158)
	at com.helger.scope.singleton.AbstractGlobalSingleton._getStaticScope(AbstractGlobalSingleton.java:48)
	at com.helger.scope.singleton.AbstractGlobalSingleton.getGlobalSingleton(AbstractGlobalSingleton.java:65)
	at com.helger.xservlet.servletstatus.ServletStatusManager.getInstance(ServletStatusManager.java:67)
	at com.helger.xservlet.AbstractXServlet.<init>(AbstractXServlet.java:182)
	at com.helger.as2servlet.AS2ReceiveServlet.<init>(AS2ReceiveServlet.java:32)

Could you please advise

@phax
Copy link
Owner

phax commented Aug 10, 2018

You need an additional bean that requires the ServletContext.
Upon creation, you need to call:

WebScopeManager.onGlobalBegin (ServletContext);

and for shutdown you need to invoke:

WebScopeManager.onGlobalEnd ();

hth

@cairnechan
Copy link
Author

it works now, many thanks

	@Bean
	public ServletRegistrationBean AS2ReceiveServlet(ServletContext servletContext) {
		WebScopeManager.onGlobalBegin(servletContext);
		ServletRegistrationBean register = new ServletRegistrationBean(new AS2ReceiveServlet(), "/as2");
		register.addInitParameter("as2-servlet-config-filename", "config/config.xml");
		return register;
	}

@phax phax closed this as completed Aug 13, 2018
@kalkrishnan
Copy link

I did this but when I register the AS2WebAppListener, it also tries to set the global scope and throws an exception that global scope has already been set

@phax
Copy link
Owner

phax commented May 6, 2020

@kalkrishnan This is preferrably used in the WebAppListener - remove it from the servlet than

@kalkrishnan
Copy link

WHen I removed it from the servlet, it again gave me an error of no global scope. I ended up keeping it in my servlet and defining my own listener which doesnt define a global scope and that worked.

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

No branches or pull requests

3 participants