user2258662
user2258662

Reputation: 45

how to gzip response in embedded tomcat

how can I do this? I read about compression, but not find anything about doing in embedded tomcat server. I read about Connecter class set the compression on in this website

http://viralpatel.net/blogs/enable-gzip-compression-in-tomcat/

but not in server. I have main method which starts tomcat server.

Upvotes: 2

Views: 597

Answers (1)

Inxsible
Inxsible

Reputation: 720

Anything you can do via XML can (most likely) be done with API calls through Java as well. In this case, if you can get a handle to the Connector object, you could probably set whatever values etc and enable compression.

Have you tried that? It would be something to the effect of

Tomcat server = new Tomcat()
Connector connector = server.getConnector()

Now set whatever values you want in your compression and after you are done, make sure to set the connector object back into the server

server.setConnector(connector)

I think that should be equivalent to the declarative way that's listed in the link you posted.

Upvotes: 2

Related Questions