Search in sources :

Example 26 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class ServiceImpl method getJaxwsEndpoint.

private JaxWsClientEndpointImpl getJaxwsEndpoint(QName portName, AbstractServiceFactoryBean sf, WebServiceFeature... features) {
    Service service = sf.getService();
    EndpointInfo ei = null;
    if (portName == null) {
        ei = service.getServiceInfos().get(0).getEndpoints().iterator().next();
    } else {
        ei = service.getEndpointInfo(portName);
        if (ei == null) {
            PortInfoImpl portInfo = getPortInfo(portName);
            if (null != portInfo) {
                try {
                    ei = createEndpointInfo(sf, portName, portInfo);
                } catch (BusException e) {
                    throw new WebServiceException(e);
                }
            }
        }
    }
    if (ei == null) {
        Message msg = new Message("INVALID_PORT", BUNDLE, portName);
        throw new WebServiceException(msg.toString());
    }
    // When the dispatch is created from EPR, the EPR's address will be set in portInfo
    PortInfoImpl portInfo = getPortInfo(portName);
    if (portInfo != null && portInfo.getAddress() != null && !portInfo.getAddress().equals(ei.getAddress())) {
        ei.setAddress(portInfo.getAddress());
    }
    try {
        return new JaxWsClientEndpointImpl(bus, service, ei, this, getAllFeatures(features));
    } catch (EndpointException e) {
        throw new WebServiceException(e);
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) BusException(org.apache.cxf.BusException)

Example 27 with BusException

use of org.apache.cxf.BusException in project cxf by apache.

the class CXFNonSpringServlet method getDestinationRegistryFromBusOrDefault.

protected DestinationRegistry getDestinationRegistryFromBusOrDefault(final String transportId) {
    DestinationFactoryManager dfm = bus.getExtension(DestinationFactoryManager.class);
    try {
        String peferredTransportId = transportId;
        // extension or customization).
        if (StringUtils.isEmpty(peferredTransportId) && getBus() != null) {
            peferredTransportId = (String) getBus().getProperty(AbstractTransportFactory.PREFERRED_TRANSPORT_ID);
        }
        if (StringUtils.isEmpty(peferredTransportId)) {
            final Set<String> candidates = dfm.getRegisteredDestinationFactoryNames();
            // consider other candidates
            if (!candidates.contains(DEFAULT_TRANSPORT_ID)) {
                peferredTransportId = candidates.stream().filter(name -> name.endsWith("/configuration")).findAny().orElse(DEFAULT_TRANSPORT_ID);
            }
        }
        DestinationFactory df = StringUtils.isEmpty(peferredTransportId) ? dfm.getDestinationFactory(DEFAULT_TRANSPORT_ID) : dfm.getDestinationFactory(peferredTransportId);
        if (df instanceof HTTPTransportFactory) {
            HTTPTransportFactory transportFactory = (HTTPTransportFactory) df;
            return transportFactory.getRegistry();
        }
    } catch (BusException e) {
    // why are we throwing a busexception if the DF isn't found?
    }
    return null;
}
Also used : Bus(org.apache.cxf.Bus) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) FilterChain(javax.servlet.FilterChain) ServletException(javax.servlet.ServletException) StringUtils(org.apache.cxf.common.util.StringUtils) HttpServletRequestWrapper(javax.servlet.http.HttpServletRequestWrapper) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) ResourceManager(org.apache.cxf.resource.ResourceManager) HttpServletRequest(javax.servlet.http.HttpServletRequest) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) Method(java.lang.reflect.Method) ServletRequest(javax.servlet.ServletRequest) ServiceListGeneratorServlet(org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet) ServletConfig(javax.servlet.ServletConfig) HttpServlet(javax.servlet.http.HttpServlet) CastUtils(org.apache.cxf.helpers.CastUtils) DestinationFactory(org.apache.cxf.transport.DestinationFactory) Collection(java.util.Collection) BusException(org.apache.cxf.BusException) HttpServletResponse(javax.servlet.http.HttpServletResponse) Set(java.util.Set) IOException(java.io.IOException) AbstractTransportFactory(org.apache.cxf.transport.AbstractTransportFactory) ClassLoaderUtils(org.apache.cxf.common.classloader.ClassLoaderUtils) ServletResponse(javax.servlet.ServletResponse) BusFactory(org.apache.cxf.BusFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) ServletContext(javax.servlet.ServletContext) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) DestinationFactory(org.apache.cxf.transport.DestinationFactory) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) BusException(org.apache.cxf.BusException)

