Author: alessio.soldano(a)jboss.com
Date: 2013-02-15 09:14:38 -0500 (Fri, 15 Feb 2013)
New Revision: 518
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodPreview.java
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/impl/reflection/EndpointMethodCaller.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/basic/WiseIntegrationBasicTest.java
Log:
[WISE-185] Request message preview + minor improvement in EndpointMethodCaller
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-02-10
16:32:46 UTC (rev 517)
+++ core/trunk/core/src/main/java/org/jboss/wise/core/client/WSMethod.java 2013-02-15
14:14:38 UTC (rev 518)
@@ -21,6 +21,7 @@
*/
package org.jboss.wise.core.client;
+import java.io.OutputStream;
import java.util.Map;
import net.jcip.annotations.ThreadSafe;
import org.jboss.wise.core.exception.InvocationException;
@@ -84,6 +85,16 @@
* @throws MappingException
*/
public InvocationResult invoke(Object args) throws InvocationException,
IllegalArgumentException, MappingException;
+
+ /**
+ * Generates and writes a preview of the request message for invoking this
+ * method with the provided arguments.
+ *
+ * @param args
+ * @param os
+ * @throws InvocationException
+ */
+ public void writeRequestPreview(Map<String, Object> args, OutputStream os)
throws InvocationException;
/**
* Gets the map of {@link WebParameter} for the webserice method represented
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodCaller.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodCaller.java 2013-02-10
16:32:46 UTC (rev 517)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodCaller.java 2013-02-15
14:14:38 UTC (rev 518)
@@ -25,6 +25,7 @@
import java.util.List;
import java.util.concurrent.Callable;
+import javax.xml.ws.Binding;
import javax.xml.ws.BindingProvider;
import javax.xml.ws.handler.Handler;
@@ -33,7 +34,7 @@
public class EndpointMethodCaller implements Callable<Object> {
- private final ThreadLocal<Object> epUnderlyingObjectInstance = new
ThreadLocal<Object>() {
+ protected final ThreadLocal<Object> epUnderlyingObjectInstance = new
ThreadLocal<Object>() {
@Override
protected Object initialValue() {
return epInstance.createInstance();
@@ -74,21 +75,23 @@
public void visitEnabler() {
if (epInstance.getExtensions() != null) {
+ Object obj = epUnderlyingObjectInstance.get();
for (WSExtensionEnabler enabler : epInstance.getExtensions()) {
- enabler.enable(epUnderlyingObjectInstance.get());
+ enabler.enable(obj);
}
}
}
public void addHandlers() {
- if (epInstance.getHandlers() != null) {
-
- for (Handler<?> handler : epInstance.getHandlers()) {
- @SuppressWarnings("rawtypes")
- List<Handler> handlerChain =
((BindingProvider)epUnderlyingObjectInstance.get()).getBinding().getHandlerChain();
+ List<Handler<?>> handlers = epInstance.getHandlers();
+ if (handlers != null && !handlers.isEmpty()) {
+ Binding binding =
((BindingProvider)epUnderlyingObjectInstance.get()).getBinding();
+ @SuppressWarnings("rawtypes")
+ List<Handler> handlerChain = binding.getHandlerChain();
+ for (Handler<?> handler : handlers) {
handlerChain.add(handler);
-
((BindingProvider)epUnderlyingObjectInstance.get()).getBinding().setHandlerChain(handlerChain);
}
+ binding.setHandlerChain(handlerChain);
}
}
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodPreview.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodPreview.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/EndpointMethodPreview.java 2013-02-15
14:14:38 UTC (rev 518)
@@ -0,0 +1,107 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2013, Red Hat, Inc., and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This 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 software 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.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.wise.core.client.impl.reflection;
+
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.ws.Binding;
+import javax.xml.ws.BindingProvider;
+import javax.xml.ws.handler.Handler;
+import javax.xml.ws.handler.MessageContext;
+import javax.xml.ws.handler.soap.SOAPHandler;
+import javax.xml.ws.handler.soap.SOAPMessageContext;
+
+import org.jboss.wise.core.client.WSEndpoint;
+
+public class EndpointMethodPreview extends EndpointMethodCaller {
+
+ private final PreviewHandler handler;
+
+ public EndpointMethodPreview( WSEndpoint epInstance,
+ Method methodPointer,
+ Object[] args,
+ OutputStream previewOutputStream) {
+ super(epInstance, methodPointer, args);
+ this.handler = new PreviewHandler(previewOutputStream);
+ }
+
+ @Override
+ public Object call() throws Exception {
+ try {
+ super.call();
+ } catch (Exception e) {
+ //ignore, here we only need to start the invocation so that our handler is
executed
+ }
+ return handler.os;
+ }
+
+ @Override
+ public void addHandlers() {
+ super.addHandlers();
+ Binding binding = ((BindingProvider) epUnderlyingObjectInstance.get()).getBinding();
+ @SuppressWarnings("rawtypes")
+ List<Handler> handlerChain = binding.getHandlerChain();
+ handlerChain.add(handler);
+ binding.setHandlerChain(handlerChain);
+ }
+
+ private class PreviewHandler implements SOAPHandler<SOAPMessageContext> {
+
+ private OutputStream os;
+
+ public PreviewHandler(OutputStream os) {
+ this.os = os;
+ }
+
+ @Override
+ public boolean handleMessage(SOAPMessageContext context) {
+ try {
+ SOAPMessage soapMessage = context.getMessage();
+ soapMessage.writeTo(os);
+ } catch (Exception e) {
+ e.printStackTrace(new PrintStream(os));
+ }
+ return false; //to stop processing handler chain, reverse direction and eventually
get back to caller
+ }
+
+ @Override
+ public boolean handleFault(SOAPMessageContext context) {
+ return true;
+ }
+
+ @Override
+ public void close(MessageContext context) {
+ }
+
+ @Override
+ public Set<QName> getHeaders() {
+ return new HashSet<QName>(); // empty set
+ }
+ }
+}
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-02-10
16:32:46 UTC (rev 517)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/WSMethodImpl.java 2013-02-15
14:14:38 UTC (rev 518)
@@ -21,6 +21,7 @@
*/
package org.jboss.wise.core.client.impl.reflection;
+import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
@@ -72,7 +73,7 @@
* received
*/
InvocationResultImpl invoke(Map<String, Object> args) throws
InvocationException, IllegalArgumentException {
- Method methodPointer = null;
+// Method methodPointer = null;
InvocationResultImpl result = null;
Map<String, Object> emptyHolder = Collections.emptyMap();
@@ -90,15 +91,15 @@
} 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++) {
- Class<?> excType = methodPointer.getExceptionTypes()[i];
- if (ite.getCause().getClass().isAssignableFrom(excType)) {
- result = new InvocationResultImpl("exception", excType, ite.getCause(),
emptyHolder);
- return result;
- }
- }
- }
+// if (methodPointer != null && methodPointer.getExceptionTypes() != null) {
+// for (int i = 0; i < methodPointer.getExceptionTypes().length; i++) {
+// Class<?> excType = methodPointer.getExceptionTypes()[i];
+// if (ite.getCause().getClass().isAssignableFrom(excType)) {
+// result = new InvocationResultImpl("exception", excType, ite.getCause(),
emptyHolder);
+// return result;
+// }
+// }
+// }
throw new InvocationException("Unknown exception received: " +
ite.getMessage(), ite);
} catch (Throwable e) {
throw new InvocationException("Generic Error during method invocation!",
e);
@@ -106,6 +107,19 @@
return result;
}
+ @Override
+ public void writeRequestPreview(Map<String, Object> args, OutputStream os)
throws InvocationException {
+ try {
+ EndpointMethodPreview caller = new EndpointMethodPreview(this.getEndpoint(),
this.getMethod(), this
+ .getParmeterInRightPositionArray(args), os);
+ ((WSEndpointImpl) this.getEndpoint()).getService().submit(caller).get();
+ } catch (Exception ite) {
+ throw new InvocationException("Unknown exception received: " +
ite.getMessage(), ite);
+ } catch (Throwable e) {
+ throw new InvocationException("Generic Error during method invocation!",
e);
+ }
+ }
+
/**
* Invokes this method with the provided arguments applying provided mapper
*
Modified:
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/basic/WiseIntegrationBasicTest.java
===================================================================
---
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/basic/WiseIntegrationBasicTest.java 2013-02-10
16:32:46 UTC (rev 517)
+++
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/basic/WiseIntegrationBasicTest.java 2013-02-15
14:14:38 UTC (rev 518)
@@ -21,6 +21,7 @@
*/
package org.jboss.wise.test.integration.basic;
+import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.util.Map;
@@ -55,6 +56,9 @@
WSMethod method = client.getWSMethod("HelloService",
"HelloWorldBeanPort", "echo");
Map<String, Object> args = new java.util.HashMap<String, Object>();
args.put("arg0", "from-wise-client");
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ method.writeRequestPreview(args, bos);
+ Assert.assertTrue(bos.toString().contains("<arg0>from-wise-client</arg0>"));
InvocationResult result = method.invoke(args, null);
Map<String, Object> res = result.getMapRequestAndResult(null, null);
Map<String, Object> test = (Map<String, Object>)
res.get("results");