Author: alessio.soldano(a)jboss.com
Date: 2013-01-31 12:08:04 -0500 (Thu, 31 Jan 2013)
New Revision: 477
Modified:
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/WSMethod.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImpl.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java
core/trunk/core/src/main/java/org/jboss/wise/core/exception/WiseRuntimeException.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImplTest.java
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/WSMethodImplTest.java
Log:
[WISE-182] Adding result type in result map
Modified: core/trunk/core/src/main/java/org/jboss/wise/core/client/WSMethod.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/client/WSMethod.java 2013-01-30
17:33:57 UTC (rev 476)
+++ core/trunk/core/src/main/java/org/jboss/wise/core/client/WSMethod.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -38,6 +38,9 @@
@ThreadSafe
public interface WSMethod {
+ public static final String RESULT = "result";
+ public static final String TYPE_PREFIX = "type.";
+
/**
* Invokes this method with the provided arguments applying provided mapper
*
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImpl.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImpl.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImpl.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -22,12 +22,14 @@
package org.jboss.wise.core.client.impl.reflection;
+import java.lang.reflect.Type;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import net.jcip.annotations.Immutable;
import net.jcip.annotations.ThreadSafe;
import org.jboss.wise.core.client.InvocationResult;
+import org.jboss.wise.core.client.WSMethod;
import org.jboss.wise.core.exception.MappingException;
import org.jboss.wise.core.mapper.WiseMapper;
@@ -49,7 +51,7 @@
* @param value
* @param results
*/
- public InvocationResultImpl(String name, Object value, Map<String, Object>
results) {
+ public InvocationResultImpl(String name, Type resultType, Object value,
Map<String, Object> results) {
this.originalObjects = new HashMap<String, Object>();
if (results == null) {
@@ -58,6 +60,9 @@
this.originalObjects.putAll(results);
if (name != null && name.trim().length() != 0) {
this.originalObjects.put(name, value);
+ if (resultType != null) {
+ this.originalObjects.put(WSMethod.TYPE_PREFIX + WSMethod.RESULT, resultType);
+ }
}
}
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -50,7 +50,7 @@
@ThreadSafe
@Immutable
public class WSMethodImpl implements WSMethod {
-
+
private final Method method;
private final WSEndpoint endpoint;
@@ -83,19 +83,19 @@
Future<Object> invocation = ((WSEndpointImpl)
this.getEndpoint()).getService().submit(caller);
if (isOneWay()) {
invocation.get();
- result = new InvocationResultImpl(null, null, emptyHolder);
+ result = new InvocationResultImpl(null, null, null, emptyHolder);
} else {
+ result = new InvocationResultImpl(RESULT, method.getGenericReturnType(),
invocation.get(), getHoldersResult(args));
- result = new InvocationResultImpl("result", invocation.get(),
getHoldersResult(args));
-
}
} catch (Exception ite) {
System.out.print("error invoking:" + this.getMethod());
System.out.print("error invoking:" + args.values().toArray());
if (methodPointer != null && methodPointer.getExceptionTypes() != null) {
for (int i = 0; i < methodPointer.getExceptionTypes().length; i++) {
- if
(ite.getCause().getClass().isAssignableFrom(methodPointer.getExceptionTypes()[i])) {
- result = new InvocationResultImpl("exception", ite.getCause(),
emptyHolder);
+ Class<?> excType = methodPointer.getExceptionTypes()[i];
+ if (ite.getCause().getClass().isAssignableFrom(excType)) {
+ result = new InvocationResultImpl("exception", excType, ite.getCause(),
emptyHolder);
return result;
}
}
@@ -201,6 +201,7 @@
WebParameterImpl wisePara = webParams.get(key);
if (wisePara != null && (wisePara.getMode() == WebParam.Mode.INOUT ||
wisePara.getMode() == WebParam.Mode.OUT)) {
holders.put(key, paras.get(key));
+ holders.put(TYPE_PREFIX + key, wisePara.getType());
}
}
return holders;
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/exception/WiseRuntimeException.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/exception/WiseRuntimeException.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/exception/WiseRuntimeException.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -23,7 +23,7 @@
package org.jboss.wise.core.exception;
/**
- * This exception is for connection/authentication failure issues.
+ * Common Wise runtime exception
*
* @author alessio.soldano(a)javalinux.it
*/
Modified:
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImplTest.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImplTest.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/InvocationResultImplTest.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -42,21 +42,21 @@
@Test
public void shoudReturnAnOriginaObjectsEmptyMapIfNameIsNull() throws Exception {
- results = new InvocationResultImpl(null, new Long(1), null);
+ results = new InvocationResultImpl(null, Long.class, new Long(1), null);
Map<String, Object> mappedResult = results.getMapRequestAndResult(null,
null);
assertThat(((Map<?,?>)mappedResult.get("results")).isEmpty(),
is(true));
}
@Test
public void shoudReturnAnOriginaObjectsEmptyMapIfNameIsEmptyString() throws Exception
{
- results = new InvocationResultImpl(" ", new Long(1), null);
+ results = new InvocationResultImpl(" ", Long.class, new Long(1),
null);
Map<String, Object> mappedResult = results.getMapRequestAndResult(null,
null);
assertThat(((Map<?,?>)mappedResult.get("results")).isEmpty(),
is(true));
}
@Test
public void shouldReturnOriginalObjectIfMapperIsNull() throws Exception {
- results = new InvocationResultImpl("result", new Long(1), null);
+ results = new InvocationResultImpl("result", Long.class, new Long(1),
null);
Map<String, Object> mappedResult = results.getMapRequestAndResult(null,
null);
assertThat((Long)((Map<?,?>)mappedResult.get("results")).get("result"),
equalTo(new Long(1)));
@@ -64,7 +64,7 @@
@Test
public void shouldApplyMapping() throws Exception {
- results = new InvocationResultImpl("result", new Long(1), null);
+ results = new InvocationResultImpl("result", Long.class, new Long(1),
null);
WiseMapper mapper = mock(WiseMapper.class);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("result", new Long(2));
@@ -76,7 +76,7 @@
@Test
public void shouldReturnInputObjectAndOriginalObjectIfMapperIsNull() throws Exception
{
- results = new InvocationResultImpl("result", new Long(1), null);
+ results = new InvocationResultImpl("result", Long.class, new Long(1),
null);
Map<String, Object> inputMap = new HashMap<String, Object>();
inputMap.put("origKey", "origValue");
Map<String, Object> mappedResult = results.getMapRequestAndResult(null,
inputMap);
@@ -87,7 +87,7 @@
@Test
public void shouldApplyMappingAndReturnIputMap() throws Exception {
- results = new InvocationResultImpl("result", new Long(1), null);
+ results = new InvocationResultImpl("result", Long.class, new Long(1),
null);
WiseMapper mapper = mock(WiseMapper.class);
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("result", new Long(2));
Modified:
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/WSMethodImplTest.java
===================================================================
---
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/WSMethodImplTest.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core/src/test/java/org/jboss/wise/core/client/impl/reflection/WSMethodImplTest.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -173,6 +173,8 @@
Map<String, Object> results = wsMethod.getHoldersResult(inputMap);
assertThat(results, hasEntry("annotation2", (Object) "foo2"));
assertThat(results, hasEntry("annotation3", (Object) "foo3"));
+ assertThat(results, hasEntry("type.annotation2", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation3", (Object) String.class));
}
@Test
@@ -187,9 +189,11 @@
WSMethodImpl wsMethod = new WSMethodImpl(method, endPointMock);
Map<String, Object> results = wsMethod.getHoldersResult(inputMap);
- assertThat(results.size(), is(2));
+ assertThat(results.size(), is(4));
assertThat(results, hasEntry("annotation2", (Object) "foo2"));
assertThat(results, hasEntry("annotation3", (Object) "foo3"));
+ assertThat(results, hasEntry("type.annotation2", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation3", (Object) String.class));
}
@Test
@@ -204,9 +208,11 @@
WSMethodImpl wsMethod = new WSMethodImpl(method, endPointMock);
Map<String, Object> results = wsMethod.getHoldersResult(inputMap);
- assertThat(results.size(), is(2));
+ assertThat(results.size(), is(4));
assertThat(results, hasEntry("annotation2", (Object) "foo2"));
assertThat(results, hasEntry("annotation3", (Object) "foo3"));
+ assertThat(results, hasEntry("type.annotation2", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation3", (Object) String.class));
}
@Test
@@ -239,11 +245,13 @@
InvocationResult invocationResults = wsMethod.invoke(inputMap);
assertThat(this.methodWorked, is(true));
Map<String, Object> results = (Map) invocationResults.getMapRequestAndResult(null,
null).get("results");
- assertThat(results.size(), is(3));
+ assertThat(results.size(), is(6));
assertThat(results, hasEntry("result", (Object) "great"));
assertThat(results, hasEntry("annotation2", (Object) "foo2"));
assertThat(results, hasEntry("annotation3", (Object) "foo3"));
-
+ assertThat(results, hasEntry("type.result", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation2", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation3", (Object) String.class));
}
@Test
@@ -263,10 +271,14 @@
InvocationResult invocationResults = wsMethod.invoke(inputMap, mapper);
assertThat(this.methodWorked, is(true));
Map<String, Object> results = (Map) invocationResults.getMapRequestAndResult(null,
null).get("results");
- assertThat(results.size(), is(3));
+ assertThat(results.size(), is(6));
assertThat(results, hasEntry("result", (Object) "great"));
assertThat(results, hasEntry("annotation2", (Object) "foo2"));
assertThat(results, hasEntry("annotation3", (Object) "foo3"));
+ assertThat(results, hasEntry("type.result", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation2", (Object) String.class));
+ assertThat(results, hasEntry("type.annotation3", (Object) String.class));
+
}
}
Modified:
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java
===================================================================
---
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java 2013-01-30
17:33:57 UTC (rev 476)
+++
core/trunk/core-cxf/src/main/java/org/jboss/wise/core/client/jaxrs/impl/RSDynamicClientImpl.java 2013-01-31
17:08:04 UTC (rev 477)
@@ -180,7 +180,7 @@
String response = get.getResponseBodyAsString();
responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, null,
response, responseHolder);
// System.out.print(response);
} catch (IOException e) {
@@ -199,7 +199,7 @@
String response = post.getResponseBodyAsString();
responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, null,
response, responseHolder);
// System.out.print(response);
} catch (IOException e) {
@@ -218,7 +218,7 @@
String response = put.getResponseBodyAsString();
responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, null,
response, responseHolder);
// System.out.print(response);
} catch (IOException e) {
@@ -235,7 +235,7 @@
String response = delete.getResponseBodyAsString();
responseHolder.put(InvocationResult.STATUS,
Integer.valueOf(statusCode));
- result = new InvocationResultImpl(InvocationResult.RESPONSE, response,
responseHolder);
+ result = new InvocationResultImpl(InvocationResult.RESPONSE, null,
response, responseHolder);
// System.out.print(response);
} catch (IOException e) {