Example 28 with BusException

use of org.apache.cxf.BusException in project component-runtime by Talend.

the class WebSocketBroadcastSetup method contextInitialized.

@Override
public void contextInitialized(final ServletContextEvent sce) {
    final ServerContainer container = ServerContainer.class.cast(sce.getServletContext().getAttribute(ServerContainer.class.getName()));
    final JAXRSServiceFactoryBean factory = JAXRSServiceFactoryBean.class.cast(bus.getExtension(ServerRegistry.class).getServers().iterator().next().getEndpoint().get(JAXRSServiceFactoryBean.class.getName()));
    final String appBase = StreamSupport.stream(Spliterators.spliteratorUnknownSize(applications.iterator(), Spliterator.IMMUTABLE), false).filter(a -> a.getClass().isAnnotationPresent(ApplicationPath.class)).map(a -> a.getClass().getAnnotation(ApplicationPath.class)).map(ApplicationPath::value).findFirst().map(s -> !s.startsWith("/") ? "/" + s : s).orElse("/api/v1");
    final String version = appBase.replaceFirst("/api", "");
    final DestinationRegistry registry;
    try {
        final HTTPTransportFactory transportFactory = HTTPTransportFactory.class.cast(bus.getExtension(DestinationFactoryManager.class).getDestinationFactory("http://cxf.apache.org/transports/http" + "/configuration"));
        registry = transportFactory.getRegistry();
    } catch (final BusException e) {
        throw new IllegalStateException(e);
    }
    final ServletContext servletContext = sce.getServletContext();
    final WebSocketRegistry webSocketRegistry = new WebSocketRegistry(registry);
    final ServletController controller = new ServletController(webSocketRegistry, new ServletConfig() {

        @Override
        public String getServletName() {
            return "Talend Component Kit Websocket Transport";
        }

        @Override
        public ServletContext getServletContext() {
            return servletContext;
        }

        @Override
        public String getInitParameter(final String s) {
            return null;
        }

        @Override
        public Enumeration<String> getInitParameterNames() {
            return emptyEnumeration();
        }
    }, new ServiceListGeneratorServlet(registry, bus));
    webSocketRegistry.controller = controller;
    Stream.concat(factory.getClassResourceInfo().stream().flatMap(cri -> cri.getMethodDispatcher().getOperationResourceInfos().stream()).map(ori -> {
        final String uri = ori.getClassResourceInfo().getURITemplate().getValue() + ori.getURITemplate().getValue();
        return ServerEndpointConfig.Builder.create(Endpoint.class, "/websocket" + version + "/" + String.valueOf(ori.getHttpMethod()).toLowerCase(ENGLISH) + uri).configurator(new ServerEndpointConfig.Configurator() {

            @Override
            public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
                final Map<String, List<String>> headers = new HashMap<>();
                if (!ori.getProduceTypes().isEmpty()) {
                    headers.put(HttpHeaders.CONTENT_TYPE, singletonList(ori.getProduceTypes().iterator().next().toString()));
                }
                if (!ori.getConsumeTypes().isEmpty()) {
                    headers.put(HttpHeaders.ACCEPT, singletonList(ori.getConsumeTypes().iterator().next().toString()));
                }
                return (T) new JAXRSEndpoint(appBase, controller, servletContext, ori.getHttpMethod(), uri, headers);
            }
        }).build();
    }), Stream.of(ServerEndpointConfig.Builder.create(Endpoint.class, "/websocket" + version + "/bus").configurator(new ServerEndpointConfig.Configurator() {

        @Override
        public <T> T getEndpointInstance(final Class<T> clazz) throws InstantiationException {
            return (T) new JAXRSEndpoint(appBase, controller, servletContext, "GET", "/", emptyMap());
        }
    }).build())).sorted(Comparator.comparing(ServerEndpointConfig::getPath)).peek(e -> log.info("Deploying WebSocket(path={})", e.getPath())).forEach(config -> {
        try {
            container.addEndpoint(config);
        } catch (final DeploymentException e) {
            throw new IllegalStateException(e);
        }
    });
}
Also used : Enumeration(java.util.Enumeration) Collections.singletonList(java.util.Collections.singletonList) Endpoint(javax.websocket.Endpoint) Map(java.util.Map) AbstractDestination(org.apache.cxf.transport.AbstractDestination) ENGLISH(java.util.Locale.ENGLISH) Instance(javax.enterprise.inject.Instance) PrintWriter(java.io.PrintWriter) RequestDispatcher(javax.servlet.RequestDispatcher) Set(java.util.Set) FastHttpDateFormat(org.apache.tomcat.util.http.FastHttpDateFormat) StandardCharsets(java.nio.charset.StandardCharsets) WebListener(javax.servlet.annotation.WebListener) Slf4j(lombok.extern.slf4j.Slf4j) Stream(java.util.stream.Stream) MessageObserver(org.apache.cxf.transport.MessageObserver) DestinationFactoryManager(org.apache.cxf.transport.DestinationFactoryManager) QName(javax.xml.namespace.QName) ServerRegistry(org.apache.cxf.endpoint.ServerRegistry) HTTPSession(org.apache.cxf.transport.http.HTTPSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CloseReason(javax.websocket.CloseReason) SimpleDateFormat(java.text.SimpleDateFormat) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) AsyncContext(javax.servlet.AsyncContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) LogUtils(org.apache.cxf.common.logging.LogUtils) WriteListener(javax.servlet.WriteListener) ContinuationProviderFactory(org.apache.cxf.transport.http.ContinuationProviderFactory) StreamSupport(java.util.stream.StreamSupport) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ServiceListGeneratorServlet(org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) TreeMap(java.util.TreeMap) Dependent(javax.enterprise.context.Dependent) ServletContext(javax.servlet.ServletContext) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) BufferedReader(java.io.BufferedReader) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) Conduit(org.apache.cxf.transport.Conduit) ServletException(javax.servlet.ServletException) Spliterators(java.util.Spliterators) Application(javax.ws.rs.core.Application) ByteBuffer(java.nio.ByteBuffer) Collections.singleton(java.util.Collections.singleton) Locale(java.util.Locale) ServletContextListener(javax.servlet.ServletContextListener) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) HttpSession(javax.servlet.http.HttpSession) ServletConfig(javax.servlet.ServletConfig) Session(javax.websocket.Session) Collections.emptyList(java.util.Collections.emptyList) HTTPServerPolicy(org.apache.cxf.transports.http.configuration.HTTPServerPolicy) Collection(java.util.Collection) BusException(org.apache.cxf.BusException) ExchangeImpl(org.apache.cxf.message.ExchangeImpl) Collections.enumeration(java.util.Collections.enumeration) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Collections.emptyEnumeration(java.util.Collections.emptyEnumeration) List(java.util.List) Principal(java.security.Principal) HttpHeaders(javax.ws.rs.core.HttpHeaders) ServletContextEvent(javax.servlet.ServletContextEvent) ServletResponse(javax.servlet.ServletResponse) ServerContainer(javax.websocket.server.ServerContainer) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Spliterator(java.util.Spliterator) JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) Bus(org.apache.cxf.Bus) MessageImpl(org.apache.cxf.message.MessageImpl) ServletDestination(org.apache.cxf.transport.servlet.ServletDestination) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) ServletInputStream(javax.servlet.ServletInputStream) HashMap(java.util.HashMap) DeploymentException(javax.websocket.DeploymentException) Inject(javax.inject.Inject) HttpUpgradeHandler(javax.servlet.http.HttpUpgradeHandler) Continuation(org.apache.cxf.continuations.Continuation) AbstractHTTPDestination(org.apache.cxf.transport.http.AbstractHTTPDestination) ConnectionSecurityProvider(org.talend.sdk.component.server.front.security.ConnectionSecurityProvider) ServletOutputStream(javax.servlet.ServletOutputStream) Cookie(javax.servlet.http.Cookie) OutputStream(java.io.OutputStream) Collections.emptyMap(java.util.Collections.emptyMap) ContinuationProvider(org.apache.cxf.continuations.ContinuationProvider) ServletRequest(javax.servlet.ServletRequest) RemoteEndpoint(javax.websocket.RemoteEndpoint) Collections.emptySet(java.util.Collections.emptySet) ContinuationCallback(org.apache.cxf.continuations.ContinuationCallback) Message(org.apache.cxf.message.Message) EndpointConfig(javax.websocket.EndpointConfig) HttpServletResponse(javax.servlet.http.HttpServletResponse) ApplicationPath(javax.ws.rs.ApplicationPath) Part(javax.servlet.http.Part) ReadListener(javax.servlet.ReadListener) Data(lombok.Data) DispatcherType(javax.servlet.DispatcherType) Comparator(java.util.Comparator) InputStream(java.io.InputStream) ServletController(org.apache.cxf.transport.servlet.ServletController) HashMap(java.util.HashMap) ApplicationPath(javax.ws.rs.ApplicationPath) JAXRSServiceFactoryBean(org.apache.cxf.jaxrs.JAXRSServiceFactoryBean) Endpoint(javax.websocket.Endpoint) RemoteEndpoint(javax.websocket.RemoteEndpoint) ServletContext(javax.servlet.ServletContext) Collections.singletonList(java.util.Collections.singletonList) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) BusException(org.apache.cxf.BusException) ServerContainer(javax.websocket.server.ServerContainer) DestinationRegistry(org.apache.cxf.transport.http.DestinationRegistry) Enumeration(java.util.Enumeration) Collections.emptyEnumeration(java.util.Collections.emptyEnumeration) ServerEndpointConfig(javax.websocket.server.ServerEndpointConfig) HTTPTransportFactory(org.apache.cxf.transport.http.HTTPTransportFactory) ServletConfig(javax.servlet.ServletConfig) ServiceListGeneratorServlet(org.apache.cxf.transport.servlet.servicelist.ServiceListGeneratorServlet) DeploymentException(javax.websocket.DeploymentException) ServletController(org.apache.cxf.transport.servlet.ServletController)

Aggregations

BusException (org.apache.cxf.BusException)28 DestinationFactoryManager (org.apache.cxf.transport.DestinationFactoryManager)7 Test (org.junit.Test)7 IOException (java.io.IOException)6 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)6 EndpointException (org.apache.cxf.endpoint.EndpointException)6 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)6 JaxWsServiceFactoryBean (org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean)5 BindingInfo (org.apache.cxf.service.model.BindingInfo)5 Bus (org.apache.cxf.Bus)4 Message (org.apache.cxf.common.i18n.Message)4 ServiceConstructionException (org.apache.cxf.service.factory.ServiceConstructionException)4 BeanInvoker (org.apache.cxf.service.invoker.BeanInvoker)4 ConduitInitiatorManager (org.apache.cxf.transport.ConduitInitiatorManager)4 DestinationFactory (org.apache.cxf.transport.DestinationFactory)4 WebServiceContext (javax.xml.ws.WebServiceContext)3 BindingFactory (org.apache.cxf.binding.BindingFactory)3 ClassLoaderHolder (org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder)3 Endpoint (org.apache.cxf.endpoint.Endpoint)3 GreeterImpl (org.apache.hello_world_soap_http.GreeterImpl)3