Index: /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl
===================================================================
--- /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl	(revision 31489)
+++ /gs3-extensions/solr/trunk/src/bin/script/solr_passes.pl	(revision 31490)
@@ -67,5 +67,5 @@
 
   # Now start up the solr-post command
-  &solrutil::open_post_pipe($core);
+  &solrutil::open_post_pipe($core, $solr_server->get_solr_base_url());
 }
 
Index: /gs3-extensions/solr/trunk/src/perllib/solrserver.pm
===================================================================
--- /gs3-extensions/solr/trunk/src/perllib/solrserver.pm	(revision 31489)
+++ /gs3-extensions/solr/trunk/src/perllib/solrserver.pm	(revision 31490)
@@ -43,13 +43,27 @@
     $self->{'server_explicitly_started'} = undef;
 
-    my $server_port = $ENV{'SOLR_PORT'};
-    my $server_host = $ENV{'SOLR_HOST'};
-    my $base_url = "http://$server_host:$server_port/solr/";
-    my $admin_url = "http://$server_host:$server_port/solr/admin/cores";
-    
-    $self->{'base-url'} = $base_url;
-    $self->{'admin-url'} = $admin_url;
+    # set SOLR_HOST and SOLR_PORT env vars (tomcat host and port, if not using jetty) 
+    # by calling ant get-default-solr-servlet if possible. Else fallback on whatever the existing env vars are.
+    # tomcat host and port would have been set up in the env as SOLR_HOST and SOLR_PORT
+    # In case someone changed the tomcat host/port, we want to update the solr server variables too
+    my $solr_url = &solrutil::get_solr_servlet_url();    
+    # get the url parts, though we won't be using most of them
+    my ($protocol, $server_host, $server_port, $servlet_name) = &solrutil::get_solr_url_parts($solr_url);
+    
+    # set the solr server env vars to what was discovered, so that any other old perl code
+    # dependent on these env vars will have any changes propagated. 
+    # (All perl code referencing these env vars should already be updated, but still...)
+    $ENV{'SOLR_HOST'} = $server_host;
+    $ENV{'SOLR_PORT'} = $server_port;
+    
+    $self->{'base-url'} = $solr_url; # e.g. of the form http://localhost:8383/solr
+    $self->{'admin-url'} = "$solr_url/admin/cores";
 
     return bless $self, $class;
+}
+
+sub get_solr_base_url {
+    my $self = shift (@_);
+    return $self->{'base-url'};
 }
 
Index: /gs3-extensions/solr/trunk/src/perllib/solrutil.pm
===================================================================
--- /gs3-extensions/solr/trunk/src/perllib/solrutil.pm	(revision 31489)
+++ /gs3-extensions/solr/trunk/src/perllib/solrutil.pm	(revision 31490)
@@ -59,9 +59,61 @@
 }
 
+# The get-solr-servlet-url ant target can be run from anywhere by specifying the
+# location of GS3's ant build.xml buildfile.
+# GSDL3SRCHOME will be set for GS3 by gs3-setup.sh.
+# Based on servercontrol::get_library_URL.
+sub get_solr_servlet_url {
+    # Set up fall backs, incl. old way of using solr host and port values that's already in the environment
+    my $solr_url = "http://".$ENV{'SOLR_HOST'}.$ENV{'SOLR_PORT'}."/solr"; # fallback to default
+
+    my $perl_command = "ant -buildfile \"$ENV{'GSDL3SRCHOME'}/build.xml\" get-solr-servlet-url";
+    
+    if (open(PIN, "$perl_command |")) {
+	while (defined (my $perl_output_line = <PIN>)) {
+	    if($perl_output_line =~ m@(https?):\/\/(\S*)@) { # grab all the non-whitespace chars
+		$solr_url="$1://".$2; # preserve the http protocol
+	    }
+	}
+	close(PIN);
+	
+	#print STDERR "XXXXXXXXXX SOLR URL: $solr_url\n";
+
+    } else {
+	print STDERR "*** ERROR IN solrutil::get_solr_servlet_url:\n";
+	print STDERR "    Failed to run $perl_command to work out GS3's solr URL\n";
+	print STDERR "    falling back to using original solr_URL: $solr_url\n";
+    }
+
+    return $solr_url;
+}
+
+# Given the solr base url (e.g. http://localhost:8383/solr by default), this function
+# returns the url's parts: protocol, host, port, solr servlet
+sub get_solr_url_parts {
+    my $solr_url = shift (@_);
+
+    # Set up fall backs, incl. old way of using solr host and port values that's already in the environment
+    my ($protocol, $server_host, $server_port, $servlet_name)
+	= ("http://", $ENV{'SOLR_HOST'}, $ENV{'SOLR_PORT'}, "solr");
+
+    
+    # http://stackoverflow.com/questions/8206135/storing-regex-result-in-a-new-variable
+    if($solr_url =~ m@(https?)://([^:]*):([0-9]*)/(.*)$@) { # m@https?://([^:]*):([^/])/(.*)@) {
+	
+	($protocol, $server_host, $server_port, $servlet_name) = ($1, $2, $3, $4);
+	
+	#print STDERR "XXXXXXXXXX PROTOCOL: $protocol, SOLR_HOST: $server_host, SOLR_PORT: $server_port, servlet: $servlet_name\n";
+
+    } else {
+	print STDERR "*** WARNING: in solrutil::get_solr_url_parts(): solr servlet URL not in expected format\n";
+    }
+
+    return ($protocol, $server_host, $server_port, $servlet_name);
+}
 
 
 sub open_post_pipe
 {
-    my ($core) = @_;
+    my ($core, $solr_base_url) = @_;
 
     my $search_path = get_search_path();
@@ -72,9 +124,7 @@
     my $full_post_jar   = solrutil::locate_file($search_path,$post_jar);
     
-    my $server_port = $ENV{'SOLR_PORT'}; # tomcat
-    my $server_host = $ENV{'SOLR_HOST'};
-    
     # Now run solr-post command
-    my $post_props = "-Durl=http://$server_host:$server_port/solr/$core/update";
+    my $post_props = "-Durl=$solr_base_url/$core/update"; # robustness of protocol is taken care of too
+
     $post_props .= " -Ddata=stdin";
     $post_props .= " -Dcommit=yes";
