ORA-28040: No matching authentication protocol error

We have got following error in Application logs and we were made to cross-check our JVM settings.

ERROR [2016-06-06 03:32:55,521]|[server.startup : 1]|[null]|getConnection
java.sql.SQLException: ORA-28040: No matching authentication protocol
DSRA0010E: SQL State = 99999, Error Code = 28,040
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:389)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:382)
at oracle.jdbc.driver.T4CTTIoauthenticate.processError(T4CTTIoauthenticate.java:441)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4CTTIoauthenticate.doOSESSKEY(T4CTTIoauthenticate.java:404)
at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:385)
at oracle.jdbc.driver.PhysicalConnection.<init>(PhysicalConnection.java:546)
at oracle.jdbc.driver.T4CConnection.<init>(T4CConnection.java:236)
at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:32)
at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:521)
at oracle.jdbc.pool.OracleDataSource.getPhysicalConnection(OracleDataSource.java:280)
at oracle.jdbc.pool.OracleDataSource.getConnection(OracleDataSource.java:207)
at oracle.jdbc.pool.OracleConnectionPoolDataSource.getPhysicalConnection(OracleConnectionPoolDataSource.java:139)

It was determined that removing JVM parameter -Doracle.jdbc.thinLogonCapability=o3 will fix the ORA-28040: No matching authentication protocol error. I remembered that we added this JVM parameter for certain applications during the WebSphere 7 upgrade. The problem was that certain applications running on WebSphere 7 with JDK 1.6 and ojdbc6.jar was not able to login to the Database. This was because of an Oracle driver “issue” when dealing with external 3rd party JCE libraries such as BouncyCastle.

Purpose of [^\x20-\x7E] in Regular Expressions

Purpose of [^\x20-\x7E] in Regular Expressions defines all characters that are not (^) in the range \x20-\x7E (hex 0x20 to 0x7E). According to http://www.asciitable.com/, those are characters from ‘space’ to ‘~’. Hence, given below Java code will work very efficiently:-

String updateMessage = message.replaceAll("[^\\x20-\\x7e]", "");

Happy Coding !!

Step by Step Learning for Blockchain using BlocApps

— ================================================
— URLs Followed:
— ================================================

— ================================================
— Prerequisites (Software to be installed)
— ================================================

— ================================================
— Steps to install bloc from NPM (Node.js Package Manager)
— Here, C:\> refers to Node.js Command Prompt
— ================================================
— Following commands needs to be executed if we have to by-pass Proxy Settings

C:\>npm config set strict-ssl false
C:\>npm config set registry "http://registry.npmjs.org/"
C:\>npm config set proxy http://<Username>:<UserPassword>@
C:\>npm config set http-proxy http://<Username>:<UserPassword>@
C:\>npm config set https-proxy https://<Username>:<UserPassword>@

--Commands used for the listing/deleting the Key/Value (if required)
-- npm config list
-- npm config delete proxy
-- npm config delete http-proxy
-- npm config delete https-proxy
-- npm config delete strict-ssl

C:\>npm install -g blockapps-bloc

