use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tika by apache.
the class StackTraceOffTest method setUpResources.
@Override
protected void setUpResources(JAXRSServerFactoryBean sf) {
List<ResourceProvider> rCoreProviders = new ArrayList<ResourceProvider>();
rCoreProviders.add(new SingletonResourceProvider(new MetadataResource()));
rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource()));
rCoreProviders.add(new SingletonResourceProvider(new DetectorResource()));
rCoreProviders.add(new SingletonResourceProvider(new TikaResource()));
rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource()));
sf.setResourceProviders(rCoreProviders);
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tika by apache.
the class TikaWelcomeTest method setUpResources.
@Override
protected void setUpResources(JAXRSServerFactoryBean sf) {
List<ResourceProvider> rpsCore = new ArrayList<ResourceProvider>();
rpsCore.add(new SingletonResourceProvider(new TikaVersion()));
rpsCore.add(new SingletonResourceProvider(new DetectorResource()));
rpsCore.add(new SingletonResourceProvider(new MetadataResource()));
List<ResourceProvider> all = new ArrayList<ResourceProvider>(rpsCore);
all.add(new SingletonResourceProvider(new TikaWelcome(rpsCore)));
sf.setResourceProviders(all);
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tika by apache.
the class TikaServerCli method main.
public static void main(String[] args) {
LOG.info("Starting {} server", new Tika());
try {
Options options = getOptions();
CommandLineParser cliParser = new GnuParser();
CommandLine line = cliParser.parse(options, args);
if (line.hasOption("help")) {
HelpFormatter helpFormatter = new HelpFormatter();
helpFormatter.printHelp("tikaserver", options);
System.exit(-1);
}
String host = DEFAULT_HOST;
if (line.hasOption("host")) {
host = line.getOptionValue("host");
if ("*".equals(host)) {
host = "0.0.0.0";
}
}
int port = DEFAULT_PORT;
if (line.hasOption("port")) {
port = Integer.valueOf(line.getOptionValue("port"));
}
boolean returnStackTrace = false;
if (line.hasOption("includeStack")) {
returnStackTrace = true;
}
TikaLoggingFilter logFilter = null;
if (line.hasOption("log")) {
String logLevel = line.getOptionValue("log");
if (LOG_LEVELS.contains(logLevel)) {
boolean isInfoLevel = "info".equals(logLevel);
logFilter = new TikaLoggingFilter(isInfoLevel);
} else {
LOG.info("Unsupported request URI log level: {}", logLevel);
}
}
CrossOriginResourceSharingFilter corsFilter = null;
if (line.hasOption("cors")) {
corsFilter = new CrossOriginResourceSharingFilter();
String url = line.getOptionValue("cors");
List<String> origins = new ArrayList<String>();
// Empty list allows all origins.
if (!url.equals("*"))
origins.add(url);
corsFilter.setAllowOrigins(origins);
}
// The Tika Configuration to use throughout
TikaConfig tika;
if (line.hasOption("config")) {
String configFilePath = line.getOptionValue("config");
LOG.info("Using custom config: {}", configFilePath);
tika = new TikaConfig(configFilePath);
} else {
tika = TikaConfig.getDefaultConfig();
}
DigestingParser.Digester digester = null;
if (line.hasOption("digest")) {
int digestMarkLimit = DEFAULT_DIGEST_MARK_LIMIT;
if (line.hasOption("dml")) {
String dmlS = line.getOptionValue("dml");
try {
digestMarkLimit = Integer.parseInt(dmlS);
} catch (NumberFormatException e) {
throw new RuntimeException("Must have parseable int after digestMarkLimit(dml): " + dmlS);
}
}
digester = new CommonsDigester(digestMarkLimit, CommonsDigester.parse(line.getOptionValue("digest")));
}
if (line.hasOption("enableFileUrl") && !line.hasOption("enableUnsecureFeatures")) {
System.err.println("If you want to enable fileUrl, you must also acknowledge the security risks\n" + "by including --enableUnsecureFeatures. See CVE-2015-3271.");
System.exit(-1);
}
InputStreamFactory inputStreamFactory = null;
if (line.hasOption("enableFileUrl") && line.hasOption("enableUnsecureFeatures")) {
inputStreamFactory = new URLEnabledInputStreamFactory();
System.out.println(FILE_URL_WARNING);
} else {
inputStreamFactory = new DefaultInputStreamFactory();
}
TikaResource.init(tika, digester, inputStreamFactory);
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
List<ResourceProvider> rCoreProviders = new ArrayList<>();
rCoreProviders.add(new SingletonResourceProvider(new MetadataResource()));
rCoreProviders.add(new SingletonResourceProvider(new RecursiveMetadataResource()));
rCoreProviders.add(new SingletonResourceProvider(new DetectorResource()));
rCoreProviders.add(new SingletonResourceProvider(new LanguageResource()));
rCoreProviders.add(new SingletonResourceProvider(new TranslateResource()));
rCoreProviders.add(new SingletonResourceProvider(new TikaResource()));
rCoreProviders.add(new SingletonResourceProvider(new UnpackerResource()));
rCoreProviders.add(new SingletonResourceProvider(new TikaMimeTypes()));
rCoreProviders.add(new SingletonResourceProvider(new TikaDetectors()));
rCoreProviders.add(new SingletonResourceProvider(new TikaParsers()));
rCoreProviders.add(new SingletonResourceProvider(new TikaVersion()));
List<ResourceProvider> rAllProviders = new ArrayList<>(rCoreProviders);
rAllProviders.add(new SingletonResourceProvider(new TikaWelcome(rCoreProviders)));
sf.setResourceProviders(rAllProviders);
List<Object> providers = new ArrayList<>();
providers.add(new TarWriter());
providers.add(new ZipWriter());
providers.add(new CSVMessageBodyWriter());
providers.add(new MetadataListMessageBodyWriter());
providers.add(new JSONMessageBodyWriter());
providers.add(new XMPMessageBodyWriter());
providers.add(new TextMessageBodyWriter());
providers.add(new TikaServerParseExceptionMapper(returnStackTrace));
if (logFilter != null) {
providers.add(logFilter);
}
if (corsFilter != null) {
providers.add(corsFilter);
}
sf.setProviders(providers);
String url = "http://" + host + ":" + port + "/";
sf.setAddress(url);
BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory factory = new JAXRSBindingFactory();
factory.setBus(sf.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
sf.create();
LOG.info("Started Apache Tika server at {}", url);
} catch (Exception ex) {
LOG.error("Can't start", ex);
System.exit(-1);
}
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.
the class CXFNonSpringJaxrsServlet method init.
@Override
public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
if (getApplication() != null) {
createServerFromApplication(servletConfig);
return;
}
String applicationClass = servletConfig.getInitParameter(JAXRS_APPLICATION_PARAM);
if (applicationClass != null) {
createServerFromApplication(applicationClass, servletConfig);
return;
}
String splitChar = getParameterSplitChar(servletConfig);
JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
bean.setBus(getBus());
String address = servletConfig.getInitParameter(SERVICE_ADDRESS_PARAM);
if (address == null) {
address = "/";
}
bean.setAddress(address);
bean.setStaticSubresourceResolution(getStaticSubResolutionValue(servletConfig));
String modelRef = servletConfig.getInitParameter(USER_MODEL_PARAM);
if (modelRef != null) {
bean.setModelRef(modelRef.trim());
}
setDocLocation(bean, servletConfig);
setSchemasLocations(bean, servletConfig);
setAllInterceptors(bean, servletConfig, splitChar);
setInvoker(bean, servletConfig);
Map<Class<?>, Map<String, List<String>>> resourceClasses = getServiceClasses(servletConfig, modelRef != null, splitChar);
Map<Class<?>, ResourceProvider> resourceProviders = getResourceProviders(servletConfig, resourceClasses);
List<?> providers = getProviders(servletConfig, splitChar);
bean.setResourceClasses(new ArrayList<Class<?>>(resourceClasses.keySet()));
bean.setProviders(providers);
for (Map.Entry<Class<?>, ResourceProvider> entry : resourceProviders.entrySet()) {
bean.setResourceProvider(entry.getKey(), entry.getValue());
}
setExtensions(bean, servletConfig);
List<? extends Feature> features = getFeatures(servletConfig, splitChar);
bean.getFeatures().addAll(features);
bean.create();
}
use of org.apache.cxf.jaxrs.lifecycle.ResourceProvider in project tomee by apache.
the class ResourceUtils method createApplication.
@SuppressWarnings("unchecked")
public static JAXRSServerFactoryBean createApplication(Application app, boolean ignoreAppPath, boolean staticSubresourceResolution, boolean useSingletonResourceProvider, Bus bus) {
Set<Object> singletons = app.getSingletons();
verifySingletons(singletons);
List<Class<?>> resourceClasses = new ArrayList<>();
List<Object> providers = new ArrayList<>();
List<Feature> features = new ArrayList<>();
Map<Class<?>, ResourceProvider> map = new HashMap<>();
// or singleton provider classes
for (Class<?> cls : app.getClasses()) {
if (isValidApplicationClass(cls, singletons)) {
if (isValidProvider(cls)) {
providers.add(createProviderInstance(cls));
} else if (Feature.class.isAssignableFrom(cls)) {
features.add(createFeatureInstance((Class<? extends Feature>) cls));
} else {
resourceClasses.add(cls);
if (useSingletonResourceProvider) {
map.put(cls, new SingletonResourceProvider(createProviderInstance(cls)));
} else {
map.put(cls, new PerRequestResourceProvider(cls));
}
}
}
}
// we can get either a provider or resource class here
for (Object o : singletons) {
if (isValidProvider(o.getClass())) {
providers.add(o);
} else if (o instanceof Feature) {
features.add((Feature) o);
} else {
resourceClasses.add(o.getClass());
map.put(o.getClass(), new SingletonResourceProvider(o));
}
}
JAXRSServerFactoryBean bean = new JAXRSServerFactoryBean();
if (bus != null) {
bean.setBus(bus);
}
String address = "/";
if (!ignoreAppPath) {
ApplicationPath appPath = locateApplicationPath(app.getClass());
if (appPath != null) {
address = appPath.value();
}
}
if (!address.startsWith("/")) {
address = "/" + address;
}
bean.setAddress(address);
bean.setStaticSubresourceResolution(staticSubresourceResolution);
bean.setResourceClasses(resourceClasses);
bean.setProviders(providers);
bean.getFeatures().addAll(features);
for (Map.Entry<Class<?>, ResourceProvider> entry : map.entrySet()) {
bean.setResourceProvider(entry.getKey(), entry.getValue());
}
Map<String, Object> appProps = app.getProperties();
if (appProps != null) {
bean.getProperties(true).putAll(appProps);
}
bean.setApplication(app);
return bean;
}
Aggregations