8017505: Better Client Service

Reviewed-by: mullan, ahgross, mgrebac
This commit is contained in:
Miroslav Kos 2013-08-01 16:09:17 -04:00
parent 6412341d45
commit b520de4e1e
7 changed files with 309 additions and 10 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -66,7 +66,7 @@ public abstract class AbstractInstanceResolver<T> extends InstanceResolver<T> {
if (!method.isAccessible()) {
method.setAccessible(true);
}
method.invoke(instance,args);
MethodUtil.invoke(instance,method, args);
} catch (IllegalAccessException e) {
throw new ServerRtException("server.rt.err",e);
} catch (InvocationTargetException e) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -232,7 +232,7 @@ public abstract class InstanceResolver<T> {
public Object invoke(Packet p, Method m, Object... args) throws InvocationTargetException, IllegalAccessException {
T t = resolve(p);
try {
return m.invoke(t, args );
return MethodUtil.invoke(t, m, args );
} finally {
postInvoke(p,t);
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.ws.api.server;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utility class to invoke sun.reflect.misc.MethodUtil.invoke() if available. If not (other then Oracle JDK) fallbacks
* to java.lang,reflect.Method.invoke()
*
* Be careful, copy of this class exists in several packages, iny modification must be done to other copies too!
*/
class MethodUtil {
private static final Logger LOGGER = Logger.getLogger(MethodUtil.class.getName());
private static final Method INVOKE_METHOD;
static {
Method method;
try {
Class<?> clazz = Class.forName("sun.reflect.misc.MethodUtil");
method = clazz.getMethod("invoke", Method.class, Object.class, Object[].class);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil found; it will be used to invoke methods.");
}
} catch (Throwable t) {
method = null;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil not found, probably non-Oracle JVM");
}
}
INVOKE_METHOD = method;
}
static Object invoke(Object target, Method method, Object[] args) throws IllegalAccessException, InvocationTargetException {
if (INVOKE_METHOD != null) {
// sun.reflect.misc.MethodUtil.invoke(method, owner, args)
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method using sun.reflect.misc.MethodUtil");
}
try {
return INVOKE_METHOD.invoke(null, method, target, args);
} catch (InvocationTargetException ite) {
// unwrap invocation exception added by reflection code ...
throw unwrapException(ite);
}
} else {
// other then Oracle JDK ...
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method directly, probably non-Oracle JVM");
}
return method.invoke(target, args);
}
}
private static InvocationTargetException unwrapException(InvocationTargetException ite) {
Throwable targetException = ite.getTargetException();
if (targetException != null && targetException instanceof InvocationTargetException) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Unwrapping invocation target exception");
}
return (InvocationTargetException) targetException;
} else {
return ite;
}
}
}

View File

@ -0,0 +1,94 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.ws.client.sei;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utility class to invoke sun.reflect.misc.MethodUtil.invoke() if available. If not (other then Oracle JDK) fallbacks
* to java.lang,reflect.Method.invoke()
* <p/>
* Be careful, copy of this class exists in several packages, iny modification must be done to other copies too!
*/
class MethodUtil {
private static final Logger LOGGER = Logger.getLogger(MethodUtil.class.getName());
private static final Method INVOKE_METHOD;
static {
Method method;
try {
Class<?> clazz = Class.forName("sun.reflect.misc.MethodUtil");
method = clazz.getMethod("invoke", Method.class, Object.class, Object[].class);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil found; it will be used to invoke methods.");
}
} catch (Throwable t) {
method = null;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil not found, probably non-Oracle JVM");
}
}
INVOKE_METHOD = method;
}
static Object invoke(Object target, Method method, Object[] args) throws IllegalAccessException, InvocationTargetException {
if (INVOKE_METHOD != null) {
// sun.reflect.misc.MethodUtil.invoke(method, owner, args)
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method using sun.reflect.misc.MethodUtil");
}
try {
return INVOKE_METHOD.invoke(null, method, target, args);
} catch (InvocationTargetException ite) {
// unwrap invocation exception added by reflection code ...
throw unwrapException(ite);
}
} else {
// other then Oracle JDK ...
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method directly, probably non-Oracle JVM");
}
return method.invoke(target, args);
}
}
private static InvocationTargetException unwrapException(InvocationTargetException ite) {
Throwable targetException = ite.getTargetException();
if (targetException != null && targetException instanceof InvocationTargetException) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Unwrapping invocation target exception");
}
return (InvocationTargetException) targetException;
} else {
return ite;
}
}
}

View File

