Allow cache-control to be used with CORS
This commit is contained in:
parent
15ba0dff03
commit
d461567433
|
@ -48,18 +48,48 @@ import static org.apache.commons.lang3.StringUtils.trim;
|
||||||
public class JavaMailEmailSender implements IEmailSender {
|
public class JavaMailEmailSender implements IEmailSender {
|
||||||
|
|
||||||
private static final Logger ourLog = LoggerFactory.getLogger(JavaMailEmailSender.class);
|
private static final Logger ourLog = LoggerFactory.getLogger(JavaMailEmailSender.class);
|
||||||
private String mySmtpServerHost;
|
private String mySmtpServerHostname;
|
||||||
private int mySmtpServerPort = 25;
|
private int mySmtpServerPort = 25;
|
||||||
private JavaMailSenderImpl mySender;
|
private JavaMailSenderImpl mySender;
|
||||||
|
private String mySmtpServerUsername;
|
||||||
|
private String mySmtpServerPassword;
|
||||||
|
|
||||||
@PostConstruct
|
public String getSmtpServerHostname() {
|
||||||
public void start() {
|
return mySmtpServerHostname;
|
||||||
Validate.notBlank(mySmtpServerHost, "No SMTP host defined");
|
}
|
||||||
|
|
||||||
mySender = new JavaMailSenderImpl();
|
/**
|
||||||
mySender.setHost(mySmtpServerHost);
|
* Set the SMTP server host to use for outbound mail
|
||||||
mySender.setPort(mySmtpServerPort);
|
*/
|
||||||
mySender.setDefaultEncoding(Constants.CHARSET_UTF8.name());
|
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
|
@Override
|
||||||
|
@ -102,18 +132,16 @@ public class JavaMailEmailSender implements IEmailSender {
|
||||||
ourLog.info("Done sending email (took {}ms)", sw.getMillis());
|
ourLog.info("Done sending email (took {}ms)", sw.getMillis());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@PostConstruct
|
||||||
* Set the SMTP server host to use for outbound mail
|
public void start() {
|
||||||
*/
|
Validate.notBlank(mySmtpServerHostname, "No SMTP host defined");
|
||||||
public void setSmtpServerHost(String theSmtpServerHost) {
|
|
||||||
mySmtpServerHost = theSmtpServerHost;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
mySender = new JavaMailSenderImpl();
|
||||||
* Set the SMTP server port to use for outbound mail
|
mySender.setHost(getSmtpServerHostname());
|
||||||
*/
|
mySender.setPort(getSmtpServerPort());
|
||||||
public void setSmtpServerPort(int theSmtpServerPort) {
|
mySender.setUsername(getSmtpServerUsername());
|
||||||
mySmtpServerPort = theSmtpServerPort;
|
mySender.setPassword(getSmtpServerPassword());
|
||||||
|
mySender.setDefaultEncoding(Constants.CHARSET_UTF8.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toTrimmedCommaSeparatedString(List<String> theTo) {
|
private static String toTrimmedCommaSeparatedString(List<String> theTo) {
|
||||||
|
|
|
@ -118,7 +118,7 @@ public class TestDstu3Config extends BaseJavaConfigDstu3 {
|
||||||
@Bean
|
@Bean
|
||||||
public IEmailSender emailSender() {
|
public IEmailSender emailSender() {
|
||||||
JavaMailEmailSender retVal = new JavaMailEmailSender();
|
JavaMailEmailSender retVal = new JavaMailEmailSender();
|
||||||
retVal.setSmtpServerHost("localhost");
|
retVal.setSmtpServerHostname("localhost");
|
||||||
retVal.setSmtpServerPort(3025);
|
retVal.setSmtpServerPort(3025);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class EmailSubscriptionDstu2Test extends BaseResourceProviderDstu2Test {
|
||||||
super.before();
|
super.before();
|
||||||
|
|
||||||
JavaMailEmailSender emailSender = new JavaMailEmailSender();
|
JavaMailEmailSender emailSender = new JavaMailEmailSender();
|
||||||
emailSender.setSmtpServerHost("localhost");
|
emailSender.setSmtpServerHostname("localhost");
|
||||||
emailSender.setSmtpServerPort(3025);
|
emailSender.setSmtpServerPort(3025);
|
||||||
emailSender.start();
|
emailSender.start();
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,10 @@ public class EmailSubscriptionDstu3Test extends BaseResourceProviderDstu3Test {
|
||||||
.setUrl(JpaConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE)
|
.setUrl(JpaConstants.EXT_SUBSCRIPTION_SUBJECT_TEMPLATE)
|
||||||
.setValue(new StringType("This is a subject"));
|
.setValue(new StringType("This is a subject"));
|
||||||
subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless());
|
subscriptionTemp.setIdElement(subscriptionTemp.getIdElement().toUnqualifiedVersionless());
|
||||||
|
|
||||||
|
|
||||||
|
ourLog.info(myFhirCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(subscriptionTemp));
|
||||||
|
|
||||||
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
ourClient.update().resource(subscriptionTemp).withId(subscriptionTemp.getIdElement()).execute();
|
||||||
waitForQueueToDrain();
|
waitForQueueToDrain();
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import ca.uhn.fhir.jpa.testutil.RandomServerPortProvider;
|
||||||
import com.icegreen.greenmail.util.GreenMail;
|
import com.icegreen.greenmail.util.GreenMail;
|
||||||
import com.icegreen.greenmail.util.GreenMailUtil;
|
import com.icegreen.greenmail.util.GreenMailUtil;
|
||||||
import com.icegreen.greenmail.util.ServerSetup;
|
import com.icegreen.greenmail.util.ServerSetup;
|
||||||
import com.icegreen.greenmail.util.ServerSetupTest;
|
|
||||||
import org.hl7.fhir.dstu3.model.IdType;
|
import org.hl7.fhir.dstu3.model.IdType;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
@ -27,8 +26,10 @@ public class JavaMailEmailSenderTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSend() throws Exception {
|
public void testSend() throws Exception {
|
||||||
JavaMailEmailSender sender = new JavaMailEmailSender();
|
JavaMailEmailSender sender = new JavaMailEmailSender();
|
||||||
sender.setSmtpServerHost("localhost");
|
sender.setSmtpServerHostname("localhost");
|
||||||
sender.setSmtpServerPort(ourPort);
|
sender.setSmtpServerPort(ourPort);
|
||||||
|
sender.setSmtpServerUsername(null);
|
||||||
|
sender.setSmtpServerPassword(null);
|
||||||
sender.start();
|
sender.start();
|
||||||
|
|
||||||
String body = "foo";
|
String body = "foo";
|
||||||
|
|
|
@ -181,6 +181,7 @@ public class TestRestfulServer extends RestfulServer {
|
||||||
config.addAllowedHeader("Content-Type");
|
config.addAllowedHeader("Content-Type");
|
||||||
config.addAllowedHeader("Access-Control-Request-Method");
|
config.addAllowedHeader("Access-Control-Request-Method");
|
||||||
config.addAllowedHeader("Access-Control-Request-Headers");
|
config.addAllowedHeader("Access-Control-Request-Headers");
|
||||||
|
config.addAllowedHeader("Cache-Control");
|
||||||
config.addAllowedOrigin("*");
|
config.addAllowedOrigin("*");
|
||||||
config.addExposedHeader("Location");
|
config.addExposedHeader("Location");
|
||||||
config.addExposedHeader("Content-Location");
|
config.addExposedHeader("Content-Location");
|
||||||
|
|
|
@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -61,29 +62,9 @@ public class CorsInterceptor extends InterceptorAdapter {
|
||||||
this(createDefaultCorsConfig());
|
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
|
* Constructor which accepts the given configuration
|
||||||
*
|
*
|
||||||
* @param theConfiguration
|
* @param theConfiguration
|
||||||
* The CORS configuration
|
* The CORS configuration
|
||||||
*/
|
*/
|
||||||
|
@ -93,13 +74,6 @@ public class CorsInterceptor extends InterceptorAdapter {
|
||||||
setConfig(theConfiguration);
|
setConfig(theConfiguration);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the CORS configuration
|
|
||||||
*/
|
|
||||||
public void setConfig(CorsConfiguration theConfiguration) {
|
|
||||||
myConfig = theConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the CORS configuration
|
* Gets the CORS configuration
|
||||||
*/
|
*/
|
||||||
|
@ -107,6 +81,13 @@ public class CorsInterceptor extends InterceptorAdapter {
|
||||||
return myConfig;
|
return myConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the CORS configuration
|
||||||
|
*/
|
||||||
|
public void setConfig(CorsConfiguration theConfiguration) {
|
||||||
|
myConfig = theConfiguration;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
|
public boolean incomingRequestPreProcessed(HttpServletRequest theRequest, HttpServletResponse theResponse) {
|
||||||
if (CorsUtils.isCorsRequest(theRequest)) {
|
if (CorsUtils.isCorsRequest(theRequest)) {
|
||||||
|
@ -124,4 +105,26 @@ public class CorsInterceptor extends InterceptorAdapter {
|
||||||
return super.incomingRequestPreProcessed(theRequest, theResponse);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue