-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide a default page for GreenMail WAR (issue #106)
Enhanced webapp for JAX-RS GreenMail API resource with initial support for getting current configuration. Added OpenAPI spec for API, and visualization / test UI by GreenMail API OpenAPI spec.
- Loading branch information
Showing
15 changed files
with
502 additions
and
53 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
greenmail-webapp/src/main/java/com/icegreen/greenmail/webapp/ConfigurationResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.icegreen.greenmail.webapp; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.Context; | ||
|
||
/** | ||
* JAX-RS 2.0 | ||
*/ | ||
@Path("/configuration") | ||
public class ConfigurationResource { | ||
private @Context | ||
ServletContext context; | ||
|
||
@GET | ||
@Produces("application/json") | ||
public Configuration configuration() { | ||
return ContextHelper.getConfiguration(context); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
greenmail-webapp/src/main/java/com/icegreen/greenmail/webapp/ContextHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.icegreen.greenmail.webapp; | ||
|
||
import javax.servlet.ServletContext; | ||
|
||
import com.icegreen.greenmail.Managers; | ||
|
||
/** | ||
* Helps accessing servlet context attributes. | ||
*/ | ||
public class ContextHelper { | ||
static final String ATTRIBUTE_NAME_MANAGERS = "greenmail_managers"; | ||
static final String ATTRIBUTE_NAME_CONFIGURATION = "greenmail_configuration"; | ||
|
||
private ContextHelper() { | ||
// Nothing | ||
} | ||
|
||
public static void initAttributes(ServletContext ctx, Managers managers, Configuration configuration) { | ||
ctx.setAttribute(ATTRIBUTE_NAME_MANAGERS, managers); | ||
ctx.setAttribute(ATTRIBUTE_NAME_CONFIGURATION, configuration); | ||
} | ||
|
||
public static Managers getManagers(ServletContext ctx) { | ||
return (Managers) ctx.getAttribute(ATTRIBUTE_NAME_MANAGERS); | ||
} | ||
|
||
public static Configuration getConfiguration(ServletContext ctx) { | ||
return (Configuration) ctx.getAttribute(ATTRIBUTE_NAME_CONFIGURATION); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...nmail-webapp/src/main/java/com/icegreen/greenmail/webapp/JacksonObjectMapperProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.icegreen.greenmail.webapp; | ||
|
||
import javax.ws.rs.ext.ContextResolver; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import static com.fasterxml.jackson.databind.SerializationFeature.FAIL_ON_EMPTY_BEANS; | ||
|
||
/** | ||
* | ||
*/ | ||
@Provider | ||
public class JacksonObjectMapperProvider implements ContextResolver<ObjectMapper> { | ||
|
||
final ObjectMapper defaultObjectMapper; | ||
|
||
public JacksonObjectMapperProvider() { | ||
defaultObjectMapper = createDefaultMapper(); | ||
} | ||
|
||
@Override | ||
public ObjectMapper getContext(Class<?> type) { | ||
return defaultObjectMapper; | ||
} | ||
|
||
|
||
private static ObjectMapper createDefaultMapper() { | ||
final ObjectMapper result = new ObjectMapper(); | ||
result.configure(FAIL_ON_EMPTY_BEANS, false); | ||
|
||
return result; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" | ||
<web-app xmlns="http://java.sun.com/xml/ns/javaee" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" | ||
version="2.4"> | ||
|
||
<context-param> | ||
<param-name>greenmail.portOffset</param-name> | ||
<param-value>10000</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.smtp.host</param-name> | ||
<param-value>127.0.0.1</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.smtp.port</param-name> | ||
<param-value>10025</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.pop3.host</param-name> | ||
<param-value>127.0.0.1</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.pop3.port</param-name> | ||
<param-value>10110</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.users</param-name> | ||
<param-value> | ||
user1:password@localhost | ||
user2:password2@localhost | ||
</param-value> | ||
</context-param> | ||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" | ||
version="3.0"> | ||
|
||
<context-param> | ||
<param-name>greenmail.portOffset</param-name> | ||
<param-value>10000</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.smtp.host</param-name> | ||
<param-value>127.0.0.1</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.smtp.port</param-name> | ||
<param-value>10025</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.pop3.host</param-name> | ||
<param-value>127.0.0.1</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.pop3.port</param-name> | ||
<param-value>10110</param-value> | ||
</context-param> | ||
<context-param> | ||
<param-name>greenmail.users</param-name> | ||
<param-value> | ||
user1:password@localhost | ||
user2:password2@localhost | ||
</param-value> | ||
</context-param> | ||
|
||
<listener> | ||
<description>GreenMail Server Startup Listener</description> | ||
<listener-class>com.icegreen.greenmail.webapp.GreenMailListener</listener-class> | ||
</listener> | ||
|
||
<servlet> | ||
<servlet-name>Jersey</servlet-name> | ||
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> | ||
<init-param> | ||
<param-name>jersey.config.server.provider.packages</param-name> | ||
<param-value>com.icegreen.greenmail.webapp</param-value> | ||
</init-param> | ||
<load-on-startup>0</load-on-startup> | ||
</servlet> | ||
<servlet-mapping> | ||
<servlet-name>Jersey</servlet-name> | ||
<url-pattern>/api/*</url-pattern> | ||
</servlet-mapping> | ||
|
||
|
||
|
||
<listener> | ||
<description>GreenMail Server Startup Listener</description> | ||
<listener-class>com.icegreen.greenmail.webapp.GreenMailListener</listener-class> | ||
</listener> | ||
<welcome-file-list> | ||
<welcome-file>index.html</welcome-file> | ||
</welcome-file-list> | ||
</web-app> |
Oops, something went wrong.