org.apache.xmlrpc.client.XmlRpcClientConfigImpl Java Examples

The following examples show how to use org.apache.xmlrpc.client.XmlRpcClientConfigImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Pingtest.java    From jivejdon with Apache License 2.0 8 votes vote down vote up
public static void main(String[] args) throws UnknownHostException, SocketException {
	try {
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

		config.setServerURL(new URL("http://ping.baidu.com/ping/RPC2"));
		config.setUserAgent("jdon.com");
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);
		Object[] params = new Object[] { "jdon", "http://www.jdon.com/", "http://www.jdon.com/47686",
				 "http://www.jdon.com/rss" };
		String pMethodName = "weblogUpdates.extendedPing";
		Object result = client.execute(pMethodName, params);

		System.out.println(result);
	} catch (Exception e) {
		
	}
	
}
 
Example #2
Source File: ApiGetVersions.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
	config.setEnabledForExtensions(true);
	config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
	XmlRpcClient client = new XmlRpcClient();
	client.setConfig(config);

	Object[] params = new Object[] { Constants.USER, Constants.REQUESTID, "887611628764801051" };
																		// strFileId

	long startTotal = System.currentTimeMillis();
	String strResponse = (String) client.execute("XmlRpcSyncHandler.getVersions", params);

	System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

	long totalTime = System.currentTimeMillis() - startTotal;
	System.out.println("Total level time --> " + totalTime + " ms");
}
 
Example #3
Source File: BlogPingClient.java    From jivejdon with Apache License 2.0 6 votes vote down vote up
public void blogPing(String serverUrl, String Title, String blogUrl, String UrlChanges,
					 String UrlRSS) {
	try {
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();

		config.setServerURL(new URL(serverUrl));
		config.setUserAgent("jdon.com");
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);
		Object[] params = new Object[]{Title, blogUrl, UrlChanges, UrlRSS};
		String pMethodName = "weblogUpdates.extendedPing";
		Object result = client.execute(pMethodName, params);

		logger.info(result);
	} catch (Exception e) {
		logger.error(e);
	}
}
 
Example #4
Source File: ApiPutMetadataFolder.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);

		Object[] params = new Object[] { Constants.USER, Constants.REQUESTID, "hola5", null};
																			// strFolderName, strParentId

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.putMetadataFolder", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #5
Source File: ApiGetMetadata.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);
		
		String strUserId = "159a1286-33df-4453-bf80-cff4af0d97b0";
		String strItemId = "100";
		String strIncludeList = "true";
		String strIncludeDeleted = "true";
		String strIncludeChunks = "true";
		String strVersion = "null";
		
		Object[] params = new Object[] { strUserId, strItemId, strIncludeList, strIncludeDeleted, strIncludeChunks, strVersion};

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.getMetadata", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #6
Source File: ApiPutMetadataFile.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);

		String[] chunks = new String[] {"1111", "2222", "3333"};
		Object[] params = new Object[] { Constants.USER, Constants.REQUESTID, "test.txt", "", "", "111111", "10", "Text", chunks};
																			// strFileName, strParentId, strOverwrite, strChecksum, strFileSize,
																			// strMimetype, strChunks

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.putMetadataFile", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #7
Source File: ApiRestoreMetadata.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);

		Object[] params = new Object[] { Constants.USER, Constants.REQUESTID, "887611628764801051", "2"};
																			// strFileId, strVersion

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.restoreMetadata", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #8
Source File: ApiDeleteMetadataFile.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);

		Object[] params = new Object[] { Constants.USER, Constants.REQUESTID, "-4573748213815439639"};
																			// strFileId

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.deleteMetadataFile", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #9
Source File: ApiCreateFolder.java    From sync-service with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		config.setEnabledForExtensions(true);
		config.setServerURL(new URL("http://127.0.0.1:" + Constants.XMLRPC_PORT));
		XmlRpcClient client = new XmlRpcClient();
		client.setConfig(config);
		
		String strUserId = "159a1286-33df-4453-bf80-cff4af0d97b0";
		String strFolderName = "folder1";
		String strParentId = "null";
		
		Object[] params = new Object[] { strUserId, strFolderName, strParentId};

		long startTotal = System.currentTimeMillis();
		String strResponse = (String) client.execute("XmlRpcSyncHandler.createFolder", params);

		System.out.println("Response --> " + Constants.PrettyPrintJson(strResponse));

		long totalTime = System.currentTimeMillis() - startTotal;
		System.out.println("Total level time --> " + totalTime + " ms");
	}
 
