use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.
the class RestServer method registerProcessor.
@Override
public void registerProcessor(ProviderConfig providerConfig, Invoker instance) {
if (!isStarted()) {
start();
}
// 在httpserver中注册此jaxrs服务
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Register jaxrs service to base url http://" + serverConfig.getHost() + ":" + serverConfig.getPort() + serverConfig.getContextPath());
}
Object obj = null;
try {
obj = ProxyFactory.buildProxy(providerConfig.getProxy(), providerConfig.getProxyClass(), instance);
httpServer.getDeployment().getRegistry().addResourceFactory(new SofaResourceFactory(providerConfig, obj), serverConfig.getContextPath());
invokerCnt.incrementAndGet();
} catch (SofaRpcRuntimeException e) {
LOGGER.error(LogCodes.getLog(LogCodes.ERROR_REGISTER_PROCESSOR_TO_SERVER, "restServer"), e);
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_REGISTER_PROCESSOR_TO_SERVER, "restServer"), e);
}
}
use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.
the class SslContextBuilder method build.
public static SslContext build() {
// Configure SSL.
SslContext sslCtx;
try {
if (SSL) {
SslProvider provider = OpenSsl.isAlpnSupported() ? SslProvider.OPENSSL : SslProvider.JDK;
SelfSignedCer ssc = new SelfSignedCer(CERTIFICATE_PATH, PRIVATE_KEY_PATH);
sslCtx = io.netty.handler.ssl.SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey()).sslProvider(provider).ciphers(Http2SecurityUtil.CIPHERS, SupportedCipherSuiteFilter.INSTANCE).applicationProtocolConfig(new ApplicationProtocolConfig(ApplicationProtocolConfig.Protocol.ALPN, // NO_ADVERTISE is currently the only mode supported by both OpenSsl and JDK providers.
ApplicationProtocolConfig.SelectorFailureBehavior.NO_ADVERTISE, // ACCEPT is currently the only mode supported by both OpenSsl and JDK providers.
ApplicationProtocolConfig.SelectedListenerFailureBehavior.ACCEPT, ApplicationProtocolNames.HTTP_2, ApplicationProtocolNames.HTTP_1_1)).build();
} else {
sslCtx = null;
}
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Exception e) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_START_SERVER, "HTTP/2"), e);
}
return sslCtx;
}
use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.
the class DefaultProviderBootstrap method register.
/**
* 注册服务
*/
protected void register() {
if (providerConfig.isRegister()) {
List<RegistryConfig> registryConfigs = providerConfig.getRegistry();
if (registryConfigs != null) {
for (RegistryConfig registryConfig : registryConfigs) {
Registry registry = RegistryFactory.getRegistry(registryConfig);
registry.init();
registry.start();
try {
registry.register(providerConfig);
} catch (SofaRpcRuntimeException e) {
throw e;
} catch (Throwable e) {
String appName = providerConfig.getAppName();
if (LOGGER.isWarnEnabled(appName)) {
LOGGER.errorWithApp(appName, LogCodes.getLog(LogCodes.ERROR_REGISTER_TO_REGISTRY, registryConfig.getId()), e);
}
}
}
}
}
}
use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.
the class ProtostuffHelper method loadProtoClassToCache.
/**
* 加载protobuf接口里方法的参数和返回值类型到缓存,不需要传递
*
* @param key 缓存的key
* @param clazz 接口名
* @param methodName 方法名
*/
private void loadProtoClassToCache(String key, Class clazz, String methodName) {
Method pbMethod = null;
Method[] methods = clazz.getMethods();
for (Method method : methods) {
if (methodName.equals(method.getName())) {
pbMethod = method;
break;
}
}
if (pbMethod == null) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_METHOD_NOT_FOUND, clazz.getName(), methodName));
}
Class[] parameterTypes = pbMethod.getParameterTypes();
if (parameterTypes == null || parameterTypes.length != 1) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_ONLY_ONE_PARAM, "protobuf", clazz.getName()));
}
Class reqClass = parameterTypes[0];
requestClassCache.put(key, reqClass);
Class resClass = pbMethod.getReturnType();
if (resClass == void.class) {
throw new SofaRpcRuntimeException(LogCodes.getLog(LogCodes.ERROR_PROTOBUF_RETURN, clazz.getName()));
}
responseClassCache.put(key, resClass);
}
use of com.alipay.sofa.rpc.core.exception.SofaRpcRuntimeException in project sofa-rpc by sofastack.
the class FileUtils method getUserHomeDir.
/**
* 得到USER_HOME目录
*
* @param base 用户目录下文件夹
* @return 得到用户目录
*/
public static String getUserHomeDir(String base) {
String userhome = System.getProperty("user.home");
File file = new File(userhome, base);
if (file.exists()) {
if (!file.isDirectory()) {
// LOGGER.error("{} exists, but not directory", file.getAbsolutePath());
throw new SofaRpcRuntimeException(file.getAbsolutePath() + " exists, but not directory");
}
} else {
// 可能创建不成功
file.mkdirs();
}
return file.getAbsolutePath();
}
Aggregations