@ -28,6 +28,7 @@ package com.sun.xml.internal.ws.client.sei;
import com.sun.istack.internal.NotNull;
import com.sun.istack.internal.Nullable;
import com.sun.xml.internal.ws.api.SOAPVersion;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
import com.sun.xml.internal.ws.api.client.WSPortInfo;
import com.sun.xml.internal.ws.api.databinding.Databinding;
import com.sun.xml.internal.ws.api.addressing.WSEndpointReference;
@ -36,12 +37,16 @@ import com.sun.xml.internal.ws.api.message.Headers;
import com.sun.xml.internal.ws.api.message.Packet;
import com.sun.xml.internal.ws.api.model.MEP;
import com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.pipe.Fiber;
import com.sun.xml.internal.ws.api.pipe.Tube;
import com.sun.xml.internal.ws.api.server.Container;
import com.sun.xml.internal.ws.api.server.ContainerResolver;
import com.sun.xml.internal.ws.binding.BindingImpl;
import com.sun.xml.internal.ws.client.*;
import com.sun.xml.internal.ws.client.AsyncResponseImpl;
import com.sun.xml.internal.ws.client.RequestContext;
import com.sun.xml.internal.ws.client.ResponseContextReceiver;
import com.sun.xml.internal.ws.client.Stub;
import com.sun.xml.internal.ws.client.WSServiceDelegate;
import com.sun.xml.internal.ws.model.JavaMethodImpl;
import com.sun.xml.internal.ws.model.SOAPSEIModel;
import com.sun.xml.internal.ws.wsdl.OperationDispatcher;
@ -50,6 +55,8 @@ import javax.xml.namespace.QName;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.util.HashMap;
import java.util.Map;
@ -132,6 +139,7 @@ public final class SEIStub extends Stub implements InvocationHandler {
private final Map<Method, MethodHandler> methodHandlers = new HashMap<Method, MethodHandler>();
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
validateInputs(proxy, method);
Container old = ContainerResolver.getDefault().enterContainer(owner.getContainer());
try {
MethodHandler handler = methodHandlers.get(method);
@ -155,6 +163,17 @@ public final class SEIStub extends Stub implements InvocationHandler {
}
}
private void validateInputs(Object proxy, Method method) {
if (proxy == null || !Proxy.isProxyClass(proxy.getClass())) {
throw new IllegalStateException("Passed object is not proxy!");
}
Class<?> declaringClass = method.getDeclaringClass();
if (method == null || declaringClass == null
|| Modifier.isStatic(method.getModifiers())) {
throw new IllegalStateException("Invoking static method is not allowed!");
}
}
public final Packet doProcess(Packet request, RequestContext rc, ResponseContextReceiver receiver) {
return super.process(request, rc, receiver);
}

View File

@ -0,0 +1,92 @@
/*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code 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 General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.sun.xml.internal.ws.policy.privateutil;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* Utility class to invoke sun.reflect.misc.MethodUtil.invoke() if available. If not (other then Oracle JDK) fallbacks
* to java.lang,reflect.Method.invoke()
*/
class MethodUtil {
private static final Logger LOGGER = Logger.getLogger(MethodUtil.class.getName());
private static final Method INVOKE_METHOD;
static {
Method method;
try {
Class<?> clazz = Class.forName("sun.reflect.misc.MethodUtil");
method = clazz.getMethod("invoke", Method.class, Object.class, Object[].class);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil found; it will be used to invoke methods.");
}
} catch (Throwable t) {
method = null;
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Class sun.reflect.misc.MethodUtil not found, probably non-Oracle JVM");
}
}
INVOKE_METHOD = method;
}
static Object invoke(Object target, Method method, Object[] args) throws IllegalAccessException, InvocationTargetException {
if (INVOKE_METHOD != null) {
// sun.reflect.misc.MethodUtil.invoke(method, owner, args)
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method using sun.reflect.misc.MethodUtil");
}
try {
return INVOKE_METHOD.invoke(null, method, target, args);
} catch (InvocationTargetException ite) {
// unwrap invocation exception added by reflection code ...
throw unwrapException(ite);
}
} else {
// other then Oracle JDK ...
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Invoking method directly, probably non-Oracle JVM");
}
return method.invoke(target, args);
}
}
private static InvocationTargetException unwrapException(InvocationTargetException ite) {
Throwable targetException = ite.getTargetException();
if (targetException != null && targetException instanceof InvocationTargetException) {
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Unwrapping invocation target exception");
}
return (InvocationTargetException) targetException;
} else {
return ite;
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -282,13 +282,13 @@ public final class PolicyUtils {
/**
* Reflection utilities wrapper
*/
public static class Reflection {
static class Reflection {
private static final PolicyLogger LOGGER = PolicyLogger.getLogger(PolicyUtils.Reflection.class);
/**
* Reflectively invokes specified method on the specified target
*/
public static <T> T invoke(final Object target, final String methodName,
static <T> T invoke(final Object target, final String methodName,
final Class<T> resultClass, final Object... parameters) throws RuntimePolicyUtilsException {
Class[] parameterTypes;
if (parameters != null && parameters.length > 0) {
@ -311,7 +311,7 @@ public final class PolicyUtils {
final Object[] parameters, final Class[] parameterTypes) throws RuntimePolicyUtilsException {
try {
final Method method = target.getClass().getMethod(methodName, parameterTypes);
final Object result = method.invoke(target, parameters);
final Object result = MethodUtil.invoke(target, method,parameters);
return resultClass.cast(result);
} catch (IllegalArgumentException e) {