Search code examples
phpphp-java-bridge

Undefined offset: 1 in http://mysite_url/../Java.inc on line 1067


I have two scenarios: one for development (windows) and another for production (unix)

Development env in Windows: I have a apache web server which calls an apache tomcat server that has installed a javabridge in order to call a jasper report. (Everything is on localhost) and everything works fine.

Production env in CentOs: I have an apache web server that calls another tomcat server (that has java installed) by javabridge in order to call a jasper report. (Here is where I get the error)

In tomcat server I can execute Javabridge functions and examples but when I call them from apache web server it fails

I am getting this error

 Undefined offset: 1 in http://mysite_url/../Java.inc on line 1067 Fatal error: unknown error: please see back end log for details in http://mysite_url/Java.inc on line 869

When I try to execute this code:

<?php

    //Parametro en caso de que el reporte no este parametrizado
    $Parametro = new java('java.util.HashMap');
    ?>

The exact code in tomcat server Java.inc file is (line 1067)

function parseHeaders() {
$this->headers=array();
$line=trim(fgets($this->socket,JAVA_RECV_SIZE));
$ar=explode (" ",$line);
$code=((int)$ar[1]);  // LINE NUMBER 1067
if ($code !=200) $this->headers["http_error"]=$code;
while (($str=trim(fgets($this->socket,JAVA_RECV_SIZE)))) {
if($str[0]=='X') {
if(!strncasecmp("X_JAVABRIDGE_REDIRECT",$str,21)) {
$this->headers["redirect"]=trim(substr($str,22));
} else if(!strncasecmp("X_JAVABRIDGE_CONTEXT",$str,20)) {
$this->headers["context"]=trim(substr($str,21));
}

And the other line in Java.inc is (867):

function dieWithBrokenConnection($msg) {
unset($this->protocol->client->protocol);
trigger_error ($msg?$msg:"unknown error: please see back end log for details",E_USER_ERROR);
}

UPDATE When I call the link from development env this is the generated header:

array(3) { [0]=> string(8) "HTTP/1.1" [1]=> string(3) "200" [2]=> string(2) "OK" }

When I call it from production env the header is empty

array(1) { [0]=> string(0) "" }

What could be the problem? Is there any option in the server that take out the header of a response or something like that?


Solution

  • My code was ok, the problem was that I was trying to access the other server by public ip so the firewall was somehow taking out the header of the request.

    The solution was to change the public ip to same network local ip and everthing started to work and java.inc started to read the header of the request so every place in Java.inc and JavaProxy.php you have to set network ip and tomcats filesystem variables too.