C:\>bloc init
	? ==========================================================================
	? ==========================================================================
	We're constantly looking for ways to make blockapps-bloc better!
	May we anonymously report usage statistics to improve the tool over time?
	More info: https://github.com/blockapps/bloc & http://blockapps.net
	========================================================================== No
		____  __           __   ___
	   / __ )/ /___  _____/ /__/   |  ____  ____  _____
	  / __  / / __ \/ ___/ //_/ /| | / __ \/ __ \/ ___/
	 / /_/ / / /_/ / /__/ ,< / ___ |/ /_/ / /_/ (__  )
	/_____/_/\____/\___/_/|_/_/  |_/ .___/ .___/____/
								  /_/   /_/
	prompt: Enter the name of your app:  Programming_BlocApps
	prompt: Enter your name:  VinayChauhan
	prompt: Enter your email so BlockApps can reach you:  vinaychauhan.java@gmail.com
	prompt: apiURL:  (http://strato-dev4.blockapps.net) http://strato-dev4.blockapps.net
	prompt: Enter the blockchain profile you wish to use.  Options: strato-dev, ethereum:  (strato-dev) strato-dev
	report obj: {"initName":"VinayChauhan","initEmail":"vinaychauhan.java@gmail.com","initTimestamp":"1471955873"}
	Wrote: C:\Programming_BlocApps\.bowerrc
	Wrote: C:\Programming_BlocApps\app.js
	Wrote: C:\Programming_BlocApps\bower.json
	Wrote: C:\Programming_BlocApps\gulpfile.js
	Wrote: C:\Programming_BlocApps\marko-taglib.json
	Wrote: C:\Programming_BlocApps\package.json
	Wrote: C:\Programming_BlocApps\test\common.js
	Wrote: C:\Programming_BlocApps\test\top.js
	Wrote: C:\Programming_BlocApps\app\lib\abi.js
	Wrote: C:\Programming_BlocApps\app\lib\analytics.js
	Wrote: C:\Programming_BlocApps\app\lib\cmd.js
	Wrote: C:\Programming_BlocApps\app\lib\codegen.js
	Wrote: C:\Programming_BlocApps\app\lib\compile.js
	Wrote: C:\Programming_BlocApps\app\lib\contract-helpers.js
	Wrote: C:\Programming_BlocApps\app\lib\icon.js
	Wrote: C:\Programming_BlocApps\app\lib\keygen.js
	Wrote: C:\Programming_BlocApps\app\lib\prompt-schema.js
	Wrote: C:\Programming_BlocApps\app\lib\scaffold.js
	Wrote: C:\Programming_BlocApps\app\lib\upload.js
	Wrote: C:\Programming_BlocApps\app\lib\yaml-config.js
	Wrote: C:\Programming_BlocApps\app\routes\addresses.js
	Wrote: C:\Programming_BlocApps\app\routes\contract.js
	Wrote: C:\Programming_BlocApps\app\routes\examples.js
	Wrote: C:\Programming_BlocApps\app\routes\home.js
	Wrote: C:\Programming_BlocApps\app\routes\users.js
	Wrote: C:\Programming_BlocApps\test\config\config.test.js
	Wrote: C:\Programming_BlocApps\test\contract\contract.test.js
	Wrote: C:\Programming_BlocApps\test\keygen\keygen.test.js
	Wrote: C:\Programming_BlocApps\test\multi\multi.test.js
	Wrote: C:\Programming_BlocApps\app\contracts\Greeter.sol
	Wrote: C:\Programming_BlocApps\app\contracts\MultiContract.sol
	Wrote: C:\Programming_BlocApps\app\contracts\Payout.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleDataFeed.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleMultiSig.sol
	Wrote: C:\Programming_BlocApps\app\contracts\SimpleStorage.sol
	Wrote: C:\Programming_BlocApps\app\contracts\Stake.sol
	Wrote: C:\Programming_BlocApps\app\contracts\template.marko
	Wrote: C:\Programming_BlocApps\app\static\css\styles.css
	Wrote: C:\Programming_BlocApps\app\components\contractJS\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractFunctions\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contracts\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractNameList\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractFunctionsCall\template.marko
	Wrote: C:\Programming_BlocApps\app\components\contractStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\globalKeystore\template.marko
	Wrote: C:\Programming_BlocApps\app\components\header\template.marko
	Wrote: C:\Programming_BlocApps\app\components\home\home.marko
	Wrote: C:\Programming_BlocApps\app\components\keyModal\template.marko
	Wrote: C:\Programming_BlocApps\app\components\loginStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\keyStatus\template.marko
	Wrote: C:\Programming_BlocApps\app\components\navTemplate\template.marko
	Wrote: C:\Programming_BlocApps\app\components\login\template.marko
	Wrote: C:\Programming_BlocApps\app\components\selectUser\template.marko
	project initiated!
	now type `cd Programming_BlocApps && npm install`
	thanks for registering with BlockApps!

C:\>cd Programming_BlocApps && npm install

C:\Programming_BlocApps>bloc genkey
	prompt: Enter a high entropy password. You will need this to sign transactions.: <<Test@1234>>

	wrote app\users\admin\e2807b606286be178347eac8609527fdb26dc703.json
		...waiting for transaction to be mined
	transaction successfully mined!

------ ================================================
------ URL For Testing/Verificatrion:
------ http://strato-dev4.blockapps.net/eth/v1.2/account?address=e2807b606286be178347eac8609527fdb26dc703
------ ================================================

—— ================================================
—— URL For Testing/Verificatrion:
—— ================================================


— ================================================
— Sample Program
— HelloWorld.sol is a contract which is already placed at location :- C:\Programming_BlocApps\app\contracts\HelloWorld.sol
— ================================================

C:\Programming_BlocApps>bloc compile HelloWorld.sol
	Compiling single contract: HelloWorld.sol
	Compile successful: contract HelloWorld {

		function getMessage1() public returns (string outMessage)  {
			return "Ananya Chauhan";

		function getMessage2(string inMessage) public returns (string outMessage)  {

			return inMessage;

	writing HelloWorld to app\meta\HelloWorld\HelloWorld.json
	wrote: app\meta\HelloWorld\HelloWorld.json

C:\Programming_BlocApps>bloc upload HelloWorld
	address: e2807b606286be178347eac8609527fdb26dc703
	prompt: Enter password to retrieve private key:
	upload contract: HelloWorld
		...waiting for transaction to be mined
	writing: app\meta\HelloWorld\102e4d7afa14a10cf0f0bb9dbd19d5c4555b2069.json
	writing: app\meta\HelloWorld\Latest.json
	creating metadata for HelloWorld

------ ================================================
------ URL For Testing/Verificatrion wherein balance could be checked:
------ http://strato-dev4.blockapps.net/eth/v1.2/account?address=e2807b606286be178347eac8609527fdb26dc703
------ ================================================	

C:\Programming_BlocApps>bloc start
	bloc is listening on
	api is pointed to http://strato-dev4.blockapps.net with profile strato-dev

— ================================================
— How to execute contract in UI
— * Also, sample javascript code using blockapps.js is shared at location C:\Programming_BlocApps\app\indexBlockChain-HelloWorld.html
— * We can use this code from UI point of view and do the necessary integration
— ================================================

Once the server is started using command “bloc start” then run following URL http://localhost:8008/contracts in browser and click on “Generate HTML”

— ================================================
— Issues Faced/Resolved
— ================================================

(1) How to Check Versions of Node and NPM
C:\Programming_BlocApps>npm -v
C:\Programming_BlocApps>node -v

(2) Unable to start the server using command :- bloc start
[Comments also updated at URL:-https://github.com/blockapps/bloc/issues/185]
Steps followed for Resolution:-

	(a) C:\Programming_BlocApps>node app.js start
		throw err;
		Error: Cannot find module './tatus/template'
			at Function.Module._resolveFilename (module.js:339:15)
			at Function.require.resolve (internal/module.js:23:19)
			at create (C:\Programming_BlocApps\app\components\contracts\template.marko.js:10:46)
			at Object.Template.c (C:\Programming_BlocApps\node_modules\marko\runtime\marko-runtime.js:103:18)
			at Object.<anonymous> (C:\Programming_BlocApps\app\components\contracts\template.marko.js:37:51)
	(b) Edit/Update a file :- C:\Programming_BlocApps\app\components\contracts\template.marko.js
		___contractFunctionsCall_template = __helpers.l(require.resolve("../contractFunctionsCall/template"));
        //___tatus_template = __helpers.l(require.resolve("../tatus/template"));
		//___tatus_template.render({"contractMeta": data.contractMeta, "apiURL": data.apiURL}, out);
	(c) C:\Programming_BlocApps>bloc start
		bloc is listening on
		api is pointed to http://strato-dev4.blockapps.net with profile strato-dev

(3) How to see contract in UI?
Once the server is started using command “bloc start” then run following URL http://localhost:8008/contracts in browser

(4) How to change the port for server in node.js?
It could be done by modifying the port settings in file C:\Programming_BlocApps\app.js
At line no. 45, we do have the port number specifications i.e. given below
var port = process.env.PORT || 8000;

(5) Any online tool for compilation of Solidity code?
Code could be compiled at https://ethereum.github.io/browser-solidity/

How to access Tomcat Manager from Eclipse

It has been observed that Tomcat Manager is not accessible after starting the Tomcat Server from Eclipse. Even after doing changes in file – $TOMCAT_HOME/conf/tomcat-users.xml changes are not getting reflected back.

Therefore, we need to configure Eclipse to take control over from Tomcat, we need to do double-click the Tomcat Server entry in Servers tab and then we will get the server configuration. At the left column, under Server Locations, select Use Tomcat installations (If it is grayed-out then delete the Server and add it again). This way Eclipse will take full control over Tomcat and we will be able to access the default Tomcat homepage with the Tomcat Manager when running from inside Eclipse.

Configuration to access Tomcat Manager from Eclipse
Configuration to access Tomcat Manager from Eclipse

Note: Above stated configuration is validated on Apache-Tomcat-8.0.33

How to enable Tomcat Manager

To access the Tomcat Manager page, we need to define users in file – $TOMCAT_HOME/conf/tomcat-users.xml. By default, there is NO user which means that no one can access the Tomcat Manager page.

To access the above mentioned page, we need to add a user(s) as the role “manager-gui”

	<role rolename="manager-gui"/>
	<user username="admin" password="admin" roles="manager-gui"/>

Once done then save the file and restart the Tomcat Server and we should able to access the default manager page (http://localhost:8080/manager) with user = “admin” and password = “admin”

Note: Above stated configuration is validated on Apache-Tomcat-8.0.33

SQLException: Failed preTestConnection

Today while working on a project requirement, we got following SQL Exception:-

java.sql.SQLException: Failed preTestConnection.
Pool requests blocked for jdbc/XXYYSZDB until the test connection thread is successful.

Since, our application uses pooled JDBC database connections from the app server hence when the connection to our database fails, pooled connections that are no longer valid might exist in the free pool.

Therefore, connection pretesting is a way to test connections from the free pool before giving them to the client. We can enable the PreTest Connections feature in the WebSphere administrative console to prevent application from obtaining connections that are no longer valid.

The feature is particularly useful for routine database outages. Because these outages are usually scheduled for periods of low use, connections to the database are likely to be in the free pool rather than in active use. Active connections are not pretested; pretesting impedes performance during normal operation.

For doing configuration in WebSphere 6.0.x, following are the steps:-
(1) In the administrative console, click Resources > JDBC providers.
(2) Select a provider and click Data Sources under Additional properties.
(3) Select a data source and click WebSphere Application Server data source properties under Additional properties.
(4) Select the PreTest Connections check box.
(5) Type a value for the PreTest Connection Retry Interval, which is measured in seconds. This property determines the frequency with which a new connection request is made after a pretest operation fails.
(6) Type a valid SQL statement for the PreTest SQL String. Use a reliable SQL command, with minimal performance impact; this statement is processed each time a connection is obtained from the free pool. For example, “select 1 from dual” in oracle or “SQL select 1” in SQL Server.