Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Working with Confluence and LWP

by TStanley (Canon)
on Jul 28, 2015 at 17:43 UTC ( #1136645=perlquestion: print w/replies, xml ) Need Help??

TStanley has asked for the wisdom of the Perl Monks concerning the following question:

My company recently bought the Confluence software from Atlassian. Confluence is a web based collaboration system, allowing users to upload
documents and other content to their personal pages, and to provide for project teams to collaborate together and share documentation. The software
also tracks changes to the documentation as well.

I have been tasked with automating some tasks that occur on a daily basis, mostly updating verification reports of our various databases, and then
publishing those to Confluence.

Confluence has several APIs, and the easiest for me to use was the RPC-XML client, as I could do it with perl. A search of CPAN gave me the Confluence::Client::XMLRPC module. So I created the following short script, to make sure I could do what I want:
#!C:\Perl64\bin\perl use strict; use warnings; use Confluence::Client::XMLRPC; my $version=2; Confluence::Client::XMLRPC::setApiVersion($version); Confluence::Client::XMLRPC::setRaiseError(1); Confluence::Client::XMLRPC::setPrintError(1); my $URL="https://jeeves.Mainoffice.Demoulas.Corp/rpc/xmlrpc/"; my $user="toms"; my $pass="password"; my $object = Confluence::Client::XMLRPC->new($URL,$user,$pass); $object->logout();
which produced the following error:
XML-RPC ERROR: Unable to connect to https://jeeves.Mainoffice.Demoulas +.Corp/rpc/xmlrpc at C:\Users\toms\Documents\Confluence\confluence.pl line 15
After a great deal of trial and error, I got the code below working:
#!C:\Perl64\bin\perl use warnings; use strict; use LWP::UserAgent; my $ua=LWP::UserAgent->new(ssl_opts=>{ verify_hostname => 0}); my $req = HTTP::Request->new(GET => 'https://jeeves.mainoffice.demoula +s.corp'); my $result = $ua->request($req); if($result->is_success){ print $result->content; }else{ print $result->status_line, "\n"; }
The catch is where I create the LWP object, telling the agent to not verify the hostname of the server. If I remove the ssl_opts, it will say it can not connect due to failing the certificate verification. The Confluence client in the first bit of code uses LWP and LWP::Protocol::https to handle the http/https part of connecting to the server. What I need to figure out is how I can pass the ssl_opts.

I am currently testing all of this on Windows 7 (64 bit), running ActiveState Perl 5.18.2


TStanley
--------
People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

Replies are listed 'Best First'.
Re: Working with Confluence and LWP
by tangent (Vicar) on Jul 28, 2015 at 18:43 UTC
    You could try setting the "PERL_LWP_SSL_VERIFY_HOSTNAME" environment variable - if that is set to 0 then LWP::UserAgent will honour it. If that doesn't work for you then you could get your hands dirty a little bit and add a couple of lines to the Confluence::Client::XMLRPC source. Also note that in the docs for that module it says that the XML API will be deprecated in favour of a REST one, no dates are given though.
      Tried the PERL_LWP_SSL_VERIFY_HOSTNAME variable already, and didn't do anything. Time to edit the source...

      TStanley
      --------
      People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell
Re: Working with Confluence and LWP
by 1nickt (Abbot) on Jul 28, 2015 at 17:48 UTC

    The error message you posted makes it appear as if the connection is being attempted to the URI rather than the host. Don't know if that's a clue.


    The way forward always starts with a minimal test.
Re: Working with Confluence and LWP
by GotToBTru (Prior) on Jul 28, 2015 at 20:07 UTC

    Have you looked at the example programs that were provided with the module? I wonder if there might be some clues there in how to format the URL.

    Dum Spiro Spero
Re: Working with Confluence and LWP
by TStanley (Canon) on Jul 30, 2015 at 13:10 UTC
    Thanks to all of those who helped. The end result was that I found an older version of the Confluence::Client::XMLRPC module on the Atlassian website, and with some minor tweaking, was able to successfully connect.

    TStanley
    --------
    People sleep peaceably in their beds at night only because rough men stand ready to do violence on their behalf. -- George Orwell

      Hey,

      I'm having the exact same issue, could you let me know what you did to fix it?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1136645]
Approved by 1nickt
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2019-10-19 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?