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);
}
}
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;
}
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);
}
});
}
Aggregations