Skip to content

Commit

Permalink
Prep v 0.14.1
Browse files Browse the repository at this point in the history
  • Loading branch information
belgattitude committed Jan 15, 2017
1 parent e7a2a65 commit 9e8edbc
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 15 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## 0.14.1 (2017-01-15)

### Improved

- Better detection of broken connections `BrokenConnectionException`
- Improved tests suite for tomcat

## 0.14.0 (2017-01-14)

### Breaking change
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"require-dev" : {
"phpunit/phpunit": "^5.5",
"friendsofphp/php-cs-fixer": "^2.0.0",
"belgattitude/pjbserver-tools": "^2.1.0",
"belgattitude/pjbserver-tools": "^2.1.1",
"monolog/monolog": "^1.21.0"
},
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
<server name="AUTORUN_PJB_STANDALONE" value="true" />
<server name="PJB_SERVLET_ADDRESS" value="http://127.0.0.1:8083/servlet.phpjavabridge" />

<!--
Generally if you have tomcat
<!--
to run the test suite on tomcat please increase
the heap memory in /etc/default/tomcat7:
JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseConcMarkSweepGC"
-->
<!--
<server name="AUTORUN_PJB_STANDALONE" value="false" />
<server name="PJB_SERVLET_ADDRESS" value="http://127.0.0.1:8080/javabridge-bundle/servlet.phpjavabridge" />
-->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Soluble Japha / PhpJavaBridge.
*
* Refactored version of phpjababridge's Java.inc file compatible
* with php java bridge 6.2.1
*
*
* @credits http://php-java-bridge.sourceforge.net/pjb/
*
* @see http://github.com/belgattitude/soluble-japha
*
* @copyright Copyright (c) 2014 Soluble components
* @author Vanvelthem Sébastien
* @license MIT
*
* The MIT License (MIT)
* Copyright (c) 2014 Vanvelthem Sébastien
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

namespace Soluble\Japha\Bridge\Driver\Pjb62\Exception;

class BrokenConnectionException extends IOException
{
}
43 changes: 35 additions & 8 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/Pjb62Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Soluble\Japha\Bridge\Driver\AbstractDriver;
use Soluble\Japha\Bridge\Driver\Pjb62\Exception\BrokenConnectionException;
use Soluble\Japha\Interfaces;
use Soluble\Japha\Bridge\Exception;

Expand Down Expand Up @@ -98,28 +99,44 @@ public function getJavaClass($class_name)
*/
public function instanciate($class_name, ...$args)
{
//return $this->pjbProxyClient->getJavaClass($class_name, $args);
if ($args === null) {
return new Java($class_name);
try {
if ($args === null) {
$java = new Java($class_name);
} else {
$java = new Java($class_name, ...$args);
}
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}

return new Java($class_name, ...$args);
return $java;
}

/**
* {@inheritdoc}
*/
public function invoke(Interfaces\JavaType $javaObject, $method, array $args = [])
{
return $this->pjbProxyClient->invokeMethod($javaObject, $method, $args);
try {
return $this->pjbProxyClient->invokeMethod($javaObject, $method, $args);
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
}

/**
* {@inheritdoc}
*/
public function getContext()
{
return $this->pjbProxyClient->getClient()->getContext();
try {
return $this->pjbProxyClient->getClient()->getContext();
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
}

/**
Expand All @@ -141,7 +158,12 @@ public function getContext()
*/
public function getJavaSession(array $args = [])
{
return $this->pjbProxyClient->getClient()->getSession();
try {
return $this->pjbProxyClient->getClient()->getSession();
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
}

/**
Expand Down Expand Up @@ -169,7 +191,12 @@ public function isInstanceOf(Interfaces\JavaObject $javaObject, $className)
*/
public function values(Interfaces\JavaObject $javaObject)
{
return $this->pjbProxyClient->getValues($javaObject);
try {
return $this->pjbProxyClient->getValues($javaObject);
} catch (BrokenConnectionException $e) {
PjbProxyClient::getInstance()->destroy();
throw $e;
}
}

/**
Expand Down
17 changes: 16 additions & 1 deletion src/Soluble/Japha/Bridge/Driver/Pjb62/PjbProxyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public static function getInstance(array $options = null, LoggerInterface $logge
*/
public static function isInitialized()
{
return self::$instance !== null;
$init = (isset(self::$instance) && self::$instance !== null);

return (bool) $init;
}

/**
Expand Down Expand Up @@ -467,13 +469,26 @@ public static function unregisterInstance()

// Added but needs more tests
//unset($client);// = null;
/*
unset(self::$client); // = null;
unset(self::$instance);// = null;
unset(self::$instanceOptionsKey); // = null;
*/

self::$client = null;
self::$instance = null;
self::$instanceOptionsKey = null;
//unset(self::$instance);
}
}

public function destroy()
{
self::$client = null;
self::$instance = null;
self::$instanceOptionsKey = null;
}

/**
* Before removing instance.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/Soluble/Japha/Bridge/Driver/Pjb62/SocketHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

namespace Soluble\Japha\Bridge\Driver\Pjb62;

use Soluble\Japha\Bridge\Driver\Pjb62\Exception\BrokenConnectionException;

class SocketHandler
{
/**
Expand Down Expand Up @@ -100,10 +102,11 @@ public function dieWithBrokenConnection($msg = '')

// Log error
$client = $this->protocol->getClient();
$client->getLogger()->critical("[soluble-japha] Broken connection: $msg (" . __METHOD__ . ')');
$client->getLogger()->critical("[soluble-japha] Broken connection: $msg, check the backend log for details\" (" . __METHOD__ . ')');

unset($this->protocol->client->protocol);
trigger_error($msg, E_USER_ERROR);

throw new BrokenConnectionException("Broken connection: $msg, check the backend log for details");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,5 @@ public function testJavaContext()
'standalone' => 'php.java.bridge.http.Context'
];
$this->assertTrue(in_array($fqdn, $supported));

}
}

0 comments on commit 9e8edbc

Please sign in to comment.