use of com.caucho.hessian.client.HessianProxyFactory in project bamboobsc by billchen198318.
the class HessianServiceProxyAspect method proxyProcess.
private Object proxyProcess(ProceedingJoinPoint pjp) throws AuthorityException, ServiceException, Throwable {
MethodSignature signature = (MethodSignature) pjp.getSignature();
Annotation[] annotations = pjp.getTarget().getClass().getAnnotations();
String serviceId = AspectConstants.getServiceId(annotations);
/**
* 不需要被遠端代理的 service-bean
*/
if (!GreenStepHessianUtils.isProxyServiceId(serviceId)) {
//logger.info( "reject proxy service: " + serviceId );
return pjp.proceed();
}
String userId = StringUtils.defaultString((String) SecurityUtils.getSubject().getPrincipal());
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
/**
* 沒使用者資訊不能處理遠端代理的 service-bean
*/
if (StringUtils.isBlank(userId)) {
logger.warn("no userId");
pjp.proceed();
}
/**
* 此使用者不能存取遠端代理的 service-bean
*/
if (GreenStepHessianUtils.isProxyBlockedAccountId(userId)) {
logger.warn("reject proxy service: " + serviceId + " , blocked userId: " + userId);
return pjp.proceed();
}
}
String serviceInterfacesName = "";
Class<?>[] serviceInterfaces = pjp.getTarget().getClass().getInterfaces();
for (Class<?> clazz : serviceInterfaces) {
if (clazz.getName().indexOf(".service.") > -1) {
serviceInterfacesName = clazz.getName();
}
}
if (StringUtils.isBlank(serviceInterfacesName)) {
logger.error("error no service interface: " + serviceId);
throw new Exception("error no service interface: " + serviceId);
}
String url = GreenStepHessianUtils.getServiceUrl(serviceId);
String theSystemPath = ApplicationSiteUtils.getHost(Constants.getSystem()) + "/" + ApplicationSiteUtils.getContextPath(Constants.getSystem());
/**
* 不要自己呼叫遠端代理的自己, 會造成 HessianServiceProxyAspect 一直重複觸發 (客戶端與server-remote同一台的情況下)
* 如客戶端是 http://127.0.0.1:8080/
* 但是客戶端有開啟 hessian.enable=Y 呼叫遠端代理, 然後遠端url設定為 hessian.serverUrl=http://127.0.0.1:8080/
*
*/
if (url.indexOf(theSystemPath) > -1) {
logger.error("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
throw new Exception("cannot open same-server. now system contextPath = " + theSystemPath + " , but proxy url = " + url);
}
logger.info("proxy url = " + url);
HessianProxyFactory factory = null;
Object proxyServiceObject = null;
if (GreenStepHessianUtils.getConfigHessianHeaderCheckValueModeEnable()) {
// 一般要checkValue模式
factory = new GreenStepHessianProxyFactory();
((GreenStepHessianProxyFactory) factory).setHeaderCheckValue(GreenStepHessianUtils.getEncAuthValue(userId));
proxyServiceObject = ((GreenStepHessianProxyFactory) factory).createForHeaderMode(Class.forName(serviceInterfacesName), url);
} else {
// 不使用checkValue模式
factory = new HessianProxyFactory();
proxyServiceObject = factory.create(Class.forName(serviceInterfacesName), url);
}
Method[] proxyObjectMethods = proxyServiceObject.getClass().getMethods();
Method proxyObjectMethod = null;
if (null == proxyObjectMethods) {
logger.error("error no find proxy method: " + serviceId);
throw new Exception("error no find proxy method: " + serviceId);
}
for (Method m : proxyObjectMethods) {
if (m.getName().equals(signature.getMethod().getName()) && Arrays.equals(m.getParameterTypes(), signature.getMethod().getParameterTypes())) {
proxyObjectMethod = m;
}
}
if (null == proxyObjectMethod) {
logger.error("error no execute proxy method: " + serviceId);
throw new Exception("error no execute proxy method: " + serviceId);
}
Object resultObj = null;
try {
resultObj = proxyObjectMethod.invoke(proxyServiceObject, pjp.getArgs());
this.setReCalculateSizePageOfForPageFindGridResult(resultObj, pjp.getArgs());
} catch (InvocationTargetException e) {
if (e.getMessage() != null) {
throw new ServiceException(e.getMessage().toString());
}
if (e.getTargetException().getMessage() != null) {
throw new ServiceException(e.getTargetException().getMessage().toString());
}
throw e;
} catch (Exception e) {
logger.error(e.getMessage().toString());
throw e;
}
logger.info("proxy success: " + serviceId + " method: " + proxyObjectMethod.getName());
return resultObj;
}
use of com.caucho.hessian.client.HessianProxyFactory in project dubbo by alibaba.
the class HessianProtocol method doRefer.
@SuppressWarnings("unchecked")
protected <T> T doRefer(Class<T> serviceType, URL url) throws RpcException {
HessianProxyFactory hessianProxyFactory = new HessianProxyFactory();
boolean isHessian2Request = url.getParameter(Constants.HESSIAN2_REQUEST_KEY, Constants.DEFAULT_HESSIAN2_REQUEST);
hessianProxyFactory.setHessian2Request(isHessian2Request);
boolean isOverloadEnabled = url.getParameter(Constants.HESSIAN_OVERLOAD_METHOD_KEY, Constants.DEFAULT_HESSIAN_OVERLOAD_METHOD);
hessianProxyFactory.setOverloadEnabled(isOverloadEnabled);
String client = url.getParameter(Constants.CLIENT_KEY, Constants.DEFAULT_HTTP_CLIENT);
if ("httpclient".equals(client)) {
hessianProxyFactory.setConnectionFactory(new HttpClientConnectionFactory());
} else if (client != null && client.length() > 0 && !Constants.DEFAULT_HTTP_CLIENT.equals(client)) {
throw new IllegalStateException("Unsupported http protocol client=\"" + client + "\"!");
}
int timeout = url.getParameter(Constants.TIMEOUT_KEY, Constants.DEFAULT_TIMEOUT);
hessianProxyFactory.setConnectTimeout(timeout);
hessianProxyFactory.setReadTimeout(timeout);
return (T) hessianProxyFactory.create(serviceType, url.setProtocol("http").toJavaURL(), Thread.currentThread().getContextClassLoader());
}
use of com.caucho.hessian.client.HessianProxyFactory in project onebusaway-application-modules by camsys.
the class ServiceInterfaceTest method setup.
@Before
public void setup() throws MalformedURLException {
String port = System.getProperty("org_onebusaway_test_port", "8080");
HessianProxyFactory factory = new HessianProxyFactory();
_service = (FederatedServiceRegistry) factory.create(FederatedServiceRegistry.class, "http://localhost:" + port + "/onebusaway-federations-webapp/remoting/service-registry");
}
use of com.caucho.hessian.client.HessianProxyFactory in project tomee by apache.
the class HessianCdiByConfigTest method client.
@Test
public void client() throws MalformedURLException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final HessianProxyFactory clientFactory = new HessianProxyFactory(loader);
final SerializerFactory factory = new SerializerFactory(loader);
factory.setAllowNonSerializable(true);
clientFactory.setSerializerFactory(factory);
final CdiService client = CdiService.class.cast(clientFactory.create(CdiService.class, "http://127.0.0.1:" + port + "/web/hessian/foo"));
final Out out = client.call(new In("test"));
assertThat(out, instanceOf(Out.class));
assertEquals("test", out.value);
}
use of com.caucho.hessian.client.HessianProxyFactory in project tomee by apache.
the class HessianCdiTest method client.
@Test
public void client() throws MalformedURLException {
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final HessianProxyFactory clientFactory = new HessianProxyFactory(loader);
final SerializerFactory factory = new SerializerFactory(loader);
factory.setAllowNonSerializable(true);
clientFactory.setSerializerFactory(factory);
final CdiService client = CdiService.class.cast(clientFactory.create(CdiService.class, "http://127.0.0.1:" + port + "/web/hessian/service"));
final Out out = client.call(new In("test"));
assertThat(out, instanceOf(Out.class));
assertEquals("test", out.value);
}
Aggregations