Search in sources :

Example 1 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager 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();
}
Also used : JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) CommonsDigester(org.apache.tika.parser.utils.CommonsDigester) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Before(org.junit.Before)

Example 2 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager 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");
}
Also used : JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) TbSysWsConfig(com.netsteadfast.greenstep.po.hbm.TbSysWsConfig) Endpoint(javax.xml.ws.Endpoint) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 3 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager in project bamboobsc by billchen198318.

the class CxfServerBean method shutdown.

public static void shutdown() throws Exception {
    logger.warn("shutdown");
    if (restartNum > 0) {
        throw new Exception("Cannot support shutdown again");
    }
    if (server != null) {
        server.stop();
        server.destroy();
        server = null;
    }
    if (serverFactoryBean != null) {
        serverFactoryBean.getBus().shutdown(true);
        BindingFactoryManager manager = serverFactoryBean.getBus().getExtension(BindingFactoryManager.class);
        manager.unregisterBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID);
        serverFactoryBean = null;
        bindingFactory.getBus().shutdown(true);
        bindingFactory = null;
    }
}
Also used : BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException)

Example 4 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager 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);
    }
}
Also used : TikaParsers(org.apache.tika.server.resource.TikaParsers) JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) GnuParser(org.apache.commons.cli.GnuParser) ArrayList(java.util.ArrayList) UnpackerResource(org.apache.tika.server.resource.UnpackerResource) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) Tika(org.apache.tika.Tika) HelpFormatter(org.apache.commons.cli.HelpFormatter) MetadataListMessageBodyWriter(org.apache.tika.server.writer.MetadataListMessageBodyWriter) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ResourceProvider(org.apache.cxf.jaxrs.lifecycle.ResourceProvider) CommonsDigester(org.apache.tika.parser.utils.CommonsDigester) XMPMessageBodyWriter(org.apache.tika.server.writer.XMPMessageBodyWriter) TikaDetectors(org.apache.tika.server.resource.TikaDetectors) MetadataResource(org.apache.tika.server.resource.MetadataResource) RecursiveMetadataResource(org.apache.tika.server.resource.RecursiveMetadataResource) JSONMessageBodyWriter(org.apache.tika.server.writer.JSONMessageBodyWriter) DigestingParser(org.apache.tika.parser.DigestingParser) CrossOriginResourceSharingFilter(org.apache.cxf.rs.security.cors.CrossOriginResourceSharingFilter) DetectorResource(org.apache.tika.server.resource.DetectorResource) TranslateResource(org.apache.tika.server.resource.TranslateResource) RecursiveMetadataResource(org.apache.tika.server.resource.RecursiveMetadataResource) Options(org.apache.commons.cli.Options) ZipWriter(org.apache.tika.server.writer.ZipWriter) LanguageResource(org.apache.tika.server.resource.LanguageResource) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) CSVMessageBodyWriter(org.apache.tika.server.writer.CSVMessageBodyWriter) TextMessageBodyWriter(org.apache.tika.server.writer.TextMessageBodyWriter) TikaMimeTypes(org.apache.tika.server.resource.TikaMimeTypes) CommandLineParser(org.apache.commons.cli.CommandLineParser) TarWriter(org.apache.tika.server.writer.TarWriter) TikaConfig(org.apache.tika.config.TikaConfig) TikaResource(org.apache.tika.server.resource.TikaResource) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) TikaVersion(org.apache.tika.server.resource.TikaVersion) CommandLine(org.apache.commons.cli.CommandLine) TikaWelcome(org.apache.tika.server.resource.TikaWelcome)

Example 5 with BindingFactoryManager

use of org.apache.cxf.binding.BindingFactoryManager in project opencast by opencast.

the class RestPublisher method createEndpoint.

/**
 * Creates a REST endpoint for the JAX-RS annotated service.
 *
 * @param ref
 *          the osgi service reference
 * @param service
 *          The service itself
 */
