Example usage for com.liferay.portal.kernel.util MethodHandler getMethodKey

List of usage examples for com.liferay.portal.kernel.util MethodHandler getMethodKey

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util MethodHandler getMethodKey.

Prototype

public MethodKey getMethodKey() 

Source Link

Usage

From source file:com.liferay.exportimport.test.PortletDataContextZipWriterTest.java

License:Open Source License

@Test
public void testMultipleByteArraysAddition() throws Exception {
    byte[] bytes = { Byte.MIN_VALUE, Byte.MAX_VALUE };

    _portletDataContext.addZipEntry(_PATH, bytes);

    List<MethodHandler> methodHandlers = _recorderZipWriter.getMethodHandlers();

    Assert.assertEquals(methodHandlers.toString(), 1, methodHandlers.size());

    MethodHandler methodHandler = methodHandlers.remove(0);

    MethodKey methodKey = methodHandler.getMethodKey();

    Assert.assertEquals(ReflectionTestUtil.getMethod(ZipWriter.class, "addEntry",
            new Class<?>[] { String.class, byte[].class }), methodKey.getMethod());

    Object[] arguments = methodHandler.getArguments();

    Assert.assertEquals(Arrays.toString(arguments), 2, arguments.length);
    Assert.assertSame(_PATH, arguments[0]);
    Assert.assertSame(bytes, arguments[1]);

    _portletDataContext.addZipEntry(_PATH, bytes);

    Assert.assertTrue(methodHandlers.toString(), methodHandlers.isEmpty());
}

From source file:com.liferay.exportimport.test.PortletDataContextZipWriterTest.java

License:Open Source License

@Test
public void testMultipleInputStreamsAddition() throws Exception {
    byte[] bytes = { Byte.MIN_VALUE, Byte.MAX_VALUE };

    InputStream is = new ByteArrayInputStream(bytes);

    _portletDataContext.addZipEntry(_PATH, is);

    List<MethodHandler> methodHandlers = _recorderZipWriter.getMethodHandlers();

    Assert.assertEquals(methodHandlers.toString(), 1, methodHandlers.size());

    MethodHandler methodHandler = methodHandlers.remove(0);

    MethodKey methodKey = methodHandler.getMethodKey();

    Assert.assertEquals(ReflectionTestUtil.getMethod(ZipWriter.class, "addEntry",
            new Class<?>[] { String.class, InputStream.class }), methodKey.getMethod());

    Object[] arguments = methodHandler.getArguments();

    Assert.assertEquals(Arrays.toString(arguments), 2, arguments.length);
    Assert.assertSame(_PATH, arguments[0]);
    Assert.assertSame(is, arguments[1]);

    _portletDataContext.addZipEntry(_PATH, is);

    Assert.assertTrue(methodHandlers.toString(), methodHandlers.isEmpty());
}

From source file:com.liferay.exportimport.test.PortletDataContextZipWriterTest.java

License:Open Source License

@Test
public void testMultipleStringsAddition() throws Exception {
    String string = RandomTestUtil.randomString();

    _portletDataContext.addZipEntry(_PATH, string);

    List<MethodHandler> methodHandlers = _recorderZipWriter.getMethodHandlers();

    Assert.assertEquals(methodHandlers.toString(), 1, methodHandlers.size());

    MethodHandler methodHandler = methodHandlers.remove(0);

    MethodKey methodKey = methodHandler.getMethodKey();

    Assert.assertEquals(ReflectionTestUtil.getMethod(ZipWriter.class, "addEntry",
            new Class<?>[] { String.class, String.class }), methodKey.getMethod());

    Object[] arguments = methodHandler.getArguments();

    Assert.assertEquals(Arrays.toString(arguments), 2, arguments.length);
    Assert.assertSame(_PATH, arguments[0]);
    Assert.assertSame(string, arguments[1]);

    _portletDataContext.addZipEntry(_PATH, string);

    Assert.assertTrue(methodHandlers.toString(), methodHandlers.isEmpty());
}

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;/*  ww  w. j a v a  2 s.  c om*/

    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;/*  w ww  . jav a2s.  c om*/
    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;
        }
    }
}