Allow cache-control to be used with CORS

This commit is contained in:
James 2017-10-26 09:08:10 -04:00
parent 15ba0dff03
commit d461567433
7 changed files with 88 additions and 51 deletions

View File

@ -48,18 +48,48 @@ import static org.apache.commons.lang3.StringUtils.trim;
public class JavaMailEmailSender implements IEmailSender {
private static final Logger ourLog = LoggerFactory.getLogger(JavaMailEmailSender.class);
private String mySmtpServerHost;
private String mySmtpServerHostname;
private int mySmtpServerPort = 25;
private JavaMailSenderImpl mySender;
private String mySmtpServerUsername;
private String mySmtpServerPassword;
@PostConstruct
public void start() {
Validate.notBlank(mySmtpServerHost, "No SMTP host defined");
public String getSmtpServerHostname() {
return mySmtpServerHostname;
}
mySender = new JavaMailSenderImpl();
mySender.setHost(mySmtpServerHost);
mySender.setPort(mySmtpServerPort);
mySender.setDefaultEncoding(Constants.CHARSET_UTF8.name());
/**
* Set the SMTP server host to use for outbound mail
*/
public void setSmtpServerHostname(String theSmtpServerHostname) {
mySmtpServerHostname = theSmtpServerHostname;
}
public String getSmtpServerPassword() {
return mySmtpServerPassword;
}
public void setSmtpServerPassword(String theSmtpServerPassword) {
mySmtpServerPassword = theSmtpServerPassword;
}
public int getSmtpServerPort() {
return mySmtpServerPort;
}
/**
* Set the SMTP server port to use for outbound mail
*/
public void setSmtpServerPort(int theSmtpServerPort) {
mySmtpServerPort = theSmtpServerPort;
}
public String getSmtpServerUsername() {
return mySmtpServerUsername;
}
public void setSmtpServerUsername(String theSmtpServerUsername) {
mySmtpServerUsername = theSmtpServerUsername;
}
@Override
@ -102,18 +132,16 @@ public class JavaMailEmailSender implements IEmailSender {
ourLog.info("Done sending email (took {}ms)", sw.getMillis());
}
/**
* Set the SMTP server host to use for outbound mail
*/
public void setSmtpServerHost(String theSmtpServerHost) {
mySmtpServerHost = theSmtpServerHost;
}
@PostConstruct
public void start() {
Validate.notBlank(mySmtpServerHostname, "No SMTP host defined");
/**
* Set the SMTP server port to use for outbound mail
*/
public void setSmtpServerPort(int theSmtpServerPort) {
mySmtpServerPort = theSmtpServerPort;
mySender = new JavaMailSenderImpl();
mySender.setHost(getSmtpServerHostname());
mySender.setPort(getSmtpServerPort());
mySender.setUsername(getSmtpServerUsername());
mySender.setPassword(getSmtpServerPassword());
mySender.setDefaultEncoding(Constants.CHARSET_UTF8.name());
}
private static String toTrimmedCommaSeparatedString(List<String> theTo) {

View File

@ -118,7 +118,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
@Bean
public IEmailSender emailSender() {
JavaMailEmailSender retVal = new JavaMailEmailSender();
retVal.setSmtpServerHost("localhost");
retVal.setSmtpServerHostname("localhost");
retVal.setSmtpServerPort(3025);
return retVal;
}

View File

@ -58,7 +58,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test {
super.before();
JavaMailEmailSender emailSender = new JavaMailEmailSender();
emailSender.setSmtpServerHost("localhost");
emailSender.setSmtpServerHostname("localhost");
emailSender.setSmtpServerPort(3025);
emailSender.start();

View File

@ -174,6 +174,10 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
.setUrl(JpaConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE)
.setValue(new StringType("This is a subject"));
subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless());
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscriptionTemp));
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
waitForQueueToDrain();

View File

@ -4,7 +4,6 @@ import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.GreenMailUtil;
import com.icegreen.greenmail.util.ServerSetup;
import com.icegreen.greenmail.util.ServerSetupTest;
import org.hl7.fhir.dstu3.model.IdType;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -27,8 +26,10 @@ public class JavaMailEmailSenderTest {
@Test
public void testSend() throws Exception {
JavaMailEmailSender sender = new JavaMailEmailSender();
sender.setSmtpServerHost("localhost");
sender.setSmtpServerHostname("localhost");
sender.setSmtpServerPort(ourPort);
sender.setSmtpServerUsername(null);
sender.setSmtpServerPassword(null);
sender.start();
String body = "foo";

View File

@ -181,6 +181,7 @@ public class TestRestfulServer extends RestfulServer {
config.addAllowedHeader("Content-Type");
config.addAllowedHeader("Access-Control-Request-Method");
config.addAllowedHeader("Access-Control-Request-Headers");
config.addAllowedHeader("Cache-Control");
config.addAllowedOrigin("*");
config.addExposedHeader("Location");
config.addExposedHeader("Content-Location");

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
*/
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -61,29 +62,9 @@ public class CorsInterceptor extends InterceptorAdapter {
this(createDefaultCorsConfig());
}
private static CorsConfiguration createDefaultCorsConfig() {
CorsConfiguration retVal = new CorsConfiguration();
// *********************************************************
// Update constructor documentation if you change these:
// *********************************************************
retVal.addAllowedHeader("Origin");
retVal.addAllowedHeader("Accept");
retVal.addAllowedHeader("X-Requested-With");
retVal.addAllowedHeader("Content-Type");
retVal.addAllowedHeader("Access-Control-Request-Method");
retVal.addAllowedHeader("Access-Control-Request-Headers");
retVal.addAllowedOrigin("*");
retVal.addExposedHeader("Location");
retVal.addExposedHeader("Content-Location");
return retVal;
}
/**
* Constructor which accepts the given configuration
*
*
* @param theConfiguration
* The CORS configuration
*/
@ -93,13 +74,6 @@ public class CorsInterceptor extends InterceptorAdapter {
setConfig(theConfiguration);
}
/**
* Sets the CORS configuration
*/
public void setConfig(CorsConfiguration theConfiguration) {
myConfig = theConfiguration;
}
/**
* Gets the CORS configuration
*/
@ -107,6 +81,13 @@ public class CorsInterceptor extends InterceptorAdapter {
return myConfig;
}
/**
* Sets the CORS configuration
*/
public void setConfig(CorsConfiguration theConfiguration) {
myConfig = theConfiguration;
}
@Override
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
if (CorsUtils.isCorsRequest(theRequest)) {
@ -124,4 +105,26 @@ public class CorsInterceptor extends InterceptorAdapter {
return super.incomingRequestPreProcessed(theRequest, theResponse);
}
private static CorsConfiguration createDefaultCorsConfig() {
CorsConfiguration retVal = new CorsConfiguration();
// *********************************************************
// Update constructor documentation if you change these:
// *********************************************************
retVal.addAllowedHeader("Origin");
retVal.addAllowedHeader("Accept");
retVal.addAllowedHeader("X-Requested-With");
retVal.addAllowedHeader("Content-Type");
retVal.addAllowedHeader("Access-Control-Request-Method");
retVal.addAllowedHeader("Access-Control-Request-Headers");
retVal.addAllowedHeader("Cache-Control");
retVal.addAllowedOrigin("*");
retVal.addExposedHeader("Location");
retVal.addExposedHeader("Content-Location");
retVal.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "PATCH"));
return retVal;
}
}