This file contains hidden or 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
/** | |
* A reusable bundle of functionality, used to define blocks of application behavior that are | |
* conditional on configuration parameters. | |
* | |
* @param <T> the required configuration interface | |
*/ | |
public interface ConfiguredBundle<T> { | |
/** | |
* Initializes the environment. | |
* |
This file contains hidden or 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
@Override | |
public void initialize(Bootstrap<MyApiConfiguration> bootstrap) | |
{ | |
bootstrap.addBundle(hibernate); | |
} |
This file contains hidden or 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
@Override | |
public void initialize(Bootstrap<?> bootstrap) | |
{ | |
ObjectMapper mapper = bootstrap.getObjectMapper(); | |
mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); | |
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); | |
} |
This file contains hidden or 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
@Override | |
public void run(MyConfiguration configuration, Environment environment) | |
{ | |
// Enable CORS headers | |
final FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); | |
// Configure CORS parameters | |
cors.setInitParameter("allowedOrigins", configuration.getAllowedOrigin()); | |
cors.setInitParameter("allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin"); | |
cors.setInitParameter("allowedMethods", "OPTIONS,GET,PUT,POST,DELETE,HEAD"); |
This file contains hidden or 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
public class MyConfiguration extends Configuration | |
{ | |
@Valid | |
@NotNull | |
@JsonProperty("allowedOrigin") | |
private String allowedOrigin; | |
public String getAllowedOrigin() | |
{ | |
return allowedOrigin; |