Search in sources :

Example 1 with XmlRpcClient

use of org.apache.ofbiz.service.xmlrpc.XmlRpcClient in project ofbiz-framework by apache.

the class AbstractXmlRpcTestCase method getRpcClient.

public org.apache.xmlrpc.client.XmlRpcClient getRpcClient(String url, String login, String password) throws MalformedURLException {
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL(url));
    if (login != null) {
        config.setBasicUserName(login);
    }
    if (password != null) {
        config.setBasicPassword(password);
    }
    if (keyStoreComponent != null && keyStoreName != null && keyAlias != null) {
        return new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
    }
    return new XmlRpcClient(config);
}
Also used : XmlRpcClient(org.apache.ofbiz.service.xmlrpc.XmlRpcClient) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL)

Example 2 with XmlRpcClient

use of org.apache.ofbiz.service.xmlrpc.XmlRpcClient in project ofbiz-framework by apache.

the class XMLRPCClientEngine method serviceInvoker.

/*
     *  Invoke the remote XMLRPC SERVICE : This engine convert all value in IN mode to one struct.
     */
private Map<String, Object> serviceInvoker(ModelService modelService, Map<String, Object> context) throws GenericServiceException {
    if (modelService.location == null || modelService.invoke == null) {
        throw new GenericServiceException("Cannot locate service to invoke");
    }
    XmlRpcClientConfigImpl config = null;
    XmlRpcClient client = null;
    String serviceName = modelService.invoke;
    String engine = modelService.engineName;
    String url = null;
    String login = null;
    String password = null;
    String keyStoreComponent = null;
    String keyStoreName = null;
    String keyAlias = null;
    try {
        url = ServiceConfigUtil.getEngineParameter(engine, "url");
        if (Start.getInstance().getConfig().portOffset != 0) {
            String s = url.substring(url.lastIndexOf(":") + 1);
            Integer rpcPort = Integer.valueOf(s.substring(0, s.indexOf("/")));
            Integer port = rpcPort + Start.getInstance().getConfig().portOffset;
            url = url.replace(rpcPort.toString(), port.toString());
        }
        login = ServiceConfigUtil.getEngineParameter(engine, "login");
        password = ServiceConfigUtil.getEngineParameter(engine, "password");
        keyStoreComponent = ServiceConfigUtil.getEngineParameter(engine, "keyStoreComponent");
        keyStoreName = ServiceConfigUtil.getEngineParameter(engine, "keyStoreName");
        keyAlias = ServiceConfigUtil.getEngineParameter(engine, "keyAlias");
        config = new XmlRpcClientConfigImpl();
        config.setBasicUserName(login);
        config.setBasicPassword(password);
        config.setServerURL(new URL(url));
    } catch (MalformedURLException | GenericConfigException e) {
        throw new GenericServiceException("Cannot invoke service : engine parameters are not correct");
    }
    if (UtilValidate.isNotEmpty(keyStoreComponent) && UtilValidate.isNotEmpty(keyStoreName) && UtilValidate.isNotEmpty(keyAlias)) {
        client = new XmlRpcClient(config, keyStoreComponent, keyStoreName, keyAlias);
    } else {
        client = new XmlRpcClient(config);
    }
    List<ModelParam> inModelParamList = modelService.getInModelParamList();
    if (Debug.verboseOn()) {
        Debug.logVerbose("[XMLRPCClientEngine.invoke] : Parameter length - " + inModelParamList.size(), module);
        for (ModelParam p : inModelParamList) {
            Debug.logVerbose("[XMLRPCClientEngine.invoke} : Parameter: " + p.name + " (" + p.mode + ")", module);
        }
    }
    Map<String, Object> result = null;
    Map<String, Object> params = new HashMap<>();
    for (ModelParam modelParam : modelService.getModelParamList()) {
        // don't include OUT parameters in this list, only IN and INOUT
        if (ModelService.OUT_PARAM.equals(modelParam.mode) || modelParam.internal) {
            continue;
        }
        Object paramValue = context.get(modelParam.name);
        if (paramValue != null) {
            params.put(modelParam.name, paramValue);
        }
    }
    List<Map<String, Object>> listParams = UtilMisc.toList(params);
    try {
        result = UtilGenerics.cast(client.execute(serviceName, listParams.toArray()));
    } catch (XmlRpcException e) {
        result = ServiceUtil.returnError(e.getLocalizedMessage());
    }
    return result;
}
Also used : MalformedURLException(java.net.MalformedURLException) XmlRpcClient(org.apache.ofbiz.service.xmlrpc.XmlRpcClient) HashMap(java.util.HashMap) ModelParam(org.apache.ofbiz.service.ModelParam) XmlRpcClientConfigImpl(org.apache.xmlrpc.client.XmlRpcClientConfigImpl) URL(java.net.URL) GenericConfigException(org.apache.ofbiz.base.config.GenericConfigException) GenericServiceException(org.apache.ofbiz.service.GenericServiceException) HashMap(java.util.HashMap) Map(java.util.Map) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

URL (java.net.URL)2 XmlRpcClient (org.apache.ofbiz.service.xmlrpc.XmlRpcClient)2 XmlRpcClientConfigImpl (org.apache.xmlrpc.client.XmlRpcClientConfigImpl)2 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GenericConfigException (org.apache.ofbiz.base.config.GenericConfigException)1 GenericServiceException (org.apache.ofbiz.service.GenericServiceException)1 ModelParam (org.apache.ofbiz.service.ModelParam)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1