Example #10
Source File: DemoDbGetter.java    From openerp-java-api with Apache License 2.0 6 votes vote down vote up
private static boolean testConnection(DemoDbInfo infos) {
	// Try to connect to that DB to check it is still available
	final XmlRpcClient client = new XmlRpcClient();
	final XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
	try {
		String protocolAsString = infos.protocol == RPCProtocol.RPC_HTTP ? "http://" : "https://"; 
		common_config.setServerURL(
				new URL(String.format("%s%s:%s/xmlrpc/2/common", protocolAsString, infos.host, infos.port)));

		int uid = (int) client.execute(common_config, "authenticate",
				new Object[] { infos.db, infos.username, infos.password, new Object[] {} });
		// Informations are valid if user could log in.
		return uid != 0;

	} catch (MalformedURLException e1) {
		// Previously saved data is causing this...
		// We will have to request a new demo db
		return false;
	} catch (XmlRpcException e) {
		// Connection to previous demo db failed somehow, we will have
		// to request a new one...
		return false;
	}
}
 
Example #11
Source File: PacmanUtilsTest.java    From pacbot with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception{
    ec2ServiceClient = PowerMockito.mock(AmazonEC2.class); 
    minVersion = PowerMockito.mock(DefaultArtifactVersion.class); 
    url = PowerMockito.mock(URL.class); 
    config = PowerMockito.mock(XmlRpcClientConfigImpl.class); 
    annotation = PowerMockito.mock(Annotation.class);
    mockStatic(HttpClientBuilder.class);
    mockStatic(HttpClient.class);
    mockStatic(CloseableHttpClient.class);
    mockStatic(HttpResponse.class);
    mockStatic(CloseableHttpResponse.class);
    
    closeableHttpClient = PowerMockito.mock(CloseableHttpClient.class);
    HttpClientBuilder httpClientBuilder = PowerMockito.mock(HttpClientBuilder.class);
    PowerMockito.when(HttpClientBuilder.create()).thenReturn(httpClientBuilder);
    PowerMockito.when(HttpClientBuilder.create().setConnectionTimeToLive(anyLong(), anyObject())).thenReturn(httpClientBuilder);
    PowerMockito.when(HttpClientBuilder.create().setConnectionTimeToLive(anyLong(), anyObject()).build()).thenReturn(closeableHttpClient);
    HttpGet httpGet = PowerMockito.mock(HttpGet.class); 
    PowerMockito.whenNew(HttpGet.class).withAnyArguments().thenReturn(httpGet);
    httpResponse = PowerMockito.mock(CloseableHttpResponse.class);
    HttpEntity entity = PowerMockito.mock(HttpEntity.class);
    InputStream input = new ByteArrayInputStream("2001".getBytes() );
    PowerMockito.when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "FINE!"));
    PowerMockito.when(entity.getContent()).thenReturn(input);
    PowerMockito.when(httpResponse.getEntity()).thenReturn(entity);
}
 
Example #12
Source File: ScriptXmlRpcClient.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Sets the port where the server is started.
 * @throws MalformedURLException
 */
@Override
public void setPort(int port) throws MalformedURLException {
    XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
    config.setServerURL(new URL("http://" + LocalHost.getLocalHost() + ":" + port));

    this.impl.setConfig(config);
}
 
Example #13
Source File: Confluence.java    From maven-confluence-plugin with Apache License 2.0 5 votes vote down vote up
protected Confluence(String endpoint, ConfluenceProxy proxyInfo ) throws URISyntaxException, MalformedURLException {
       this(new XmlRpcClient());
if (endpoint.endsWith("/")) {
           endpoint = endpoint.substring(0, endpoint.length() - 1);
       }

       endpoint = ConfluenceService.Protocol.XMLRPC.addTo(endpoint);
   
       final java.net.URI serviceURI = new java.net.URI(endpoint);

       XmlRpcClientConfigImpl clientConfig = new XmlRpcClientConfigImpl();
       clientConfig.setServerURL(serviceURI.toURL() );

       clientConfig.setEnabledForExtensions(true); // add this to support attachment upload

       client.setConfig( clientConfig );

       if( isProxyEnabled(proxyInfo, serviceURI) ) {
           
           final XmlRpcCommonsTransportFactory transportFactory = new XmlRpcCommonsTransportFactory( client );

           final HttpClient httpClient = new HttpClient();
           final HostConfiguration hostConfiguration = httpClient.getHostConfiguration();
           hostConfiguration.setProxy( proxyInfo.host, proxyInfo.port );
           hostConfiguration.setHost(serviceURI.getHost(), serviceURI.getPort(), serviceURI.toURL().getProtocol());

           if( !isNullOrEmpty(proxyInfo.userName) && !isNullOrEmpty(proxyInfo.password) ) {
               Credentials cred = new UsernamePasswordCredentials(proxyInfo.userName,proxyInfo.password);
               httpClient.getState().setProxyCredentials(AuthScope.ANY, cred);
           }

           transportFactory.setHttpClient( httpClient );
           client.setTransportFactory( transportFactory );
       }
   }
 
