Package org.openengsb.core.api.remote

Examples of org.openengsb.core.api.remote.MethodResult


    public void setUp() throws Exception {
        serviceUtils = new DefaultOsgiUtilsService(bundleContext);
        createDomainProviderMock(NullDomain.class, "test");
        createFactoryMock("testc", NullDomainImpl.class, "test");
        callrouter = mock(OutgoingPortUtilService.class);
        MethodResult result = MethodResult.newVoidResult();
        when(callrouter.sendMethodCallWithResult(anyString(), anyString(), any(MethodCall.class))).thenReturn(result);
        registerService(callrouter, new Hashtable<String, Object>(), OutgoingPortUtilService.class);
        registrationManager = new ConnectorRegistrationManager(bundleContext,
                mock(TransformationEngine.class), new ForwardMethodInterceptor(), new SecurityAttributeProviderImpl());
        ProxyConnectorProvider proxyConnectorProvider = new ProxyConnectorProvider();
View Full Code Here


        return (Document) domResult.getNode();
    }

    private MethodResultMessage parseMethodResult(Document input) throws JAXBException {
        MethodResultMessage request = unmarshaller.unmarshal(input, MethodResultMessage.class).getValue();
        MethodResult result = request.getResult();
        Class<?> resultClass;
        try {
            resultClass = Class.forName(result.getClassName());
        } catch (ClassNotFoundException e) {
            throw new FilterException(e);
        }

        JAXBContext jaxbContext = JAXBContext.newInstance(MethodResult.class, resultClass);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        Object parsedArg = unmarshaller.unmarshal((Node) result.getArg(), resultClass).getValue();
        result.setArg(parsedArg);
        return request;
    }
View Full Code Here

            }
            resultMessage = objectMapper.readValue(resultString, MethodResultMessage.class);
        } catch (IOException e) {
            throw new FilterException(e);
        }
        MethodResult result = resultMessage.getResult();
        if (result.getType().equals(ReturnType.Void)) {
            result.setArg(null);
        } else {
            Class<?> resultType;
            try {
                resultType = Class.forName(result.getClassName());
            } catch (ClassNotFoundException e) {
                throw new FilterException(e);
            }
            Object convertedValue = objectMapper.convertValue(result.getArg(), resultType);
            result.setArg(convertedValue);
        }
        return resultMessage;
    }
View Full Code Here

    @Override
    protected MethodResultMessage doFilter(MethodCallMessage input, Map<String, Object> metadata) {
        metadata.put("callId", input.getCallId());
        metadata.put("answer", input.isAnswer());
        MethodResult result = requestHandler.handleCall(input.getMethodCall());
        return new MethodResultMessage(result, input.getCallId());
    }
View Full Code Here

            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;
    }
View Full Code Here

            return String.format("(&%s(%s=%s))", filter, org.osgi.framework.Constants.SERVICE_PID, serviceId);
        }
    }

    private MethodResult invokeMethod(Object service, Method method, Object[] args) {
        MethodResult returnTemplate = new MethodResult();
        try {
            Object result = method.invoke(service, args);
            if (method.getReturnType().getName().equals("void")) {
                returnTemplate.setType(ReturnType.Void);
            } else {
                returnTemplate.setType(ReturnType.Object);
                returnTemplate.setArg(result);
                String resultClassName =
                    result == null ? method.getReturnType().getName() : result.getClass().getName();
                returnTemplate.setClassName(resultClassName);
            }
        } catch (Exception e) {
            LOGGER.warn("Exception in remote method invocation: ", e);
            returnTemplate.setType(ReturnType.Exception);
            if (e.getClass().equals(InvocationTargetException.class)) {
                e = (Exception) e.getCause();
                // if it's not an Exception we are in REAL trouble anyway
            }
            returnTemplate.setArg(e.getCause());
            returnTemplate.setClassName(e.getClass().getName());
        }
        return returnTemplate;
    }
View Full Code Here

TOP

Related Classes of org.openengsb.core.api.remote.MethodResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.