public static void convertAllArgs(MethodCall call) { Object[] args = call.getArgs(); List<String> classes = call.getClasses(); Preconditions.checkArgument(args.length == classes.size()); for (int i = 0; i < args.length; i++) { args[i] = convertArgument(classes.get(i), args[i]); } }
private static List<String> getRealClassImplementation(Method method, Object[] args) { if (args == null) { return Collections.emptyList(); } List<String> argClasses = new ArrayList<String>(args.length); for (int i = 0; i < args.length; i++) { argClasses.add(getArgumentClass(method, args[i], i)); } return argClasses; }
public MethodCall(String methodName, Object[] args, Map<String, String> metaData) { this(methodName, args, metaData, null); classes = getRealClassImplementation(); }
@Override public MethodResultMessage doFilter(MethodCallRequest input, Map<String, Object> metadata) throws FilterException { LOGGER.debug("entered EKBProxyOutgoingFilter"); Object[] parameters = input.getMethodCall().getArgs(); if (parameters != null) { List<String> classes = input.getMethodCall().getClasses(); List<String> newClasses = new ArrayList<String>(); input.getMethodCall().setArgs(parameters); input.getMethodCall().setClasses(newClasses);
public List<String> getRealClassImplementation() { List<String> argsClasses = new ArrayList<String>(); if (getArgs() != null) { for (Object object : getArgs()) { if (object == null) { argsClasses.add(null); } else if (object instanceof List<?>) { argsClasses.add(List.class.getName()); } else { argsClasses.add(object.getClass().getName()); } } } return argsClasses; }
public static void sendRemoteEvent(String portId, String destination, RemoteEvent e, Map<String, String> metaData) throws PortNotAvailableException { MethodCall methodCall = new MethodCall("processRemoteEvent", new Object[]{ e }, metaData); OutgoingPortUtilService portUtilService = utilsService.getOsgiServiceProxy(OutgoingPortUtilService.class); portUtilService.sendMethodCall(portId, destination, methodCall); }
private Class<?>[] getArgTypes(MethodCall args) { List<Class<?>> clazzes = new ArrayList<Class<?>>(); for (String clazz : args.getClasses()) { try { clazzes.add(this.getClass().getClassLoader().loadClass(clazz)); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("The classes defined could not be found", e); } } return clazzes.toArray(new Class<?>[0]); }
@Override public MethodResult handleCall(MethodCall call) { Map<String, String> metaData = call.getMetaData(); String contextId = metaData.get("contextId"); if (contextId != null) { ContextHolder.get().setCurrentContextId(contextId); } Object service = retrieveOpenEngSBService(call); Method method = findMethod(service, call.getMethodName(), getArgTypes(call)); Object[] args = retrieveArguments(call, method); MethodResult methodResult = invokeMethod(service, method, args); methodResult.setMetaData(call.getMetaData()); return methodResult; }
private Object retrieveOpenEngSBService(MethodCall call) { Map<String, String> metaData = call.getMetaData(); String serviceId = metaData.get("serviceId"); String filter = metaData.get("serviceFilter"); String filterString = createFilterString(filter, serviceId); return utilsService.getService(filterString); }
@Override public MethodResultMessage doFilter(MethodCallRequest input, Map<String, Object> metadata) throws FilterException { Object[] parameters = input.getMethodCall().getArgs(); LOGGER.debug("entered EKBProxyIncomingFilter"); if (parameters != null) { List<String> classes = input.getMethodCall().getClasses(); List<String> newClasses = new ArrayList<String>(); input.getMethodCall().setArgs(parameters); input.getMethodCall().setClasses(newClasses);
private Object[] retrieveArguments(MethodCall call, Method method) { Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Object[] originalArgs = call.getArgs(); for (int i = 0; i < originalArgs.length; i++) { Annotation[] currentArgAnnotations = parameterAnnotations[i]; Class<? extends CustomJsonMarshaller<?>> transformationAnnotation = searchForTransformationAnnotation(currentArgAnnotations); if (transformationAnnotation == null) { continue; } CustomJsonMarshaller<?> transformationInstance = createTransformationInstance(transformationAnnotation); originalArgs[i] = transformationInstance.transformArg(originalArgs[i]); } return originalArgs; }
public static void sendRemoteEvent(String portId, String destination, RemoteEvent e, Map<String, String> metaData) throws PortNotAvailableException { MethodCall methodCall = new MethodCall("processRemoteEvent", new Object[]{ e }, metaData); OutgoingPortUtilService portUtilService = utilsService.getOsgiServiceProxy(OutgoingPortUtilService.class); portUtilService.sendMethodCall(portId, destination, methodCall); }
private Document serializeRequest(MethodCallRequest result) { DOMResult domResult = new DOMResult(); try { @SuppressWarnings("unchecked") List<Class<?>> classes = ClassUtils.convertClassNamesToClasses(result.getMethodCall().getClasses()); if (classes.contains(null)) { throw new FilterException("Could not load all required classes. Require: " + result.getMethodCall().getClasses() + " got: " + classes); } classes.add(MethodCallRequest.class); JAXBContext jaxbContext = JAXBContext.newInstance(classes.toArray(new Class<?>[classes.size()])); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.marshal(new JAXBElement<MethodCallRequest>(new QName(MethodCallRequest.class.getSimpleName()), MethodCallRequest.class, result), domResult); } catch (JAXBException e) { throw new FilterException(e); } return (Document) domResult.getNode(); }
public static void convertAllArgs(MethodCall call) { Object[] args = call.getArgs(); List<String> classes = call.getClasses(); Preconditions.checkArgument(args.length == classes.size()); for (int i = 0; i < args.length; i++) { args[i] = convertArgument(classes.get(i), args[i]); } }
@Override public Object doInvoke(Object proxy, Method method, Object[] args) throws Throwable { List<Class<?>> paramList = Arrays.asList(method.getParameterTypes()); List<String> paramTypeNames = new ArrayList<String>(); for (Class<?> paramType : paramList) { paramTypeNames.add(paramType.getName()); } MethodCall methodCall = new MethodCall(method.getName(), args, metadata, paramTypeNames); MethodResult callResult = portUtil.sendMethodCallWithResult(portId, destination, methodCall); switch (callResult.getType()) { case Object: return callResult.getArg(); case Void: return null; case Exception: throw new RuntimeException(callResult.getArg().toString()); default: throw new IllegalStateException("Return Type has to be either Void, Object or Exception"); } }
public MethodCall(String methodName, Object[] args, Map<String, String> metaData) { this(methodName, args, metaData, getRealClassImplementation(null, args)); }
private MethodCallRequest parseMethodCall(Document input) throws JAXBException { MethodCallRequest request = unmarshaller.unmarshal(input, MethodCallRequest.class).getValue(); MethodCall result = request.getMethodCall(); List<String> classNames = result.getClasses(); Class<?>[] clazzes = new Class<?>[classNames.size()]; ClassLoader cl = this.getClass().getClassLoader(); for (int i = 0; i < classNames.size(); i++) { try { clazzes[i] = cl.loadClass(classNames.get(i)); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } JAXBContext jaxbContext = JAXBContext.newInstance(clazzes); Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); Object[] args = result.getArgs(); for (int i = 0; i < args.length; i++) { args[i] = unmarshaller.unmarshal((Node) args[i], clazzes[i]).getValue(); } return request; }
public MethodCall(Method method, Object[] args, Map<String, String> metaData) { this(method.getName(), args, metaData, getRealClassImplementation(method, args)); }