#7 Override php.ini java.hosts and java.servlet values

closed-wont-fix
None
5
2007-04-11
2007-03-19
rdonaire
No

We have several J2EE applications deployed into Tomcat running on different machines, for example,

- App1 -> Tomcat1
- App2 -> Tomcat1
- App3 -> Tomcat2
- App4 -> Tomcat3
.
.
.
- AppN -> TomcatM

and one Apache running on another machine.

We want to use Apache as front-end and connect per PHP script to one, and only one, Tomcat back-end, but the host address is determined by php.ini.

Request: java.hosts and java.servlet can be overrided per PHP script?

Discussion

  • Logged In: YES
    user_id=1637115
    Originator: NO

    Hi,

    I have added a FAQ entry for this:

    Can I set the java.hosts option at run-time?
    Yes. The bridge examines the environment variables X_JAVABRIDGE_OVERRIDE_HOSTS and X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT.

    To direct a php script to a web context FOO running on computer 192.168.4.98, port 8080, use the following code:

    <?php
    $_SERVER['X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT']="h:192.168.4.98:8080//FOO/JavaBridge.phpjavabridge";
    echo java_server_name();
    ?>
    Assuming that the option java.servlet or JAVA_SERVLET (pure PHP implementation) is set to On, the above example uses plain HTTP to connect to the server 192.168.4.98 on port 8080 using the web context FOO. If PHP has been compiled with openssl enabled, s:.. can be used to connect to a SSL port. When java.servlet or JAVA_SERVLET is set to User or Off, the bridge ignores the specified FOO context and uses the request context instead, or it connects to a standalone socket listener directly (if the option is Off).

    To direct a php instance to a to a web context FOO running on computer 192.168.4.98, port 8080, use the variable X_JAVABRIDGE_OVERRIDE_HOSTS instead. This variable must be set before the PHP instance starts.

    When X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT is used and the php instance already has a persistent connection to another host, it opens a second persistent connection to the new host.

     
    • status: open --> pending-wont-fix
     
    • assigned_to: nobody --> jost_boekemeier
     
  • rdonaire
    rdonaire
    2007-03-26

    • status: pending-wont-fix --> open-wont-fix
     
  • rdonaire
    rdonaire
    2007-03-26

    Logged In: YES
    user_id=1727110
    Originator: YES

    Hi, sorry for my late response.

    I tried the solution explained in the comment and doesn't works for me, it generates errors or warnings:
    1. The script,
    <?php
    $_SERVER['X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT']="h:192.168.4.98:8080//FOO/JavaBridge.phpjavabridge";
    echo java_server_name();
    java_session();
    ?>

    outputs

    192.168.4.98:8080
    Fatal error: Cannot redeclare get_cookies() (previously declared in cookies:1) in cookies on line 2

    2. The script,

    <?php
    echo java_server_name();
    java_session();
    ?>

    outputs

    127.0.0.1:8080
    Warning: Cannot modify header information - headers already sent by (output started at C:\X\java.php:3) in setResultWith_cookie on line 4

    Also, setting $_SERVER[X_JAVABRIDGE_OVERRIDE_HOSTS] hasn't any effect (I seach in C code and I didn't found any reference).

    On the other hand, what's the difference between X_JAVABRIDGE_OVERRIDE_HOSTS and X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT?

     
  • Logged In: NO

    Hi,

    it does work, the J2EE component uses this. But I agree that it isn't exactly user-friendly.

    > Fatal error: Cannot redeclare get_cookies()

    That's just a bug in your test script, it doesn't have anything to do with the problem.

    If you want to test your setting, use

    strace -s 1024 php script.php

    > $_SERVER[X_JAVABRIDGE_OVERRIDE_HOSTS] hasn't any effect

    No, of course not. See the FAQ for details. This setting redirects the php instance, not the script

    > X_JAVABRIDGE_OVERRIDE_HOSTS and X_JAVABRIDGE_OVERRIDE_HOSTS_REDIRECT?

    The former must be set before the instance starts. The later can be used within a script, but before any java_* is called, of course.

    Regards,
    Jost Boekemeier

     
    • status: open-wont-fix --> pending-wont-fix
     
    • status: pending-wont-fix --> closed-wont-fix
     
  • Logged In: YES
    user_id=1312539
    Originator: NO

    This Tracker item was closed automatically by the system. It was
    previously set to a Pending status, and the original submitter
    did not respond within 14 days (the time period specified by
    the administrator of this Tracker).