public class BookServer extends AbstractBusTestServerBase {
public static final String PORT = allocatePort(BookServer.class);
protected void run() {
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
sf.setResourceClasses(BookStore.class, SimpleBookStore.class, BookStorePerRequest.class);
List<Object> providers = new ArrayList<Object>();
//default lifecycle is per-request, change it to singleton
BinaryDataProvider p = new BinaryDataProvider();
p.setProduceMediaTypes(Collections.singletonList("application/bar"));
p.setEnableBuffering(true);
providers.add(p);
JAXBElementProvider jaxbProvider = new JAXBElementProvider();
Map<String, String> jaxbElementClassMap = new HashMap<String, String>();
jaxbElementClassMap.put(BookNoXmlRootElement.class.getName(), "BookNoXmlRootElement");
jaxbProvider.setJaxbElementClassMap(jaxbElementClassMap);
providers.add(jaxbProvider);
providers.add(new FormatResponseHandler());
providers.add(new GenericHandlerWriter());
providers.add(new FaultyRequestHandler());
sf.setProviders(providers);
List<Interceptor<? extends Message>> outInts = new ArrayList<Interceptor<? extends Message>>();
outInts.add(new CustomOutInterceptor());
sf.setOutInterceptors(outInts);
List<Interceptor<? extends Message>> outFaultInts = new ArrayList<Interceptor<? extends Message>>();
outFaultInts.add(new CustomOutFaultInterceptor());
sf.setOutFaultInterceptors(outFaultInts);
sf.setResourceProvider(BookStore.class,
new SingletonResourceProvider(new BookStore(), true));
sf.setAddress("http://localhost:" + PORT + "/");
sf.getProperties(true).put("org.apache.cxf.jaxrs.mediaTypeCheck.strict", true);
sf.getProperties().put("org.apache.cxf.http.header.split", true);
sf.create();
}