List of usage examples for com.liferay.portal.kernel.util MethodKey getDeclaringClass
public Class<?> getDeclaringClass()
From source file:org.kmworks.liferay.rpc.server.RPCTunnelServlet.java
License:Open Source License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { ObjectInputStream ois;/* w ww. ja v a 2 s . c o m*/ try { ois = new ObjectInputStream(request.getInputStream()); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe, ioe); } return; } Object returnObj = null; boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess(); try { AccessControlThreadLocal.setRemoteAccess(true); Object obj = ois.readObject(); @SuppressWarnings("unchecked") ObjectValuePair<HttpPrincipal, MethodHandler> ovp = (ObjectValuePair<HttpPrincipal, MethodHandler>) obj; //HttpPrincipal principal = ovp.getKey(); // not used here MethodHandler methodHandler = ovp.getValue(); if (methodHandler != null) { MethodKey methodKey = methodHandler.getMethodKey(); if (!isValidRequest(methodKey.getDeclaringClass())) { return; } returnObj = methodHandler.invoke(true); } } catch (InvocationTargetException ite) { returnObj = ite.getCause(); if (!(returnObj instanceof PortalException)) { _log.error(ite, ite); if (returnObj != null) { Throwable throwable = (Throwable) returnObj; returnObj = new SystemException(throwable.getMessage()); } else { returnObj = new SystemException(); } } } catch (Exception e) { _log.error(e, e); } finally { AccessControlThreadLocal.setRemoteAccess(remoteAccess); } if (returnObj != null) { try { try (ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream())) { oos.writeObject(returnObj); oos.flush(); } } catch (IOException ioe) { _log.error(ioe, ioe); throw ioe; } } }
From source file:org.kmworks.portal.rpc.server.RPCTunnelServlet.java
License:Open Source License
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { ClassLoader classLoader = PortalClassLoaderUtil.getClassLoader(); ObjectInputStream ois;/*from w ww. j a v a 2 s .c o m*/ try { ois = new ClassLoaderObjectInputStream(request.getInputStream(), classLoader); } catch (IOException ioe) { if (LOG.isWarnEnabled()) { LOG.warn(ioe, ioe); } return; } Object returnObj = null; boolean remoteAccess = AccessControlThreadLocal.isRemoteAccess(); try { AccessControlThreadLocal.setRemoteAccess(true); Object obj = ois.readObject(); @SuppressWarnings("unchecked") ObjectValuePair<HttpPrincipal, MethodHandler> ovp = (ObjectValuePair<HttpPrincipal, MethodHandler>) obj; //HttpPrincipal principal = ovp.getKey(); MethodHandler methodHandler = ovp.getValue(); if (methodHandler != null) { MethodKey methodKey = methodHandler.getMethodKey(); if (!isValidRequest(methodKey.getDeclaringClass())) { return; } if (isServiceRequest(methodKey.getDeclaringClass())) { // Simulate login PrincipalThreadLocal.setName(ovp.getKey().getLogin()); PrincipalThreadLocal.setPassword(ovp.getKey().getPassword()); } returnObj = methodHandler.invoke(true); } } catch (InvocationTargetException ite) { returnObj = ite.getCause(); if (!(returnObj instanceof PortalException)) { LOG.error(ite, ite); if (returnObj != null) { Throwable throwable = (Throwable) returnObj; returnObj = new SystemException(throwable.getMessage()); } else { returnObj = new SystemException(); } } } catch (Exception e) { LOG.error(e, e); } finally { AccessControlThreadLocal.setRemoteAccess(remoteAccess); } if (returnObj != null) { try { returnObj = makeSerializable(returnObj); try (ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream())) { oos.writeObject(returnObj); oos.flush(); } } catch (Exception ioe) { LOG.error(ioe, ioe); throw ioe; } } }