Used to export a proxy that does not expose any internals but just + * a specific interface intended for remote access. + * + * @return the proxy + * @see #setServiceInterface + * @see #setService + */ + protected Object getProxyForService() { + Object targetService = getService(); + if (targetService == null) { + throw new IllegalArgumentException("Property 'service' is required"); + } + checkServiceInterface(); + + ProxyFactory proxyFactory = new ProxyFactory(); + proxyFactory.addInterface(getServiceInterface()); + proxyFactory.setTarget(targetService); + proxyFactory.setOpaque(true); + + return proxyFactory.getProxy(ClassUtils.getDefaultClassLoader()); + } } diff --git a/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceExporter.java b/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceExporter.java index 1e27c798..83e9c7a9 100644 --- a/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceExporter.java +++ b/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceExporter.java @@ -44,7 +44,6 @@ public class AutoJsonRpcServiceExporter implements BeanFactoryPostProcessor { private ObjectMapper objectMapper; private ErrorResolver errorResolver = null; - private Boolean registerTraceInterceptor; private boolean backwardsCompatible = true; private boolean rethrowExceptions = false; private boolean allowExtraParams = false; @@ -141,10 +140,6 @@ private void registerServiceProxy(DefaultListableBeanFactory defaultListableBean builder.addPropertyValue("invocationListener", invocationListener); } - if (registerTraceInterceptor != null) { - builder.addPropertyValue("registerTraceInterceptor", registerTraceInterceptor); - } - if (httpStatusCodeProvider != null) { builder.addPropertyValue("httpStatusCodeProvider", httpStatusCodeProvider); } @@ -225,12 +220,16 @@ public void setAllowLessParams(boolean allowLessParams) { } /** - * See {@link org.springframework.remoting.support.RemoteExporter#setRegisterTraceInterceptor(boolean)} + * See {@code org.springframework.remoting.support.RemoteExporter#setRegisterTraceInterceptor(boolean)} + *
+ * Note: this method is deprecated and marked for removal. + * {@code RemoteExporter} and {@code TraceInterceptor-s} are no longer supported. * * @param registerTraceInterceptor the registerTraceInterceptor value to set */ + @Deprecated public void setRegisterTraceInterceptor(boolean registerTraceInterceptor) { - this.registerTraceInterceptor = registerTraceInterceptor; + // NOOP } /** diff --git a/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceImplExporter.java b/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceImplExporter.java index db9cad1a..ad355395 100644 --- a/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceImplExporter.java +++ b/src/main/java/com/googlecode/jsonrpc4j/spring/AutoJsonRpcServiceImplExporter.java @@ -50,7 +50,6 @@ public class AutoJsonRpcServiceImplExporter implements BeanFactoryPostProcessor private ObjectMapper objectMapper; private ErrorResolver errorResolver = null; - private Boolean registerTraceInterceptor; private boolean backwardsCompatible = true; private boolean rethrowExceptions = false; private boolean allowExtraParams = false; @@ -181,11 +180,7 @@ private void registerServiceProxy(DefaultListableBeanFactory defaultListableBean if (invocationListener != null) { builder.addPropertyValue("invocationListener", invocationListener); } - - if (registerTraceInterceptor != null) { - builder.addPropertyValue("registerTraceInterceptor", registerTraceInterceptor); - } - + if (httpStatusCodeProvider != null) { builder.addPropertyValue("httpStatusCodeProvider", httpStatusCodeProvider); } @@ -280,14 +275,18 @@ public void setAllowExtraParams(boolean allowExtraParams) { public void setAllowLessParams(boolean allowLessParams) { this.allowLessParams = allowLessParams; } - + /** - * See {@link org.springframework.remoting.support.RemoteExporter#setRegisterTraceInterceptor(boolean)} + * See {@code org.springframework.remoting.support.RemoteExporter#setRegisterTraceInterceptor(boolean)} + *
+ * Note: this method is deprecated and marked for removal.
+ * {@code RemoteExporter} and {@code TraceInterceptor-s} are no longer supported.
*
* @param registerTraceInterceptor the registerTraceInterceptor value to set
*/
+ @Deprecated
public void setRegisterTraceInterceptor(boolean registerTraceInterceptor) {
- this.registerTraceInterceptor = registerTraceInterceptor;
+ // NOOP
}
/**
diff --git a/src/main/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporter.java b/src/main/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporter.java
index 7bc2ab53..e43cd1ac 100644
--- a/src/main/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporter.java
+++ b/src/main/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporter.java
@@ -9,10 +9,7 @@
import java.io.IOException;
/**
- * {@link HttpRequestHandler} that exports services using Json
- * according to the JSON-RPC proposal specified at:
- *
- * http://groups.google.com/group/json-rpc.
+ * {@link HttpRequestHandler} that exports user services using JSON-RPC over HTTP protocol
*/
public class JsonServiceExporter extends AbstractJsonServiceExporter implements HttpRequestHandler {
diff --git a/src/main/java/com/googlecode/jsonrpc4j/spring/JsonStreamServiceExporter.java b/src/main/java/com/googlecode/jsonrpc4j/spring/JsonStreamServiceExporter.java
index ae62351e..7469c469 100644
--- a/src/main/java/com/googlecode/jsonrpc4j/spring/JsonStreamServiceExporter.java
+++ b/src/main/java/com/googlecode/jsonrpc4j/spring/JsonStreamServiceExporter.java
@@ -11,11 +11,7 @@
/**
- * {@link org.springframework.remoting.support.RemoteExporter RemoteExporter}
- * that exports services using Json according to the JSON-RPC proposal specified
- * at:
- *
- * http://groups.google.com/group/json-rpc.
+ * Exports user defined services as streaming server, which provides JSON-RPC over sockets.
*/
@SuppressWarnings("unused")
public class JsonStreamServiceExporter extends AbstractJsonServiceExporter implements DisposableBean {
diff --git a/src/test/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporterIntegrationTest.java b/src/test/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporterIntegrationTest.java
new file mode 100644
index 00000000..dfd36248
--- /dev/null
+++ b/src/test/java/com/googlecode/jsonrpc4j/spring/JsonServiceExporterIntegrationTest.java
@@ -0,0 +1,53 @@
+package com.googlecode.jsonrpc4j.spring;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.ApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+
+import com.googlecode.jsonrpc4j.spring.service.Service;
+import com.googlecode.jsonrpc4j.spring.service.ServiceImpl;
+
+import static org.junit.Assert.*;
+
+/**
+ * This test ensures that {@link com.googlecode.jsonrpc4j.spring.JsonServiceExporter} bean is
+ * constructed according to Spring Framework configuration.
+ */
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration("classpath:serverApplicationContextC.xml")
+public class JsonServiceExporterIntegrationTest {
+
+ private static final String BEAN_NAME_AND_URL_PATH = "/UserService.json";
+
+ @Autowired
+ private ApplicationContext applicationContext;
+
+ @Test
+ public void testExportedService() {
+ assertNotNull(applicationContext);
+
+ // check that the bean was only exported on the configured path.
+ {
+ Object bean = applicationContext.getBean(BEAN_NAME_AND_URL_PATH);
+ assertEquals(JsonServiceExporter.class, bean.getClass());
+
+ String[] names = applicationContext.getBeanNamesForType(JsonServiceExporter.class);
+ assertNotNull(names);
+ assertEquals(1, names.length);
+ assertEquals(BEAN_NAME_AND_URL_PATH, names[0]);
+ }
+
+ // check that service classes were also successfully configured in the context.
+
+ {
+ Service service = applicationContext.getBean(Service.class);
+ assertTrue(service instanceof ServiceImpl);
+
+ ServiceImpl serviceImpl = applicationContext.getBean(ServiceImpl.class);
+ assertNotNull(serviceImpl);
+ }
+ }
+}
diff --git a/src/test/resources/serverApplicationContextC.xml b/src/test/resources/serverApplicationContextC.xml
new file mode 100644
index 00000000..ed2c0156
--- /dev/null
+++ b/src/test/resources/serverApplicationContextC.xml
@@ -0,0 +1,14 @@
+