@Test public void testServiceWithHostName() throws Exception { InputStream stream = getClass().getResourceAsStream("RPCSumServiceWithHostName.xml"); Service service = RPCServices.createFromXml(stream); Map<String, Object> parameters = new HashMap<>(); WriteCache<Map<String, Object>> cache = new WriteCache<>(); WriteCache<Exception> exceptionCache = new WriteCache<>(); parameters.put("a", ValueFactory.newVDouble(10.0)); parameters.put("b", ValueFactory.newVDouble(20.0)); ServiceMethod serviceMethod = service.getServiceMethods().get("sum"); assertNotNull("serviceMethod is null", serviceMethod); Map<String, Object> result = serviceMethod.executeSync(parameters); VDouble vdouble = (VDouble) cache.getValue().get("c"); assertThat(vdouble.getValue(), equalTo(30.0)); }
public static Service createFromXml(InputStream input) { try { if (input == null) { throw new IllegalArgumentException("input stream is not valid: null"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); String ver = xPath.evaluate("/pvAccessRPCService/@ver", document).trim(); String serviceName = xPath.evaluate("/pvAccessRPCService/@name", document).trim(); String serviceDescription = xPath.evaluate("/pvAccessRPCService/@description", document).trim(); if (!ver.equals("1")) { throw new IllegalArgumentException("Unsupported version " + ver); } String channelName = xPath.evaluate("/pvAccessRPCService/channelName/text()", document).trim(); if (channelName.isEmpty()) { throw new IllegalArgumentException("channelName element is missing"); } String poolPropertiesAsText = xPath.evaluate("/pvAccessRPCService/poolproperties/text()", document).trim(); if (!poolPropertiesAsText.isEmpty()) { PooledRPCClientFactory.setPoolConfiguration(poolPropertiesAsText); } String hostName = xPath.evaluate("/pvAccessRPCService/host/text()", document).trim(); if (hostName.isEmpty()) { hostName = null; } String methodFieldName = xPath.evaluate("/pvAccessRPCService/methodFieldName/text()", document).trim(); if (methodFieldName.isEmpty()) { methodFieldName = null; } boolean useNTQuery = false; String useNTQueryStr = xPath.evaluate("/pvAccessRPCService/useNTQuery/text()", document).trim(); if (!useNTQueryStr.isEmpty()) { useNTQuery = Boolean.valueOf(useNTQueryStr); } RPCServiceDescription service = new RPCServiceDescription(serviceName, serviceDescription, hostName, channelName, methodFieldName, useNTQuery); service.executorService(defaultExecutor); NodeList methods = (NodeList) xPath.evaluate("/pvAccessRPCService/methods/method", document, XPathConstants.NODESET); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); String structureId = xPath.evaluate("structureid/text()", method).trim(); String methodName = xPath.evaluate("@name", method).trim(); String methodDescription = xPath.evaluate("@description", method).trim(); String resultName = xPath.evaluate("result/@name", method).trim(); String resultType = xPath.evaluate("result/@type", method).trim(); String resultFieldName = xPath.evaluate("result/@fieldName", method).trim(); if (resultFieldName.isEmpty()) { resultFieldName = null; } String operationName = xPath.evaluate("@operationName", method).trim(); if (operationName.isEmpty()) { operationName = null; } boolean isResultStandalone = Boolean.parseBoolean(xPath.evaluate("result/@standalone", method)); String resultDescription = xPath.evaluate("result/@description", method).trim(); NodeList multipleResultsList = (NodeList) xPath.evaluate("result", method, XPathConstants.NODESET); if ((multipleResultsList != null) && (multipleResultsList.getLength() > 1)) { throw new IllegalArgumentException(methodName + ":The pvAccess RPC rpcservice can only have one result"); } if ((multipleResultsList.getLength() > 0) && !isResultStandalone && resultName.isEmpty()) { throw new IllegalArgumentException("nonstandalone result must be named."); } if (isResultStandalone && resultName.isEmpty()) { resultName = "result"; } RPCServiceMethodDescription pvAccessRPCMethodDescription = new RPCServiceMethodDescription(methodName, methodDescription, operationName, structureId, isResultStandalone); if (!resultName.isEmpty()) { pvAccessRPCMethodDescription.addRPCResult(resultName, resultFieldName, resultDescription, getClassFromString(resultType)); } NodeList arguments = (NodeList) xPath.evaluate("argument", method, XPathConstants.NODESET); for (int nArg = 0; nArg < arguments.getLength(); nArg++) { Node argument = arguments.item(nArg); String argName = xPath.evaluate("@name", argument).trim(); String argDescription = xPath.evaluate("@description", argument).trim(); String argType = xPath.evaluate("@type", argument).trim(); String argFieldName = xPath.evaluate("@fieldName", argument).trim(); if (argFieldName.isEmpty()) { argFieldName = null; } if (!argName.isEmpty()) { pvAccessRPCMethodDescription.addArgument(argName, argFieldName, argDescription, getClassFromString(argType)); } } service.addServiceMethod(pvAccessRPCMethodDescription); } return service.createService(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(RPCServices.class.getName()).log(Level.FINEST, "Couldn't create rpcservice", ex); throw new IllegalArgumentException("Couldn't create rpcservice", ex); } }
RPCServices { public static Service createFromXml(InputStream input) { try { if (input == null) { throw new IllegalArgumentException("input stream is not valid: null"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); String ver = xPath.evaluate("/pvAccessRPCService/@ver", document).trim(); String serviceName = xPath.evaluate("/pvAccessRPCService/@name", document).trim(); String serviceDescription = xPath.evaluate("/pvAccessRPCService/@description", document).trim(); if (!ver.equals("1")) { throw new IllegalArgumentException("Unsupported version " + ver); } String channelName = xPath.evaluate("/pvAccessRPCService/channelName/text()", document).trim(); if (channelName.isEmpty()) { throw new IllegalArgumentException("channelName element is missing"); } String poolPropertiesAsText = xPath.evaluate("/pvAccessRPCService/poolproperties/text()", document).trim(); if (!poolPropertiesAsText.isEmpty()) { PooledRPCClientFactory.setPoolConfiguration(poolPropertiesAsText); } String hostName = xPath.evaluate("/pvAccessRPCService/host/text()", document).trim(); if (hostName.isEmpty()) { hostName = null; } String methodFieldName = xPath.evaluate("/pvAccessRPCService/methodFieldName/text()", document).trim(); if (methodFieldName.isEmpty()) { methodFieldName = null; } boolean useNTQuery = false; String useNTQueryStr = xPath.evaluate("/pvAccessRPCService/useNTQuery/text()", document).trim(); if (!useNTQueryStr.isEmpty()) { useNTQuery = Boolean.valueOf(useNTQueryStr); } RPCServiceDescription service = new RPCServiceDescription(serviceName, serviceDescription, hostName, channelName, methodFieldName, useNTQuery); service.executorService(defaultExecutor); NodeList methods = (NodeList) xPath.evaluate("/pvAccessRPCService/methods/method", document, XPathConstants.NODESET); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); String structureId = xPath.evaluate("structureid/text()", method).trim(); String methodName = xPath.evaluate("@name", method).trim(); String methodDescription = xPath.evaluate("@description", method).trim(); String resultName = xPath.evaluate("result/@name", method).trim(); String resultType = xPath.evaluate("result/@type", method).trim(); String resultFieldName = xPath.evaluate("result/@fieldName", method).trim(); if (resultFieldName.isEmpty()) { resultFieldName = null; } String operationName = xPath.evaluate("@operationName", method).trim(); if (operationName.isEmpty()) { operationName = null; } boolean isResultStandalone = Boolean.parseBoolean(xPath.evaluate("result/@standalone", method)); String resultDescription = xPath.evaluate("result/@description", method).trim(); NodeList multipleResultsList = (NodeList) xPath.evaluate("result", method, XPathConstants.NODESET); if ((multipleResultsList != null) && (multipleResultsList.getLength() > 1)) { throw new IllegalArgumentException(methodName + ":The pvAccess RPC rpcservice can only have one result"); } if ((multipleResultsList.getLength() > 0) && !isResultStandalone && resultName.isEmpty()) { throw new IllegalArgumentException("nonstandalone result must be named."); } if (isResultStandalone && resultName.isEmpty()) { resultName = "result"; } RPCServiceMethodDescription pvAccessRPCMethodDescription = new RPCServiceMethodDescription(methodName, methodDescription, operationName, structureId, isResultStandalone); if (!resultName.isEmpty()) { pvAccessRPCMethodDescription.addRPCResult(resultName, resultFieldName, resultDescription, getClassFromString(resultType)); } NodeList arguments = (NodeList) xPath.evaluate("argument", method, XPathConstants.NODESET); for (int nArg = 0; nArg < arguments.getLength(); nArg++) { Node argument = arguments.item(nArg); String argName = xPath.evaluate("@name", argument).trim(); String argDescription = xPath.evaluate("@description", argument).trim(); String argType = xPath.evaluate("@type", argument).trim(); String argFieldName = xPath.evaluate("@fieldName", argument).trim(); if (argFieldName.isEmpty()) { argFieldName = null; } if (!argName.isEmpty()) { pvAccessRPCMethodDescription.addArgument(argName, argFieldName, argDescription, getClassFromString(argType)); } } service.addServiceMethod(pvAccessRPCMethodDescription); } return service.createService(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(RPCServices.class.getName()).log(Level.FINEST, "Couldn't create rpcservice", ex); throw new IllegalArgumentException("Couldn't create rpcservice", ex); } } }
RPCServices { public static Service createFromXml(InputStream input) { try { if (input == null) { throw new IllegalArgumentException("input stream is not valid: null"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); String ver = xPath.evaluate("/pvAccessRPCService/@ver", document).trim(); String serviceName = xPath.evaluate("/pvAccessRPCService/@name", document).trim(); String serviceDescription = xPath.evaluate("/pvAccessRPCService/@description", document).trim(); if (!ver.equals("1")) { throw new IllegalArgumentException("Unsupported version " + ver); } String channelName = xPath.evaluate("/pvAccessRPCService/channelName/text()", document).trim(); if (channelName.isEmpty()) { throw new IllegalArgumentException("channelName element is missing"); } String poolPropertiesAsText = xPath.evaluate("/pvAccessRPCService/poolproperties/text()", document).trim(); if (!poolPropertiesAsText.isEmpty()) { PooledRPCClientFactory.setPoolConfiguration(poolPropertiesAsText); } String hostName = xPath.evaluate("/pvAccessRPCService/host/text()", document).trim(); if (hostName.isEmpty()) { hostName = null; } String methodFieldName = xPath.evaluate("/pvAccessRPCService/methodFieldName/text()", document).trim(); if (methodFieldName.isEmpty()) { methodFieldName = null; } boolean useNTQuery = false; String useNTQueryStr = xPath.evaluate("/pvAccessRPCService/useNTQuery/text()", document).trim(); if (!useNTQueryStr.isEmpty()) { useNTQuery = Boolean.valueOf(useNTQueryStr); } RPCServiceDescription service = new RPCServiceDescription(serviceName, serviceDescription, hostName, channelName, methodFieldName, useNTQuery); service.executorService(defaultExecutor); NodeList methods = (NodeList) xPath.evaluate("/pvAccessRPCService/methods/method", document, XPathConstants.NODESET); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); String structureId = xPath.evaluate("structureid/text()", method).trim(); String methodName = xPath.evaluate("@name", method).trim(); String methodDescription = xPath.evaluate("@description", method).trim(); String resultName = xPath.evaluate("result/@name", method).trim(); String resultType = xPath.evaluate("result/@type", method).trim(); String resultFieldName = xPath.evaluate("result/@fieldName", method).trim(); if (resultFieldName.isEmpty()) { resultFieldName = null; } String operationName = xPath.evaluate("@operationName", method).trim(); if (operationName.isEmpty()) { operationName = null; } boolean isResultStandalone = Boolean.parseBoolean(xPath.evaluate("result/@standalone", method)); String resultDescription = xPath.evaluate("result/@description", method).trim(); NodeList multipleResultsList = (NodeList) xPath.evaluate("result", method, XPathConstants.NODESET); if ((multipleResultsList != null) && (multipleResultsList.getLength() > 1)) { throw new IllegalArgumentException(methodName + ":The pvAccess RPC rpcservice can only have one result"); } if ((multipleResultsList.getLength() > 0) && !isResultStandalone && resultName.isEmpty()) { throw new IllegalArgumentException("nonstandalone result must be named."); } if (isResultStandalone && resultName.isEmpty()) { resultName = "result"; } RPCServiceMethodDescription pvAccessRPCMethodDescription = new RPCServiceMethodDescription(methodName, methodDescription, operationName, structureId, isResultStandalone); if (!resultName.isEmpty()) { pvAccessRPCMethodDescription.addRPCResult(resultName, resultFieldName, resultDescription, getClassFromString(resultType)); } NodeList arguments = (NodeList) xPath.evaluate("argument", method, XPathConstants.NODESET); for (int nArg = 0; nArg < arguments.getLength(); nArg++) { Node argument = arguments.item(nArg); String argName = xPath.evaluate("@name", argument).trim(); String argDescription = xPath.evaluate("@description", argument).trim(); String argType = xPath.evaluate("@type", argument).trim(); String argFieldName = xPath.evaluate("@fieldName", argument).trim(); if (argFieldName.isEmpty()) { argFieldName = null; } if (!argName.isEmpty()) { pvAccessRPCMethodDescription.addArgument(argName, argFieldName, argDescription, getClassFromString(argType)); } } service.addServiceMethod(pvAccessRPCMethodDescription); } return service.createService(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(RPCServices.class.getName()).log(Level.FINEST, "Couldn't create rpcservice", ex); throw new IllegalArgumentException("Couldn't create rpcservice", ex); } }  }
RPCServices { public static Service createFromXml(InputStream input) { try { if (input == null) { throw new IllegalArgumentException("input stream is not valid: null"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); String ver = xPath.evaluate("/pvAccessRPCService/@ver", document).trim(); String serviceName = xPath.evaluate("/pvAccessRPCService/@name", document).trim(); String serviceDescription = xPath.evaluate("/pvAccessRPCService/@description", document).trim(); if (!ver.equals("1")) { throw new IllegalArgumentException("Unsupported version " + ver); } String channelName = xPath.evaluate("/pvAccessRPCService/channelName/text()", document).trim(); if (channelName.isEmpty()) { throw new IllegalArgumentException("channelName element is missing"); } String poolPropertiesAsText = xPath.evaluate("/pvAccessRPCService/poolproperties/text()", document).trim(); if (!poolPropertiesAsText.isEmpty()) { PooledRPCClientFactory.setPoolConfiguration(poolPropertiesAsText); } String hostName = xPath.evaluate("/pvAccessRPCService/host/text()", document).trim(); if (hostName.isEmpty()) { hostName = null; } String methodFieldName = xPath.evaluate("/pvAccessRPCService/methodFieldName/text()", document).trim(); if (methodFieldName.isEmpty()) { methodFieldName = null; } boolean useNTQuery = false; String useNTQueryStr = xPath.evaluate("/pvAccessRPCService/useNTQuery/text()", document).trim(); if (!useNTQueryStr.isEmpty()) { useNTQuery = Boolean.valueOf(useNTQueryStr); } RPCServiceDescription service = new RPCServiceDescription(serviceName, serviceDescription, hostName, channelName, methodFieldName, useNTQuery); service.executorService(defaultExecutor); NodeList methods = (NodeList) xPath.evaluate("/pvAccessRPCService/methods/method", document, XPathConstants.NODESET); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); String structureId = xPath.evaluate("structureid/text()", method).trim(); String methodName = xPath.evaluate("@name", method).trim(); String methodDescription = xPath.evaluate("@description", method).trim(); String resultName = xPath.evaluate("result/@name", method).trim(); String resultType = xPath.evaluate("result/@type", method).trim(); String resultFieldName = xPath.evaluate("result/@fieldName", method).trim(); if (resultFieldName.isEmpty()) { resultFieldName = null; } String operationName = xPath.evaluate("@operationName", method).trim(); if (operationName.isEmpty()) { operationName = null; } boolean isResultStandalone = Boolean.parseBoolean(xPath.evaluate("result/@standalone", method)); String resultDescription = xPath.evaluate("result/@description", method).trim(); NodeList multipleResultsList = (NodeList) xPath.evaluate("result", method, XPathConstants.NODESET); if ((multipleResultsList != null) && (multipleResultsList.getLength() > 1)) { throw new IllegalArgumentException(methodName + ":The pvAccess RPC rpcservice can only have one result"); } if ((multipleResultsList.getLength() > 0) && !isResultStandalone && resultName.isEmpty()) { throw new IllegalArgumentException("nonstandalone result must be named."); } if (isResultStandalone && resultName.isEmpty()) { resultName = "result"; } RPCServiceMethodDescription pvAccessRPCMethodDescription = new RPCServiceMethodDescription(methodName, methodDescription, operationName, structureId, isResultStandalone); if (!resultName.isEmpty()) { pvAccessRPCMethodDescription.addRPCResult(resultName, resultFieldName, resultDescription, getClassFromString(resultType)); } NodeList arguments = (NodeList) xPath.evaluate("argument", method, XPathConstants.NODESET); for (int nArg = 0; nArg < arguments.getLength(); nArg++) { Node argument = arguments.item(nArg); String argName = xPath.evaluate("@name", argument).trim(); String argDescription = xPath.evaluate("@description", argument).trim(); String argType = xPath.evaluate("@type", argument).trim(); String argFieldName = xPath.evaluate("@fieldName", argument).trim(); if (argFieldName.isEmpty()) { argFieldName = null; } if (!argName.isEmpty()) { pvAccessRPCMethodDescription.addArgument(argName, argFieldName, argDescription, getClassFromString(argType)); } } service.addServiceMethod(pvAccessRPCMethodDescription); } return service.createService(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(RPCServices.class.getName()).log(Level.FINEST, "Couldn't create rpcservice", ex); throw new IllegalArgumentException("Couldn't create rpcservice", ex); } }  static Service createFromXml(InputStream input); }
RPCServices { public static Service createFromXml(InputStream input) { try { if (input == null) { throw new IllegalArgumentException("input stream is not valid: null"); } DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(input); XPathFactory xpathFactory = XPathFactory.newInstance(); XPath xPath = xpathFactory.newXPath(); String ver = xPath.evaluate("/pvAccessRPCService/@ver", document).trim(); String serviceName = xPath.evaluate("/pvAccessRPCService/@name", document).trim(); String serviceDescription = xPath.evaluate("/pvAccessRPCService/@description", document).trim(); if (!ver.equals("1")) { throw new IllegalArgumentException("Unsupported version " + ver); } String channelName = xPath.evaluate("/pvAccessRPCService/channelName/text()", document).trim(); if (channelName.isEmpty()) { throw new IllegalArgumentException("channelName element is missing"); } String poolPropertiesAsText = xPath.evaluate("/pvAccessRPCService/poolproperties/text()", document).trim(); if (!poolPropertiesAsText.isEmpty()) { PooledRPCClientFactory.setPoolConfiguration(poolPropertiesAsText); } String hostName = xPath.evaluate("/pvAccessRPCService/host/text()", document).trim(); if (hostName.isEmpty()) { hostName = null; } String methodFieldName = xPath.evaluate("/pvAccessRPCService/methodFieldName/text()", document).trim(); if (methodFieldName.isEmpty()) { methodFieldName = null; } boolean useNTQuery = false; String useNTQueryStr = xPath.evaluate("/pvAccessRPCService/useNTQuery/text()", document).trim(); if (!useNTQueryStr.isEmpty()) { useNTQuery = Boolean.valueOf(useNTQueryStr); } RPCServiceDescription service = new RPCServiceDescription(serviceName, serviceDescription, hostName, channelName, methodFieldName, useNTQuery); service.executorService(defaultExecutor); NodeList methods = (NodeList) xPath.evaluate("/pvAccessRPCService/methods/method", document, XPathConstants.NODESET); for (int i = 0; i < methods.getLength(); i++) { Node method = methods.item(i); String structureId = xPath.evaluate("structureid/text()", method).trim(); String methodName = xPath.evaluate("@name", method).trim(); String methodDescription = xPath.evaluate("@description", method).trim(); String resultName = xPath.evaluate("result/@name", method).trim(); String resultType = xPath.evaluate("result/@type", method).trim(); String resultFieldName = xPath.evaluate("result/@fieldName", method).trim(); if (resultFieldName.isEmpty()) { resultFieldName = null; } String operationName = xPath.evaluate("@operationName", method).trim(); if (operationName.isEmpty()) { operationName = null; } boolean isResultStandalone = Boolean.parseBoolean(xPath.evaluate("result/@standalone", method)); String resultDescription = xPath.evaluate("result/@description", method).trim(); NodeList multipleResultsList = (NodeList) xPath.evaluate("result", method, XPathConstants.NODESET); if ((multipleResultsList != null) && (multipleResultsList.getLength() > 1)) { throw new IllegalArgumentException(methodName + ":The pvAccess RPC rpcservice can only have one result"); } if ((multipleResultsList.getLength() > 0) && !isResultStandalone && resultName.isEmpty()) { throw new IllegalArgumentException("nonstandalone result must be named."); } if (isResultStandalone && resultName.isEmpty()) { resultName = "result"; } RPCServiceMethodDescription pvAccessRPCMethodDescription = new RPCServiceMethodDescription(methodName, methodDescription, operationName, structureId, isResultStandalone); if (!resultName.isEmpty()) { pvAccessRPCMethodDescription.addRPCResult(resultName, resultFieldName, resultDescription, getClassFromString(resultType)); } NodeList arguments = (NodeList) xPath.evaluate("argument", method, XPathConstants.NODESET); for (int nArg = 0; nArg < arguments.getLength(); nArg++) { Node argument = arguments.item(nArg); String argName = xPath.evaluate("@name", argument).trim(); String argDescription = xPath.evaluate("@description", argument).trim(); String argType = xPath.evaluate("@type", argument).trim(); String argFieldName = xPath.evaluate("@fieldName", argument).trim(); if (argFieldName.isEmpty()) { argFieldName = null; } if (!argName.isEmpty()) { pvAccessRPCMethodDescription.addArgument(argName, argFieldName, argDescription, getClassFromString(argType)); } } service.addServiceMethod(pvAccessRPCMethodDescription); } return service.createService(); } catch (ParserConfigurationException | SAXException | IOException | XPathExpressionException ex) { Logger.getLogger(RPCServices.class.getName()).log(Level.FINEST, "Couldn't create rpcservice", ex); throw new IllegalArgumentException("Couldn't create rpcservice", ex); } }  static Service createFromXml(InputStream input);  }