Example #14
Source File: Purchasing.java    From BowlerStudio with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void test() throws XmlRpcException, MalformedURLException {

	XmlRpcClient client = new XmlRpcClient();

	XmlRpcClientConfigImpl start_config = new XmlRpcClientConfigImpl();
	start_config.setServerURL(new URL("https://demo.odoo.com/start"));
	Map<String, String> info = (Map<String, String>) client.execute(start_config, "start", emptyList());

	String url = info.get("host"), db = info.get("database"), username = info.get("user"),
			password = info.get("password");
	XmlRpcClientConfigImpl common_config = new XmlRpcClientConfigImpl();
	common_config.setServerURL(new URL(String.format("%s/xmlrpc/2/common", url)));
	Map<String, String> serverInfo = (Map<String, String>) client.execute(common_config, "version", emptyList());

	int uid = (int) client.execute(common_config, "authenticate",
			new Object[] { db, username, password, emptyMap() });

	XmlRpcClient models = new XmlRpcClient() {
		{
			setConfig(new XmlRpcClientConfigImpl() {
				{
					setServerURL(new URL(String.format("%s/xmlrpc/2/object", url)));
				}
			});
		}
	};
	models.execute("execute_kw", new Object[] { db, uid, password, "res.partner", "check_access_rights",
			new Object[] { "read" }, new HashMap() {
				{
					put("raise_exception", false);
				}
			} });
	// https://sourceforge.net/p/openerpjavaapi/wiki/Home/
	

}
 
Example #15
Source File: AbstractXmlRpcTestCase.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #16
Source File: PacmanUtils.java    From pacbot with Apache License 2.0 5 votes vote down vote up
public static XmlRpcClient getXMLRPCClient(String rpcUrl) throws MalformedURLException {

        XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
        config.setServerURL(new URL(rpcUrl));
        XmlRpcClient client = new XmlRpcClient();
        client.setConfig(config);
        return client;
    }
 
Example #17
Source File: OdooXmlRpcProxy.java    From openerp-java-api with Apache License 2.0 4 votes vote down vote up
/**
 * Proxy object to handle calls to and from the Odoo server
 * 
 * @param protocol
 *            Protocol to use when connecting to the RPC service ex.
 *            http/https
 * @param host
 *            Host name or IP address where the Odoo server is hosted
 * @param port
 *            XML-RPC port number to connect to. Typically 8069.
 * @param service
 *            Odoo webservice to call (db, common or object)
 */
public OdooXmlRpcProxy(RPCProtocol protocol, String host, int port, RPCServices service) {
	super();

	String URL = "";

	switch (service) {
	case RPC_COMMON:
		URL = this.RPC_COMMON_URL;
		break;
	case RPC_OBJECT:
		URL = this.RPC_OBJECT_URL;
		break;
	case RPC_REPORT:
		URL = this.RPC_REPORT_URL;
		break;
	case RPC_DATABASE:
		URL = this.RPC_DATABASE_URL;
		break;
	}

	String protocol_str = "";
	switch (protocol) {
	case RPC_HTTP:
		protocol_str = "http";
		break;

	default:
		protocol_str = "https";
		break;
	}

	useProxyIfAvailable(protocol);

	XmlRpcClientConfigImpl xmlrpcConfigLogin = new XmlRpcClientConfigImpl();

	// Odoo seems to be documented for supporting extensions
	// https://doc.odoo.com/v6.0/developer/6_22_XML-RPC_web_services/index.html/
	// https://www.odoo.com/fr_FR/forum/aide-1/question/using-openerp-xml-rpc-api-with-java-2872
	xmlrpcConfigLogin.setEnabledForExtensions(true);

	// The URL is hardcoded and can not be malformed
	try {
		xmlrpcConfigLogin.setServerURL(new URL(protocol_str, host, port, URL));
	} catch (MalformedURLException e) {
	}

	this.setConfig(xmlrpcConfigLogin);
}
 
