Permalink
Browse files

Avoid proxies and generate whole model from scratch

  • Loading branch information...
topolik committed Jun 16, 2014
1 parent 27bdba8 commit 5ae55f0a5e8d474c3ff4a154eba228087bdb5705
@@ -2,7 +2,8 @@
import com.liferay.portal.kernel.jsonwebservice.JSONWebService;
import com.liferay.portal.service.osgi.cxf.LiferayCXFOSGiServlet;
import com.liferay.portal.service.osgi.wrapper.JaxWsServiceGenerator;
import com.liferay.portal.service.osgi.wrapper.JaxWsServiceFactory;
import com.liferay.portal.service.osgi.wrapper.JaxWsServiceMetadata;
import com.liferay.portal.service.remote.JAXWSService2;
import com.liferay.portal.service.remote.JAXWSServiceImpl2;
import org.apache.cxf.BusFactory;
@@ -25,9 +26,11 @@
import javax.jws.WebService;
import javax.xml.ws.Endpoint;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
* @author Tomas Polesovsky
@@ -39,13 +42,13 @@
// TODO: until we have the right @REMOTE annotation, use JSONWebService annotation
private static final Class PORTAL_REMOTE_SERVICE_ANNOTATION = JSONWebService.class;
private JaxWsServiceGenerator _wrapper;
private JaxWsServiceFactory _serviceFactory;
@Override
public void start(BundleContext bundleContext) throws Exception {
try {
_wrapper = new JaxWsServiceGenerator();
_serviceFactory = new JaxWsServiceFactory();
_bundleContext = bundleContext;
_cxfServlet = new LiferayCXFOSGiServlet();
@@ -88,7 +91,7 @@ public void stop(BundleContext bundleContext) {
}
_httpServer = null;
_wrapper = null;
_serviceFactory = null;
if (_serviceRegistration != null) {
_bundleContext.ungetService(_serviceRegistration.getReference());
@@ -118,9 +121,18 @@ protected void registerPortalService(ServiceReference serviceReference) {
Object webService = service;
if (hasAnnotation(service.getClass(), PORTAL_REMOTE_SERVICE_ANNOTATION)) {
try {
if(counter==100){return;}
webService = _wrapper.wrapPortalService(service);
counter++;
// TODO: remove
if(counter==100){return;}counter++;
HashMap<String, Object> configuration = new HashMap<String, Object>();
JaxWsServiceMetadata metadata = new JaxWsServiceMetadata();
metadata.setService(service);
metadata.setConfiguration(configuration);
for (String key : serviceReference.getPropertyKeys()) {
configuration.put(key, serviceReference.getProperty(key));
}
webService = _serviceFactory.createService(metadata);
} catch (Exception e) {
e.printStackTrace();
return;
@@ -180,7 +192,7 @@ private void unregisterPortalService(ServiceReference serviceReference) {
}
}
_wrapper.detachServiceClass(service.getClass());
_serviceFactory.detachServiceClass(service.getClass());
}
@@ -0,0 +1,89 @@
/**
* Copyright (c) 2000-2014 Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.service.osgi.wrapper;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* @author Tomas Polesovsky
*/
public abstract class ClassWrapper implements Serializable {
public static String generateMethodKey(Method method) {
StringBuilder key = new StringBuilder();
key.append(method.getName());
key.append("(");
for (Class parameterType : method.getParameterTypes()) {
key.append(parameterType.getName());
key.append(",");
}
key.append(") ");
key.append(method.getReturnType().getName());
return key.toString();
}
public void wrapClass(Object originalClass) {
this._wrappedClass = originalClass;
initMethods();
}
public Object invoke(String methodName, Object... args) throws Exception {
Method originalMethod = _methodsIndex.get(methodName);
if (originalMethod == null) {
throw new Exception("Unable to find original method!");
}
Object[] unwrappedArguments = unwrap(args);
Object result = originalMethod.invoke(_wrappedClass, unwrappedArguments);
return wrap(result);
}
protected void initMethods() {
Map methodsIndex = new HashMap();
Method[] methods = _wrappedClass.getClass().getMethods();
for (Method method : methods) {
methodsIndex.put(generateMethodKey(method), method);
}
_methodsIndex = methodsIndex;
}
private Object[] unwrap(Object[] args) {
throw new UnsupportedOperationException("");
}
private Object wrap(Object result) {
throw new UnsupportedOperationException("");
}
private Map<String, Method> _methodsIndex;
private Object _wrappedClass;
}
@@ -0,0 +1,36 @@
/**
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*/
package com.liferay.portal.service.osgi.wrapper;
/**
* @author Tomas Polesovsky
*/
public class IncompatibleMethodException extends Throwable {
public IncompatibleMethodException() {
super();
}
public IncompatibleMethodException(String message) {
super(message);
}
public IncompatibleMethodException(String message, Throwable cause) {
super(message, cause);
}
public IncompatibleMethodException(Throwable cause) {
super(cause);
}
}
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2000-2014 Liferay, Inc. All rights reserved.
* Copyright (c) 2000-present Liferay, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -17,6 +17,20 @@
/**
* @author Tomas Polesovsky
*/
public interface MethodParameterWrapper {
void wrap(Object originalInterfaceInstance);
public class IncompatibleTypeException extends Throwable {
public IncompatibleTypeException() {
super();
}
public IncompatibleTypeException(String message) {
super(message);
}
public IncompatibleTypeException(String message, Throwable cause) {
super(message, cause);
}
public IncompatibleTypeException(Throwable cause) {
super(cause);
}
}
@@ -14,10 +14,24 @@
package com.liferay.portal.service.osgi.wrapper;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
/**
* @author Tomas Polesovsky
*/
public class ServiceWrapper {
public abstract class JaxWsService extends ClassWrapper {
public void setMetadata(JaxWsServiceMetadata metadata) {
this._metadata = metadata;
super.wrapClass(metadata.getService());
}
public JaxWsServiceMetadata getMetadata() {
return _metadata;
}
private JaxWsServiceMetadata _metadata;
}
Oops, something went wrong.

0 comments on commit 5ae55f0

Please sign in to comment.