You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@ws.apache.org by ppptulen <pp...@gmail.com> on 2013/08/12 12:58:10 UTC

Problem with log in to have write access

Hi,

I'm trying read wiki and update wiki page with xml rpc. 

Guys have working python rpc xml script which with that account I rewrited
it to java. When I'm changing account name in config doesn't affect resuts -
so it is not log in. How I should log in with xml rpc in java?

I have this code:

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.xmlrpc.XmlRpcException;
//import org.apache.xmlrpc.client.XmlRpcClient;
//import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
//import org.apache.xmlrpc.client.XmlRpcCommonsTransportFactory;
import org.apache.xmlrpc.client.*;

public class Test 
{
	
	Test( String targetBuild ) throws XmlRpcException
	{
		String pageURL = null;		
		
		if ( targetBuild.contains("AAA"))
		{	pageURL = "wiki/AAA";	}
		else if ( targetBuild.contains("BBB"))
		{	pageURL = "wiki/BBB";	}
		else if ( targetBuild.contains("CCC"))
		{	pageURL = "wiki/CCC";	}

		if ( pageURL == null )
		{	
			System.out.println("pageURL for wikiUpdate is empty! Exiting...");	
			System.exit(1);
		}
	
		XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
		XmlRpcClient client = new XmlRpcClient();

		try
		{	config.setServerURL(new
URL("http://wiki.someserver.com/?action=xmlrpc2"));	}
		catch (MalformedURLException e)
		{	e.printStackTrace();	}
	     
		config.setBasicUserName("xmlrpcuser");  
		config.setBasicPassword("xmlrpcpassword"); 
		
		client.setConfig(config);	     
	     
		String oldPage = null;
		
		oldPage = getWikiPage(client, pageURL);
	     
		List<String> dataSections = separateWikiSections(oldPage);
	     
		String linpackSection = dataSections.get(2);
	     
		if ( !linpackSectionContainsTargetBuild(linpackSection, targetBuild))
		{ 	 
			modifyLinpackSection( dataSections, targetBuild );     
			updateWikiPage(client, pageURL, buildPageFromSections(dataSections));
		} 
	}
	
	private String buildPageFromSections( List<String> dataSections )
	{
		String concatenatedString = null;
		
		for ( String section : dataSections )
		{
			if ( concatenatedString != null )
			{	concatenatedString = concatenatedString + section;	}
			else
			{	concatenatedString = section;	}
		}
		return concatenatedString;			
	}
	
	private void modifyLinpackSection( List<String> dataSection, String
targetBuild )
	{	dataSection.set(3, "|| " + targetBuild + " || {./} || {./} || {./} ||
{./} ||\n##block end");	}

	public boolean linpackSectionContainsTargetBuild( String linpackSection,
String targetBuild )
	{
		if ( linpackSection.contains(targetBuild))
		{	return true;	}
		else
		{	return false;	}
	}
	
	public String getWikiPage( XmlRpcClient client, String pageURL ) throws
XmlRpcException
	{
	     Vector<String> parms = new Vector<>();

	     parms.add(pageURL);

	return (String)client.execute( "getPage", parms );
	}

	public void updateWikiPage( XmlRpcClient client, String pageURL, String
newPage ) throws XmlRpcException
	{
		Vector<String> parms = new Vector<>();
	     parms.add( pageURL );
	     parms.add( newPage );
	     
	     client.execute("putPage", parms );
	}
	
	public List<String> separateWikiSections ( String oldPage )
	{
		List<String> dataBlocks = new ArrayList<>();
		
     	Pattern pattern = Pattern.compile("(.*)(##block start)(.*)(##block
end)(.*)", Pattern.DOTALL);

       	Matcher matcher = pattern.matcher( oldPage );

    	while ( matcher.find())
    	{	
    		dataBlocks.add(matcher.group(1));
    		dataBlocks.add(matcher.group(2));
    		dataBlocks.add(matcher.group(3));
    		dataBlocks.add(matcher.group(4));
    		dataBlocks.add(matcher.group(5));
    	}
    	return dataBlocks;		
	}

	public static void main (String [] args) 
	{

		try
		{	new Test(args[0]);	}
		catch (XmlRpcException e)
		{	e.printStackTrace();	}
		
	}
}
	     
	     




--
View this message in context: http://apache-xml-project.6118.n7.nabble.com/Problem-with-log-in-to-have-write-access-tp40413.html
Sent from the Apache Xml-RPC - User mailing list archive at Nabble.com.