protected void createEndpoint(ServiceReference<?> ref, Object service) {
    String serviceType = (String) ref.getProperty(SERVICE_TYPE_PROPERTY);
    String servicePath = (String) ref.getProperty(SERVICE_PATH_PROPERTY);
    boolean servicePublishFlag = ref.getProperty(SERVICE_PUBLISH_PROPERTY) == null || Boolean.parseBoolean((String) ref.getProperty(SERVICE_PUBLISH_PROPERTY));
    boolean jobProducer = Boolean.parseBoolean((String) ref.getProperty(SERVICE_JOBPRODUCER_PROPERTY));
    ServiceRegistration<?> reg = servletRegistrationMap.get(servicePath);
    if (reg != null) {
        logger.debug("Rest endpoint {} is still registred, skip registering again", servicePath);
        return;
    }
    RestServlet cxf = new RestServlet();
    try {
        Dictionary<String, Object> props = new Hashtable<>();
        props.put(SharedHttpContext.ALIAS, servicePath);
        props.put(SharedHttpContext.SERVLET_NAME, service.toString());
        props.put(SharedHttpContext.CONTEXT_ID, RestConstants.HTTP_CONTEXT_ID);
        props.put(SharedHttpContext.SHARED, "true");
        props.put(SERVICE_TYPE_PROPERTY, serviceType);
        props.put(SERVICE_PATH_PROPERTY, servicePath);
        props.put(SERVICE_PUBLISH_PROPERTY, servicePublishFlag);
        props.put(SERVICE_JOBPRODUCER_PROPERTY, jobProducer);
        reg = componentContext.getBundleContext().registerService(Servlet.class.getName(), cxf, props);
    } catch (Exception e) {
        logger.info("Problem registering REST endpoint {} : {}", servicePath, e.getMessage());
        return;
    }
    servletRegistrationMap.put(servicePath, reg);
    // Wait for the servlet to be initialized as long as one minute. Since the servlet is published via the whiteboard,
    // this may happen asynchronously. However, after 30 seconds we expect the HTTP service and the whiteboard
    // implementation to be loaded and active.
    int count = 0;
    while (!cxf.isInitialized() && count < 300) {
        logger.debug("Waiting for the servlet at '{}' to be initialized", servicePath);
        try {
            Thread.sleep(100);
            count++;
        } catch (InterruptedException e) {
            logger.warn("Interrupt while waiting for RestServlet initialization");
            break;
        }
    }
    // Was initialization successful
    if (!cxf.isInitialized()) {
        logger.error("Whiteboard implemenation failed to pick up REST endpoint declaration {}", serviceType);
        return;
    }
    resourceProviders.put(ref, new SingletonResourceProvider(service));
    // Set up cxf
    Bus bus = cxf.getBus();
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setBus(bus);
    sf.setProviders(providers);
    // Set the service class
    sf.setResourceProviders(new ArrayList<>(resourceProviders.values()));
    sf.setResourceComparator(new OsgiCxfEndpointComparator());
    sf.setAddress("/");
    BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);
    JAXRSBindingFactory factory = new JAXRSBindingFactory();
    factory.setBus(sf.getBus());
    manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);
    if (server != null) {
        logger.debug("Destroying JAX-RS server");
        server.stop();
        server.destroy();
    }
    server = sf.create();
    logger.info("Registered REST endpoint at " + servicePath);
    if (service instanceof RestEndpoint) {
        ((RestEndpoint) service).endpointPublished();
    }
}
Also used : Bus(org.apache.cxf.Bus) JAXRSBindingFactory(org.apache.cxf.jaxrs.JAXRSBindingFactory) Hashtable(java.util.Hashtable) JAXRSServerFactoryBean(org.apache.cxf.jaxrs.JAXRSServerFactoryBean) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) SingletonResourceProvider(org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider) ServletException(javax.servlet.ServletException) XMLStreamException(javax.xml.stream.XMLStreamException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Aggregations

BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)33 Bus (org.apache.cxf.Bus)15 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)11 WSDLServiceBuilder (org.apache.cxf.wsdl11.WSDLServiceBuilder)8 Before (org.junit.Before)8 BindingInfo (org.apache.cxf.service.model.BindingInfo)7 BindingOperationInfo (org.apache.cxf.service.model.BindingOperationInfo)7 ServiceInfo (org.apache.cxf.service.model.ServiceInfo)7 IMocksControl (org.easymock.IMocksControl)7 Definition (javax.wsdl.Definition)6 BusException (org.apache.cxf.BusException)6 BindingFactory (org.apache.cxf.binding.BindingFactory)6 Test (org.junit.Test)6 Service (javax.wsdl.Service)5 WSDLReader (javax.wsdl.xml.WSDLReader)5 QName (javax.xml.namespace.QName)5 SoapBindingInfo (org.apache.cxf.binding.soap.model.SoapBindingInfo)5 JAXRSBindingFactory (org.apache.cxf.jaxrs.JAXRSBindingFactory)5 JAXRSServerFactoryBean (org.apache.cxf.jaxrs.JAXRSServerFactoryBean)4 WSDLFactory (javax.wsdl.factory.WSDLFactory)3