Example #18
Source File: DemoDbGetter.java    From openerp-java-api with Apache License 2.0 4 votes vote down vote up
private static DemoDbInfo getNewDemoDb() throws XmlRpcException {
	System.out.println("Requesting new demo db from https://demo.odoo.com/start");
	final XmlRpcClient client = new XmlRpcClient();

	final XmlRpcClientConfigImpl start_config = new XmlRpcClientConfigImpl();
	try {
		start_config.setServerURL(new URL("https://demo.odoo.com/start"));
		String methodName = "start";
		Object[] params = new Object[] {};
		@SuppressWarnings("unchecked")
		final Map<String, String> info = (Map<String, String>) client.execute(start_config, methodName, params);

		String url = info.get("host");
		final String db = info.get("database");
		final String username = info.get("user");
		final String password = info.get("password");

		RPCProtocol protocol;
		Integer port;

		if (url.startsWith(HTTPS_PROTOCOL)) {
			protocol = RPCProtocol.RPC_HTTPS;
			url = url.substring(HTTPS_PROTOCOL.length());
			port = 443;
		} else {
			protocol = RPCProtocol.RPC_HTTP;
			url = url.substring(HTTP_PROTOCOL.length());
			port = 80;
		}

		int lastIndexOfColon = url.lastIndexOf(':');
		if (lastIndexOfColon != -1) {
			// Port specified in the url
			String portString = url.substring(lastIndexOfColon + 1);
			if (portString != null && !portString.isEmpty()) {
				port = Integer.parseInt(portString);
			}
			url = url.substring(0, lastIndexOfColon - 1);
		}

		return new DemoDbInfo(protocol, url, port, db, username, password);
	} catch (MalformedURLException e) {
		// Won't happen, as "https://demo.odoo.com/start" is a valid URL...
		return null;
	}
}
 
Example #19
Source File: cfXMLRPC.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
public cfTagReturnType render(cfSession _Session) throws cfmRunTimeException {
  String server	= getDynamic( _Session, "SERVER").getString();
  String method	= getDynamic( _Session, "METHOD").getString();
  cfData params	= getDynamic( _Session, "PARAMS");


//-- Create the return structure, and prefill it in with debug data
cfStructData	xmlrpc = new cfStructData();
xmlrpc.setData("server", 	new cfStringData(server) );
xmlrpc.setData("method", 	new cfStringData(method) );


  //-- The params must be an array
  if ( params.getDataType() != cfData.CFARRAYDATA ){
	xmlrpc.setData("success", cfBooleanData.FALSE);
	xmlrpc.setData("error", 	new cfStringData("PARAMS must be an array type") );
	_Session.setData("xmlrpc", xmlrpc);
	return cfTagReturnType.NORMAL;
}

  //-- Clean up the server
  if ( !server.toLowerCase().startsWith("http://") )
    server	= "http://" + server;

  try{
  	XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
      config.setServerURL(new URL(server));
      XmlRpcClient client = new XmlRpcClient();
      client.setConfig(config);

 	//-- Need to convert the CFML structure into a Java structure
   Vector javaParamsV 		= (Vector) tagUtils.convertCFtoJava( params, java.util.Vector.class );
   Object[] javaParams     = new Object[javaParamsV.size()];
   for(int i=0; i<javaParams.length; i++)
   	javaParams[i] = javaParamsV.get(i);

      Object xmlResult 			= client.execute(method,javaParams);

    xmlrpc.setData("result", 	tagUtils.convertToCfData( xmlResult ) );
    xmlrpc.setData("success", cfBooleanData.TRUE);

  }catch(Exception E){
    xmlrpc.setData("success", cfBooleanData.FALSE);
    xmlrpc.setData("error", 	new cfStringData(E.getMessage()) );
  }

  _Session.setData("xmlrpc", xmlrpc);

  return cfTagReturnType.NORMAL;
}
 
Example #20
Source File: XmlRpcClientDefaults.java    From scava with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of {@link XmlRpcClientConfig}.
 */
public static XmlRpcClientConfig newXmlRpcClientConfig() {
    return new XmlRpcClientConfigImpl();
}