public String getFoo()
{
return foo;
}
package com.smashit.common.config.resteasy;
import java.util.HashMap;
import org.jboss.resteasy.plugins.spring.SpringBeanProcessor;
import org.jboss.resteasy.spi.ResteasyDeployment;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.springmvc.ResteasyHandlerAdapter;
import org.jboss.resteasy.springmvc.ResteasyHandlerMapping;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import com.smashit.common.http.HttpCommonBusiness;
import com.smashit.common.http.HttpCommonBusinessImpl;
@ConditionalOnClass(ResteasyHandlerMapping.class)
@EnableConfigurationProperties
@Configuration
@ConditionalOnWebApplication
public class SpringMvcResteasyConfig {
public static String API_PATH_PREFIX="api";
@ConditionalOnMissingBean(ResteasyDeployment.class)
@ConfigurationProperties(prefix="resteasy.deployment")
@Bean(initMethod="start", destroyMethod="stop")
public ResteasyDeployment resteasyDeployment(final SpringBeanProcessor springBeanProcessor) {
ResteasyDeployment resteasyDeployment = new ResteasyDeployment() {
public void start() {
super.start();
if (springBeanProcessor.getRegistry() == null) {
springBeanProcessor.setRegistry(this.getRegistry());
}
}
};
resteasyDeployment.setProviderFactory(springBeanProcessor.getProviderFactory());
resteasyDeployment.setMediaTypeMappings(new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("pdf", HttpCommonBusinessImpl.CONTENT_TYPE_PDF);
put("json", HttpCommonBusinessImpl.CONTENT_TYPE_JSON);
put("xml", HttpCommonBusinessImpl.CONTENT_TYPE_XML);
put("csv", HttpCommonBusinessImpl.CONTENT_TYPE_CSV);
put("html", HttpCommonBusinessImpl.CONTENT_TYPE_HMTL);
put("xls", HttpCommonBusinessImpl.CONTENT_TYPE_OFFICE_XLS);
put("xlsx", HttpCommonBusinessImpl.CONTENT_TYPE_OFFICE_XLSX);
put("doc", HttpCommonBusinessImpl.CONTENT_TYPE_OFFICE_DOC);
put("docx", HttpCommonBusinessImpl.CONTENT_TYPE_OFFICE_DOCX);
put("rtf", HttpCommonBusinessImpl.CONTENT_TYPE_RTF);
put("ods", HttpCommonBusinessImpl.CONTENT_TYPE_OPENOFFICE_ODS);
put("odt", HttpCommonBusinessImpl.CONTENT_TYPE_OPENOFFICE_ODT);
}
});
resteasyDeployment.setLanguageExtensions(new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
put("en", "en-US");
put("fr", "fr-FR");
put("it", "it-IT");
put("de", "de-DE");
}
});
return resteasyDeployment;
}
@ConditionalOnMissingBean(SpringBeanProcessor.class)
@Bean
public SpringBeanProcessor springBeanProcessor() {
SpringBeanProcessor springBeanProcessor = new SpringBeanProcessor();
springBeanProcessor.setProviderFactory(new ResteasyProviderFactory());
return springBeanProcessor;
}
/** Receive requests from spring MVC dispatcher servlet. There is no RestEasy Servlet at all
*
* @param deployment
* @return
*/
@ConditionalOnMissingBean(ResteasyHandlerMapping.class)
@Bean
public ResteasyHandlerMapping resteasyHandlerMapper(ResteasyDeployment deployment) {
ResteasyHandlerMapping handlerMapping = new ResteasyHandlerMapping(deployment);
handlerMapping.setOrder(Ordered.LOWEST_PRECEDENCE);
handlerMapping.setPrefix("/"+API_PATH_PREFIX);
return handlerMapping;
}
@ConditionalOnMissingBean(ResteasyHandlerAdapter.class)
@Bean
public ResteasyHandlerAdapter resteasyHandlerAdapter(ResteasyDeployment deployment) {
return new ResteasyHandlerAdapter(deployment);
}
}