use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project camel by apache.
the class CxfRsEndpoint method createJAXRSServerFactoryBean.
public JAXRSServerFactoryBean createJAXRSServerFactoryBean() {
JAXRSServerFactoryBean answer = newJAXRSServerFactoryBean();
setupJAXRSServerFactoryBean(answer);
return answer;
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project midpoint by Evolveum.
the class RestServiceInitializer method startServer.
public void startServer() throws Exception {
applicationContext = new ClassPathXmlApplicationContext("ctx-rest-test-main.xml");
LOGGER.info("Spring context initialized.");
JAXRSServerFactoryBean sf = (JAXRSServerFactoryBean) applicationContext.getBean("restService");
sf.setAddress(ENDPOINT_ADDRESS);
server = sf.create();
repositoryService = (SqlRepositoryServiceImpl) applicationContext.getBean("repositoryService");
provisioning = (ProvisioningServiceImpl) applicationContext.getBean("provisioningService");
taskManager = (TaskManager) applicationContext.getBean("taskManager");
modelService = (ModelService) applicationContext.getBean("modelController");
xmlProvider = (TestXmlProvider) applicationContext.getBean("testXmlProvider");
jsonProvider = (TestJsonProvider) applicationContext.getBean("testJsonProvider");
yamlProvider = (TestYamlProvider) applicationContext.getBean("testYamlProvider");
InternalsConfig.encryptionChecks = false;
prismContext = (PrismContext) applicationContext.getBean("prismContext");
Task initTask = getTaskManager().createTaskInstance(TestAbstractRestService.class.getName() + ".startServer");
OperationResult result = initTask.getResult();
addObject(ROLE_SUPERUSER_FILE, result);
addObject(ROLE_ENDUSER_FILE, result);
addObject(ROLE_REST_FILE, result);
addObject(ROLE_READER_FILE, result);
addObject(USER_ADMINISTRATOR_FILE, result);
addObject(USER_NOBODY_FILE, result);
addObject(USER_CYCLOPS_FILE, result);
addObject(USER_SOMEBODY_FILE, result);
addObject(VALUE_POLICY_GENERAL, result);
addObject(VALUE_POLICY_NUMERIC, result);
addObject(VALUE_POLICY_SIMPLE, result);
addObject(SECURITY_POLICY, result);
addObject(SYSTEM_CONFIGURATION_FILE, result);
dummyAuditService = getDummyAuditService().getInstance();
InternalMonitor.reset();
getModelService().postInit(result);
result.computeStatus();
TestUtil.assertSuccessOrWarning("startServer failed (result)", result, 1);
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project tika by apache.
the class CXFTestBase method setUp.
@Before
public void setUp() {
this.tika = TikaConfig.getDefaultConfig();
TikaResource.init(tika, new CommonsDigester(DIGESTER_READ_LIMIT, CommonsDigester.DigestAlgorithm.MD5), new DefaultInputStreamFactory());
JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
setUpResources(sf);
setUpProviders(sf);
sf.setAddress(endPoint + "/");
BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
JAXRSBindingFactory factory = new JAXRSBindingFactory();
factory.setBus(sf.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
server = sf.create();
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean in project bamboobsc by billchen198318.
the class CxfServerBean method start.
public static void start(PublishingCXFServlet servlet, ServletConfig servletConfig, Bus bus, boolean loadBusManual) {
logger.info("start");
CxfServerBean.servlet = servlet;
CxfServerBean.servletConfig = servletConfig;
CxfServerBean.bus = bus;
if (server != null && serverFactoryBean != null) {
logger.warn("Server is found , not start");
return;
}
try {
if (loadBusManual) {
logger.info("load bus manual mode");
CxfServerBean.bus = servlet.loadBusManual(servletConfig);
restartNum = restartNum + 1;
}
BusFactory.setDefaultBus(CxfServerBean.bus);
serverFactoryBean = new JAXRSServerFactoryBean();
serverFactoryBean.setBus(CxfServerBean.bus);
List<TbSysWsConfig> configs = getSystemWsConfigs();
publishDefault(configs);
int r = publishRest(serverFactoryBean, configs);
BindingFactoryManager manager = serverFactoryBean.getBus().getExtension(BindingFactoryManager.class);
bindingFactory = new JAXRSBindingFactory();
bindingFactory.setBus(serverFactoryBean.getBus());
manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, bindingFactory);
if (r > 0) {
server = serverFactoryBean.create();
}
} catch (Exception e) {
e.printStackTrace();
}
logger.info("end");
}
use of org.apache.cxf.jaxrs.JAXRSServerFactoryBean 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);
}
}
Aggregations