@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (Object.class.equals(method.getDeclaringClass())) { return method.invoke(this, args); } else { final InvocationHandler invocationHandler = dispatchers.get(method); return invocationHandler.invoke(proxy, method, args); } }
@Override public R invoke(Object proxy, Method invokedMethod, Object[] args) throws Throwable { try { return delegate.invoke(proxy, invokedMethod, args); } catch (TimeoutException timeout) { return null; } }
@Override public R invoke(Object proxy, Method invokedMethod, Object[] args) throws Throwable { try { return delegate.invoke(proxy, invokedMethod, args); } catch (InterruptedException timeout) { Thread.currentThread().interrupt(); return null; } }
private static void checkStub(Remote stub, Class<? extends Remote> stubClass) { // Check remote stub is from the expected class. // if (stub.getClass() != stubClass) { if (!Proxy.isProxyClass(stub.getClass())) { throw new SecurityException("Expecting a " + stubClass.getName() + " stub!"); } else { InvocationHandler handler = Proxy.getInvocationHandler(stub); if (handler.getClass() != RemoteObjectInvocationHandler.class) { throw new SecurityException( "Expecting a dynamic proxy instance with a " + RemoteObjectInvocationHandler.class.getName() + " invocation handler!"); } else { stub = (Remote) handler; } } } // Check RemoteRef in stub is from the expected class // "sun.rmi.server.UnicastRef2". // RemoteRef ref = ((RemoteObject) stub).getRef(); if (ref.getClass() != UnicastRef2.class) { throw new SecurityException( "Expecting a " + UnicastRef2.class.getName() + " remote reference in stub!"); } // Check RMIClientSocketFactory in stub is from the expected class // "javax.rmi.ssl.SslRMIClientSocketFactory". // LiveRef liveRef = ((UnicastRef2) ref).getLiveRef(); RMIClientSocketFactory csf = liveRef.getClientSocketFactory(); if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class) { throw new SecurityException( "Expecting a " + SslRMIClientSocketFactory.class.getName() + " RMI client socket factory in stub!"); } }
@Override public R invoke(Object proxy, Method invokedMethod, Object[] args) throws Throwable { try { return delegate.invoke(proxy, invokedMethod, args); } catch (ExecutionException e) { Throwable cause = e.getCause(); for (Class<?> exception : declaredExceptions) { if (exception.isInstance(cause)) { throw cause; } } throw new CommandExecutionException( "Command execution resulted in a checked exception that was " + "not declared on the gateway", cause); } }
private void process(HttpServletRequest request, HttpServletResponse resp) { AsyncContext asyncContext = request.startAsync(); if (request.getRequestURL().toString().endsWith("/CORS")) { resp.addHeader("Access-Control-Allow-Origin", "*"); resp.addHeader("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE"); resp.addHeader( "Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept"); } // Just ACCEPT and REPLY OK if OPTIONS if (request.getMethod().equals("OPTIONS")) { resp.setStatus(HttpServletResponse.SC_OK); } String fullPath = request.getRequestURI(); fullPath = (fullPath.substring(fullPath.indexOf("/service/") + 9)); String parts[] = fullPath.split("/"); String beanName = parts[0]; String method = parts[1]; String params = request.getParameter("params"); if (request.getMethod().equals("POST")) { try { StringBuilder buffer = new StringBuilder(); BufferedReader reader; reader = request.getReader(); String line; while ((line = reader.readLine()) != null) { buffer.append(line); } params = buffer.toString(); } catch (Exception e) { // TODO: handle exception } } JsonObject paramsObj = CommonUtils.parse(params).getAsJsonObject(); String UID = session.getId(); // (paramsObj.get("sessionUID")).getAsString(); NGSessionScopeContext.setCurrentContext(UID); receiveEvents.fire(new HalfDuplexDataReceivedEvent(paramsObj)); Object result = remoteInvoker.invoke(locator.lookup(beanName, UID), method, paramsObj, UID); try { PrintWriter writer = asyncContext.getResponse().getWriter(); writer.write(util.getJson(result)); writer.flush(); asyncContext.complete(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }