Search code examples
javascriptajaxweb-servicesperlbugzilla

What's a good way to access the bugzilla webservice from a different domain?


I have two sites products.company.com and bugzilla.internal.com. I would like to access bug information from the products.company.com page. I set up a jQuery ajax function to make a jsonrpc call to bugzilla.internal.com/jsonrpc.cgi. However due to cross domain scripting restrictions, this was blocked by apache (as expected). So then I shot the ajax to a cgi script on products.company.com and then used curl in that script to shoot off the request to bugzilla.internal.com/jsonrpc.cgi, but now it says

You don't have permission to access /jsonrpc.cgi

What to do?

if it makes the task any simpler, I only want to use the get bug feature.


Solution

  • If your web server at products.company.com is Apache, you can set up a ProxyPass.

    If you can't modify web server configuration, then a simple proxy cgi at products.company.com can do the trick:

    #!/usr/bin/perl
    
    use LWP::UserAgent;
    use CGI qw(:standard);
    
    
    
    my $URL='http://bugzilla.internal.com/jsonrpc.cgi';
    
    my $q = new CGI;
    my $query = &query_string();
    
    my $req = HTTP::Request->new(POST => $URL);
    $req->content_type('application/x-www-form-urlencoded');
    $req->content($query);
    
    my $ua = LWP::UserAgent->new;
    $res = $ua->request($req);
    
    if ($res->is_success) {
       printf "Content-Type: %s\n\n", $res->header('Content-Type');
       print $res->content;
    } else {
       printf "Content-Type: text/plain\n\n";
       print "Error: " . $res->status_line . "\n";
    }
    
    
    
    print $cgi->header(-type => 'text/xml');
    print $response->decoded_content;