Integrating BIRT with Esproc - java
We've been using Esproc with our BIRT reports for a while now and everything worked perfectly. We followed this tutorial and things worked. However, the latest version of their software incorporated a couple of new functionalities and as such, we now need to upgrade the version running with BIRT. The thing is that now, nothing's working. We keep getting NullPointerException when trying to run reports. This is what we're getting so far:
The following report will be sent to Eclipse:
------
STATUS
------
pluginId org.eclipse.jface
pluginVersion 3.12.0.v20160518-1929
code 2
severity 4
message Problems occurred when invoking code from plug-in: "org.eclipse.jface".
fingerprint eb22eddc61b2abbaef12193bb7441fab
Exception:java.lang.NullPointerException: null
at com.esproc.jdbc.Server.getDfxList(Unknown Source:88)
at com.esproc.jdbc.InternalConnection.getMetaData(Unknown Source:314)
at org.eclipse.birt.report.data.oda.jdbc.ui.provider.JdbcMetaDataProvider.isSupportSchema(JdbcMetaDataProvider.java:305)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createDBMetaDataSelectionComposite(SQLDataSetEditorPage.java:405)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageControl(SQLDataSetEditorPage.java:334)
at org.eclipse.birt.report.data.oda.jdbc.ui.editors.SQLDataSetEditorPage.createPageCustomControl(SQLDataSetEditorPage.java:307)
at org.eclipse.datatools.connectivity.oda.design.ui.wizards.DataSetWizardPage.createControl(DataSetWizardPage.java:123)
at org.eclipse.datatools.connectivity.oda.design.internal.ui.DataSetEditorPageCore.createContents(DataSetEditorPageCore.java:74)
at org.eclipse.jface.preference.PreferencePage.createControl(PreferencePage.java:241)
at org.eclipse.birt.report.designer.data.ui.dataset.PropertyPageWrapper.createPageControl(PropertyPageWrapper.java:61)
at org.eclipse.birt.report.designer.data.ui.property.PropertyNode.createPageControl(PropertyNode.java:238)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showPage(AbstractPropertyDialog.java:577)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.showSelectionPage(AbstractPropertyDialog.java:482)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.showSelectionPage(DataSetEditor.java:913)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2$1.run(AbstractPropertyDialog.java:438)
at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog$2.selectionChanged(AbstractPropertyDialog.java:433)
at org.eclipse.jface.viewers.Viewer$1.run(Viewer.java:158)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:50)
at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:173)
at org.eclipse.jface.viewers.Viewer.fireSelectionChanged(Viewer.java:155)
at org.eclipse.jface.viewers.StructuredViewer.updateSelection(StructuredViewer.java:2191)
at org.eclipse.jface.viewers.StructuredViewer.setSelection(StructuredViewer.java:1728)
at org.eclipse.jface.viewers.TreeViewer.setSelection(TreeViewer.java:1077)
at org.eclipse.jface.viewers.Viewer.setSelection(Viewer.java:383)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.initTreeSelection(AbstractPropertyDialog.java:408)
at org.eclipse.birt.report.designer.data.ui.property.AbstractPropertyDialog.createDialogArea(AbstractPropertyDialog.java:299)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createDialogArea(DataSetEditor.java:124)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:767)
at org.eclipse.birt.report.designer.data.ui.dataset.DataSetEditor.createContents(DataSetEditor.java:602)
at org.eclipse.jface.window.Window.create(Window.java:426)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1095)
at org.eclipse.birt.report.designer.ui.dialogs.BaseDialog.open(BaseDialog.java:107)
at org.eclipse.birt.report.designer.data.ui.actions.EditDataSetAction.doAction(EditDataSetAction.java:105)
at org.eclipse.birt.report.designer.internal.ui.views.actions.AbstractElementAction.run(AbstractElementAction.java:70)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:473)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:565)
at org.eclipse.jface.action.ActionContributionItem.lambda$4(ActionContributionItem.java:397)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4410)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4228)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3816)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$4.run(PartRenderingEngine.java:1121)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1022)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:150)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:687)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:604)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:138)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
at sun.reflect.NativeMethodAccessorImpl.invoke0(null:-2)
at sun.reflect.NativeMethodAccessorImpl.invoke(null:-1)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(null:-1)
at java.lang.reflect.Method.invoke(null:-1)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:673)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:610)
at org.eclipse.equinox.launcher.Main.run(Main.java:1519)
------
REPORT
------
anonymousId 12355fbc-cb0f-41c4-b330-1d4a60fd5df2
name
email
comment
eclipseBuildId 4.6.0.I20160606-1100
eclipseProduct org.eclipse.epp.package.reporting.product
javaRuntimeVersion 1.8.0_71-b15
osgiWs win32
osgiOs Windows10
osgiOsVersion 10.0.0
osgiArch x86_64
severity UNKNOWN
-------
BUNDLES
-------
name org.eclipse.birt.report.data.oda.jdbc.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.data.oda.jdbc
version 4.6.0.v201606072122
name org.eclipse.birt
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui
version 4.6.0.v201606072122
name org.eclipse.birt.report.designer.ui.views
version 4.6.0.v201606072122
name org.eclipse.core.databinding.observable
version 1.6.0.v20160511-1747
name org.eclipse.core.databinding
version 1.6.0.v20160412-0910
name org.eclipse.core.runtime
version 3.12.0.v20160606-1342
name org.eclipse.datatools.connectivity.oda.design.ui
version 3.3.0.201603142002
name org.eclipse.datatools.connectivity.oda.design
version 3.4.0.201603142002
name org.eclipse.datatools.connectivity.oda
version 3.5.0.201603142002
name org.eclipse.datatools.connectivity
version 1.13.0.201603142002
name org.eclipse.e4.ui.workbench
version 1.4.0.v20160517-1624
name org.eclipse.e4.ui.workbench.swt
version 0.14.0.v20160523-1900
name org.eclipse.equinox.app
version 1.3.400.v20150715-1528
name org.eclipse.equinox.launcher
version 1.3.200.v20160318-1642
name org.eclipse.jface
version 3.12.0.v20160518-1929
name org.eclipse.swt
version 3.105.0.v20160603-0902
name org.eclipse.ui
version 3.108.0.v20160518-1929
name org.eclipse.ui.ide.application
version 1.1.100.v20160518-1929
name org.eclipse.ui.ide
version 3.12.0.v20160601-1609
Anyone has any idea what's going on?
Thanks
Okay, so I was able to actually get things working and the solution isn't exactly what I'd call trivial. I actually had to modify and recompile three BIRT classes. You can easily get the source code here if you don't want to do the Google search. Anyway, our first modification is given to us by the error message cited above. We need to alter JdbcMetaDataProvider.java located in the org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar package. What we're looking for is the isSupportSchema() method. and more specifically this bit of code:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
Not having access to Esproc's code, I can't exactly say why it does this, but connection.getMetaData( ).supportsSchemasInTableDefinitions( ); throws a NullPointerException. With no "catch" block to treat said exception, Eclipse will just stop its execution and prevent you from accessing your dataset. So we need to fix that like so:
try
{
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( SQLException e )
{
try
{
reconnect( );
return connection.getMetaData( ).supportsSchemasInTableDefinitions( );
}
catch ( Exception e1 )
{
try
{
ResultSet rs = connection.getMetaData( ).getSchemas( );
if( rs != null )
return true;
else
return false;
}
catch (SQLException e2)
{
logger.log( Level.WARNING, e.getMessage( ), e1 );
return false;
}
}
}
catch (NullPointerException e)
{
return false;
}
Now then, the next two bits of code we need to alter are located in the oda-jdbc.jar package. The first one we're looking for is the Connection.java class and more specifically the method populateConnectionProp( ).
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
This time the culprit throwing a NullPointerException is this line jdbcConn.getMetaData().getDriverName(). Again, not having access to Esproc's code, I don't really know why trying to recover the driver's name doesn't work, but anyway all we need to do is actually catch the exception and things will work normally again:
private void populateConnectionProp( ) throws SQLException
{
if( jdbcConn!= null )
{
if( this.autoCommit != null )
jdbcConn.setAutoCommit( this.autoCommit );
else
{
try
{
if (DBConfig.getInstance().qualifyPolicy(
jdbcConn.getMetaData().getDriverName(),
DBConfig.SET_COMMIT_TO_FALSE) ) {
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
catch(NullPointerException e)
{
this.autoCommit = false;
jdbcConn.setAutoCommit( false );
}
}
if( this.isolationMode!= Constants.TRANSCATION_ISOLATION_DEFAULT)
jdbcConn.setTransactionIsolation( this.isolationMode );
}
}
The other class we're looking for is the CallStatement.java class. In it we're going to have to locate the getCallableParamMetaData() method that I've pasted below:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
return paramMetaDataList;
}
Basically, somewhere within the while ( rs.next( ) ) loop lies the culprit throwing the NullPointerException. So all we need to do to is add a catch statement to treat it as follow:
private java.util.List getCallableParamMetaData( )
{
java.util.List paramMetaDataList = new ArrayList( );
try
{
DatabaseMetaData metaData = conn.getMetaData( );
String cataLog = conn.getCatalog( );
String procedureNamePattern = getNamePattern( this.paramUtil.getProcedure( ) );
String schemaPattern = null;
if ( this.paramUtil.getSchema( ) != null )
{
schemaPattern = getNamePattern( this.paramUtil.getSchema( ) );
}
// handles schema.package.storedprocedure for databases such as
// Oracle
if ( !metaData.supportsCatalogsInProcedureCalls( ) )
{
if (this.paramUtil.getPackage( ) != null)
{
cataLog = getNamePattern( this.paramUtil.getPackage( ) );
}
}
java.sql.ResultSet rs = null;
rs = metaData.getProcedureColumns( cataLog,
schemaPattern,
procedureNamePattern,
null );
while ( rs.next( ) )
{
ParameterDefn p = new ParameterDefn( );
p.setParamName( rs.getString( "COLUMN_NAME" ) );
p.setParamInOutType( rs.getInt( "COLUMN_TYPE" ) );
p.setParamType( rs.getInt( "DATA_TYPE" ) );
p.setParamTypeName( rs.getString( "TYPE_NAME" ) );
p.setPrecision( rs.getInt( "PRECISION" ) );
p.setScale( rs.getInt( "SCALE" ) );
p.setIsNullable( rs.getInt( "NULLABLE" ) );
if ( p.getParamType( ) == Types.OTHER )
correctParamType( p );
paramMetaDataList.add( p );
}
rs.close( );
}
catch ( SQLException e )
{
logger.log( Level.SEVERE, "Fail to get SP paramters", e );
}
catch( JDBCException ex)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex );
}
catch( NullPointerException ex1)
{
logger.log( Level.SEVERE, "Fail to get SP paramters", ex1 );
}
return paramMetaDataList;
}
Once you've done your modifications to the files, you actually need to recompile your source code. To do this successfully, you're going to need to copy a couple of jars from Eclipse's plugin folder into the same folder as where you've placed the file you're trying to compile. The jars are given below in the command you need to enter to compile your source code. Here's what you need to enter in order to compile each file:
JdbcMetaDataProvider.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/org.eclipse.birt.report.data.oda.jdbc.ui_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design_3.4.0.201603142002.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda.design.ui_3.3.0.201603142002.jar;
c:/mypath/org.eclipse.emf.ecore_2.12.0.v20160420-0247.jar;
c:/mypath/org.eclipse.emf.common_2.12.0.v20160420-0247.jar" JdbcMetaDataProvider.java > log.txt 2>&1
Connection.java
javac -cp ".;
c:/mypath/org.eclipse.birt.report.data.bidi.utils_4.6.0.v201606072122.jar;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" Connection.java > log.txt 2>&1
CallStatement.java
javac -cp ".;
c:/mypath/oda-jdbc.jar;
c:/mypath/org.eclipse.datatools.connectivity.oda_3.5.0.201603142002.jar;
c:/mypath/com.ibm.icu_56.1.0.v201601250100.jar" CallStatement.java > log.txt 2>&1
Now, there's a couple of things that need to be said about the two above commands:
1) They actually need to be entered on one line. I merely broke them down like so for clarity purposes so that each jar needed was easy to spot.
2) This is actually a windows command. If you're running the command on Linux, each jar needs to be separated by a colon(:) instead of a semi-colon(;).
Once the compilation is successful, you'll end up with the following .class files:
JdbcMetaDataProvider$1TempThread.class
JdbcMetaDataProvider$2TempThread.class
JdbcMetaDataProvider.class
Connection$Constants.class
Connection.class
CallStatement.class
These need to be copied back into the original jar files so that they replace the files already there. Luckily, a jar file is nothing more than a zip file so in windows, any unzipping software will easily open things up for you and allow you to navigate to the proper folder.
Here are the the folders in question for each jar:
org\eclipse\birt\report\data\oda\jdbc\ui\provider\
org\eclipse\birt\report\data\oda\jdbc\
org\eclipse\birt\report\data\oda\jdbc\
Once that's done, restart Eclipse and things should work like normal again. I hope this helps someone in the future.
Related
Writing foreach statement to filter Binance API results returns arbitrary data
I'm calling Binance API that returns a list of data. Now I want to filter the data to get some results and store using foreach statement in Java but it's been giving the result inclusively some arbitrary data result. I'm sure it is because of the way the foreach cascades. What I'm trying to achieve is this: private void pairscompared(){ List<Double> myPrice = new ArrayList<>(); List<TickerPrice> allPrices = client.getAll() aww; for ( String btcPairsOnly: BTCPairsOnly()) { for (String usdtPairsOnly: USDTPairsOnly()) { if (btcPairsOnly.substring(0, btcPairsOnly.length()-3).equals(usdtPairsOnly.substring(0, usdtPairsOnly.length()-4))) { for ( TickerPrice tickerPrice: allPrices ) { if (btcPairsOnly.equals(tickerPrice.getSymbol()) ) { myPrice.add(BTCUSDTPrice()/Double.parseDouble(tickerPrice.getPrice())); } if( usdtPairsOnly.equals(tickerPrice.getSymbol()) ) { for ( Double myPriceBTC: myPrice) { System.out.println(usdtPairsOnly +"-----" +myPriceBTC * Double.parseDouble(tickerPrice.getPrice())); } } } } } } } } This is the kind of result I'm getting. It is supposed to return a single result per currency pair, but returning multiple per pair. SRMUSDT,1018.9288322183007 ANTUSDT,13.774766561800812 ANTUSDT,91.36056959924552 ANTUSDT,256.1968943442934 ANTUSDT,367.53275089477034 ANTUSDT,6.177161506010758 ANTUSDT,1052.5387358691876 ANTUSDT,10574.05783480371 ANTUSDT,30001.77456723378 ANTUSDT,1790.6866920747113 ANTUSDT,2042.9811238046154 ANTUSDT,10587.61664808673 ANTUSDT,9757.716721797087 ANTUSDT,3246.2358031974827 ANTUSDT,1086433.2751325325 ANTUSDT,14039.257227727085 ANTUSDT,315.8280072030071 ANTUSDT,15174.461192736637 ANTUSDT,1551.7672913989231 ANTUSDT,804.6112468325528 ANTUSDT,69.52890427406093 ANTUSDT,2811.71983308228 ANTUSDT,61.50578628470293 ANTUSDT,206179.87846750594 ANTUSDT,18977.432417513217 ANTUSDT,28847.210473068306 ANTUSDT,19769.6990579948 ANTUSDT,3525.053479979846 ANTUSDT,7534.449812274411 ANTUSDT,11638.697448816409 ANTUSDT,64.86093827635698 ANTUSDT,19711.91847695616 ANTUSDT,8970.326322598154 ANTUSDT,171935.90547808146 ANTUSDT,860.5867421958602 ANTUSDT,3436.871425977244 ANTUSDT,62423.31734545072 ANTUSDT,42487.32420280973 ANTUSDT,52233.91847232688 ANTUSDT,10956.270509605802 ANTUSDT,1386.125792090672 ANTUSDT,530036.653245724 ANTUSDT,11622.776386012216 ANTUSDT,47105.8086880985 ANTUSDT,3397.7484133475873 ANTUSDT,823792.807291102 ANTUSDT,4814.360932388137 ANTUSDT,44171.13455068425 ANTUSDT,242624.30622636256 ANTUSDT,6851.488052540721 ANTUSDT,1429537.2832569634 ANTUSDT,13785.034666651782 ANTUSDT,272.76692934340844 ANTUSDT,1923.1819399426236 ANTUSDT,602.491161880425 ANTUSDT,151808.5142918124 ANTUSDT,15807.031391665156 ANTUSDT,669330.3478424352 ANTUSDT,94316.07425176422 ANTUSDT,1568178.5858503766 ANTUSDT,1.6708001897502722E7 ANTUSDT,3858573.770837548 ANTUSDT,6265299.392463503 ANTUSDT,1.2541500333864527E7 ANTUSDT,87374.88342534943 ANTUSDT,7164710.131229129 ANTUSDT,303085.5238352935 ANTUSDT,260527.40447495517 ANTUSDT,3731.181578744949 ANTUSDT,1990.4036985506448 ANTUSDT,236700.19018912394 ANTUSDT,344.07330952691433 ANTUSDT,517175.70918429096 ANTUSDT,17.10565434013944 ANTUSDT,44.84090796135899 ANTUSDT,14650.220516996562 ANTUSDT,9999637.309239421 ANTUSDT,30631.308936305937 ANTUSDT,44421.62550123691 ANTUSDT,505453.4045454992 ANTUSDT,212913.40241144891 ANTUSDT,1008.2532158446976 ANTUSDT,632660.0445964657 ANTUSDT,481469.7852672536 ANTUSDT,227497.62665903594 ANTUSDT,9946.725891879225 ANTUSDT,305130.5354576847 ANTUSDT,1669526.8054573308 ANTUSDT,57338.8681606322 ANTUSDT,421139.2657969 ANTUSDT,5.009062907989301E7 ANTUSDT,618027.3308269432 ANTUSDT,1.669325105689848E7 ANTUSDT,4592.007276561801 ANTUSDT,73022.88659001338 ANTUSDT,307591.42773404904 ANTUSDT,417.6749932669856 ANTUSDT,10557.793803567285 ANTUSDT,1485.2370786854685 ANTUSDT,118261.76524409353 ANTUSDT,185287.0857367485 ANTUSDT,22561.773674443128 ANTUSDT,1236.2723302784589 ANTUSDT,125570.41521446458 ANTUSDT,44314.9525104471 ANTUSDT,19.24354178729621 ANTUSDT,735174.4349151909 ANTUSDT,190190.9122818317 ANTUSDT,1741.4845673390487 ANTUSDT,12750.881037867899 ANTUSDT,1851734.706835224 ANTUSDT,609717.0111591265 ANTUSDT,40409.604959186814 ANTUSDT,68531.36047057436 ANTUSDT,2780158.009891447 ANTUSDT,80186.50832352106 ANTUSDT,202593.37220313048 ANTUSDT,1887.3043500308997 ANTUSDT,57686.7681303317 ANTUSDT,21541.17400538674 ANTUSDT,85889.49822902192 ANTUSDT,370080.0600848642 ANTUSDT,1850401.8600102018 ANTUSDT,5315.656100751345 ANTUSDT,176644.02650899472 ANTUSDT,31.539010746687662 ANTUSDT,1979.7888828042514 ANTUSDT,952.3952515801872 ANTUSDT,50757.17925737214 ANTUSDT,8.776068811879435 ANTUSDT,5569.711983320112 ANTUSDT,311.90254639586675 ANTUSDT,0.8419310354932523 ANTUSDT,81360.2740570123 ANTUSDT,3581.7496523396912 ANTUSDT,1021.9303834635372 CRVUSDT,10.412930641467927 CRVUSDT,69.06333187816846 CRVUSDT,193.67010536241355 CRVUSDT,277.8336043928448 CRVUSDT,4.669578539473018 CRVUSDT,795.6586999054995 CRVUSDT,7993.379077509899 CRVUSDT,22679.614662647327 CRVUSDT,1353.6560668027703 CRVUSDT,1544.3761350554992 CRVUSDT,8003.6287599029365 CRVUSDT,7376.27218489005 CRVUSDT,2453.967413014815 CRVUSDT,821281.0206098281 CRVUSDT,10612.870360754605 CRVUSDT,238.7477943007701 CRVUSDT,11471.019215657485 CRVUSDT,1173.0467521565827 CRVUSDT,608.2397889664911 CRVUSDT,52.559849528833624 CRVUSDT,2125.498350463366 CRVUSDT,46.49483414169978 CRVUSDT,155860.12035239537 CRVUSDT,14345.846561546086 CRVUSDT,21806.83066447679 CRVUSDT,14944.754538670091 CRVUSDT,2664.7375278421123 CRVUSDT,5695.610373129821 CRVUSDT,8798.185344762103 CRVUSDT,49.03113592394278 CRVUSDT,14901.075745270604 CRVUSDT,6781.050365497971 CRVUSDT,129973.64786464954 CRVUSDT,650.5540414966429 CRVUSDT,2598.0769707987974 CRVUSDT,47188.43481029146 CRVUSDT,32117.97151556091 CRVUSDT,39485.83576673866 CRVUSDT,8282.309859396324 CRVUSDT,1047.8313130486192 CRVUSDT,400677.20080201246 CRVUSDT,8786.149937702776 CRVUSDT,35609.27994523498 CRVUSDT,2568.5022251818646 CRVUSDT,622739.9445773957 CRVUSDT,3639.3797489804215 CRVUSDT,33390.83521797934 CRVUSDT,183410.00998706592 CRVUSDT,5179.330594233003 CRVUSDT,1080647.9015932744 CRVUSDT,10420.692737700396 CRVUSDT,206.19609804609092 CRVUSDT,1453.8148477289499 CRVUSDT,455.44863882891923 CRVUSDT,114758.49866585882 CRVUSDT,11949.205875137332 CRVUSDT,505975.2161347491 CRVUSDT,71297.52327583302 CRVUSDT,1185452.7461233763 CRVUSDT,1.263028771744685E7 CRVUSDT,2916859.6702132453 CRVUSDT,4736205.708390937 CRVUSDT,9480652.360282563 CRVUSDT,66050.38254786693 CRVUSDT,5416108.456574679 CRVUSDT,229115.21033553488 CRVUSDT,196943.7217558706 CRVUSDT,2820.558505719945 CRVUSDT,1504.63062793418 CRVUSDT,178931.71925661966 CRVUSDT,260.09961705047544 CRVUSDT,390955.06737095467 CRVUSDT,12.930890075099084 CRVUSDT,33.89714536411249 CRVUSDT,11074.723440231724 CRVUSDT,7559150.223982632 CRVUSDT,23155.506409498947 CRVUSDT,33580.19195827093 CRVUSDT,382093.6798030234 CRVUSDT,160950.2768705742 CRVUSDT,762.1813958533816 CRVUSDT,478254.5776332747 CRVUSDT,363963.44413222047 CRVUSDT,171975.11092989525 CRVUSDT,7519.152238053682 CRVUSDT,230661.1214106458 CRVUSDT,1262066.1665155625 CRVUSDT,43344.88388882583 CRVUSDT,318357.0440534961 CRVUSDT,3.786563235437026E7 CRVUSDT,467193.0882864403 CRVUSDT,1.261913693101238E7 CRVUSDT,3471.2931839117077 CRVUSDT,55201.09904513555 CRVUSDT,232521.41432195855 CRVUSDT,315.7382534253357 CRVUSDT,7981.084406057156 CRVUSDT,1122.7537408420778 CRVUSDT,89399.08734564554 CRVUSDT,140066.3716426894 CRVUSDT,17055.402236142123 CRVUSDT,934.550721523993 CRVUSDT,94924.00603539583 CRVUSDT,33499.553317359765 CRVUSDT,14.547009927775411 CRVUSDT,555749.5559584612 CRVUSDT,143773.38224520267 CRVUSDT,1316.4620925900902 CRVUSDT,9638.932120499698 CRVUSDT,1399804.8520216339 CRVUSDT,460910.96496179735 CRVUSDT,30547.33536145826 CRVUSDT,51805.76383228634 CRVUSDT,2101639.4288380947 CRVUSDT,60616.38473568128 CRVUSDT,153148.92805678892 CRVUSDT,1426.6934548793733 CRVUSDT,43607.8762407032 CRVUSDT,16283.887632325857 CRVUSDT,64927.516838613155 CRVUSDT,279759.2235167563 CRVUSDT,1398797.2965409374 CRVUSDT,4018.330041578821 CRVUSDT,133532.71636331212 CRVUSDT,23.841676730588155 CRVUSDT,1496.6064382215447 CRVUSDT,719.9559900687989 CRVUSDT,38369.5059217377 CRVUSDT,6.634202868908979 CRVUSDT,4210.381665276148 CRVUSDT,235.78037188114766 CRVUSDT,0.6364514010569469 CRVUSDT,61503.68406793058 CRVUSDT,2707.596570699286 CRVUSDT,772.5205473117921 CRVUSDT,1022.6864367205029 SANDUSDT,0.1259172193123368 SANDUSDT,0.8351407500893632 SANDUSDT,2.341934463103714 SANDUSDT,3.359672324845054 SANDUSDT,0.05646636526219258 SANDUSDT,9.621415378950992 SANDUSDT,96.65905795446359 SANDUSDT,274.2507476255765 SANDUSDT,16.36893720950121 SANDUSDT,18.67519867309022 SANDUSDT,96.78300111227416 SANDUSDT,89.19676068075256 SANDUSDT,29.674331229997943 SANDUSDT,9931.250475957184 SANDUSDT,128.33496839273576 SANDUSDT,2.8870314621694995 SANDUSDT,138.71203910279323 SANDUSDT,14.184938922641505 SANDUSDT,7.355072797352887 SANDUSDT,0.6355742036530637 SANDUSDT,25.70235519263735 SANDUSDT,0.5622336716809071 SANDUSDT,1884.7213750089036 SANDUSDT,173.47557281498243 SANDUSDT,263.6967030540815 SANDUSDT,180.7178017032755 SANDUSDT,32.22304567811933 SANDUSDT,68.87354244106504 SANDUSDT,106.3910892861592 SANDUSDT,0.5929036222215496 SANDUSDT,180.18962069476297 SANDUSDT,81.99910624969272 SANDUSDT,1571.6920515942647 SANDUSDT,7.866753245377614 SANDUSDT,31.416960218635044 SANDUSDT,570.620961533241 SANDUSDT,388.38304051376554 SANDUSDT,477.4781291802055 SANDUSDT,100.15292167847562 SANDUSDT,12.670784987469869 SANDUSDT,4845.145012867183 SANDUSDT,106.24555244908782 SANDUSDT,430.6013039751177 SANDUSDT,31.05933085777829 SANDUSDT,7530.414335387361 SANDUSDT,44.008799615767266 SANDUSDT,403.77500493671687 SANDUSDT,2217.8653874490415 SANDUSDT,62.630485958292674 SANDUSDT,13067.615977624006 SANDUSDT,126.01108160790753 SANDUSDT,2.493403652917983 SANDUSDT,17.580096259549403 SANDUSDT,5.507462607360816 SANDUSDT,1387.7045321821527 SANDUSDT,144.4944587257736 SANDUSDT,6118.449690131112 SANDUSDT,862.1574640089909 SANDUSDT,14334.957041160738 SANDUSDT,152730.36604721603 SANDUSDT,35271.80497437512 SANDUSDT,57272.04697944015 SANDUSDT,114643.74666241262 SANDUSDT,798.706991461441 SANDUSDT,65493.69623475911 SANDUSDT,2770.5504992727724 SANDUSDT,2381.520309543317 SANDUSDT,34.10729372705667 SANDUSDT,18.19458049659484 SANDUSDT,2163.712148993348 SANDUSDT,3.145226032023446 SANDUSDT,4727.581182897244 SANDUSDT,0.15636536701837067 SANDUSDT,0.4098975047310421 SANDUSDT,133.91987599473248 SANDUSDT,91408.19326862818 SANDUSDT,280.0054162698304 SANDUSDT,406.0647805067772 SANDUSDT,4620.425827673874 SANDUSDT,1946.2735332534999 SANDUSDT,9.216594759141115 SANDUSDT,5783.240915785901 SANDUSDT,4401.1879454917425 SANDUSDT,2079.5901273928375 SANDUSDT,90.92452201990109 SANDUSDT,2789.24425903978 SANDUSDT,15261.396406786938 SANDUSDT,524.1432444543442 SANDUSDT,3849.6975650709082 SANDUSDT,457885.9974902715 SANDUSDT,5649.481071611036 SANDUSDT,152595.52638782345 SANDUSDT,41.97623130181651 SANDUSDT,667.5132231331655 SANDUSDT,2811.739646607821 SANDUSDT,3.8180301272272352 SANDUSDT,96.51038599121024 SANDUSDT,13.576776210950419 SANDUSDT,1081.0486380073978 SANDUSDT,1693.7372046040546 SANDUSDT,206.24057700682815 SANDUSDT,11.300951884958511 SANDUSDT,1147.858110027663 SANDUSDT,405.08966660443116 SANDUSDT,0.17590811871154619 SANDUSDT,6720.340423826196 SANDUSDT,1738.5638228829619 SANDUSDT,15.919173164268383 SANDUSDT,116.55772726654688 SANDUSDT,16926.986322616434 SANDUSDT,5573.515185766559 SANDUSDT,369.390295446547 SANDUSDT,626.4555052479955 SANDUSDT,25413.843805182103 SANDUSDT,732.9969701601485 SANDUSDT,1851.9365801573676 SANDUSDT,17.252133797387575 SANDUSDT,527.3234505643258 SANDUSDT,196.9111214561948 SANDUSDT,785.1288612847785 SANDUSDT,3382.95766245904 SANDUSDT,16914.80256870503 SANDUSDT,48.5912143791542 SANDUSDT,1614.7296962424527 SANDUSDT,0.28830285546164913 SANDUSDT,18.097548864421473 SANDUSDT,8.705988680622168 SANDUSDT,463.97903322367307 SANDUSDT,0.08022336903697878 SANDUSDT,50.91357753060775 SANDUSDT,2.85114823270517 SANDUSDT,0.007696218615860683 SANDUSDT,743.7265398136324 SANDUSDT,32.741313943296475 SANDUSDT,9.34161981179129 SANDUSDT,12.366723334107826 SANDUSDT,1023.277039109042
problem is in second if block for ( TickerPrice tickerPrice: allPrices ) { if (btcPairsOnly.equals(tickerPrice.getSymbol()) ) { myPrice.add(BTCUSDTPrice().divide(tickerPrice.getPrice(), RoundingMode.HALF_UP)); } if( usdtPairsOnly.equals(tickerPrice.getSymbol()) ) { for ( BigDecimal myPriceBTC: myPrice) { System.out.println(usdtPairsOnly +"-----" +myPriceBTC * Double.parseDouble(tickerPrice.getPrice())); } } } you print out all items from myPrices in every iteration when second if return true: if( usdtPairsOnly.equals(tickerPrice.getSymbol()) ) What exactly you want to do? Code should looks more like: private void pairscompared(){ List<TickerPrice> myPrice = new ArrayList<>(); List<TickerPrice> allPrices = client.getAll(); for ( String btcPairsOnly: BTCPairsOnly()) { for (String usdtPairsOnly: USDTPairsOnly()) { if (btcPairsOnly.substring(0, btcPairsOnly.length()-3).equals(usdtPairsOnly.substring(0, usdtPairsOnly.length()-4))) { for ( TickerPrice tickerPrice: allPrices ) { if (btcPairsOnly.equals(tickerPrice.getSymbol()) ) { myPrice.add( new TickerPrice(btcPairsOnly, BTCUSDTPrice()/Double.parseDouble(tickerPrice.getPrice())) ); } if( usdtPairsOnly.equals(tickerPrice.getSymbol()) ) { //TODO what you want to do when tickerPrice is usdtPairsOnly } } } } } for ( TickerPrice myPriceBTC: myPrice) { System.out.println(myPriceBTC +"-----" +myPriceBTC.getPrice())); } } }
How to manipulate parameters sending to remote object in CORBA using interceptors
New to CORBA but could establish remote method invoking from a client to server. When using interceptors and try to encrypt parameters for the remote method, it throws below Failed to initialise ORB: org.omg.CORBA.NO_RESOURCES: vmcid: OMG minor code: 1 completed: No org.omg.CORBA.NO_RESOURCES: vmcid: OMG minor code: 1completed: No at com.sun.corba.se.impl.logging.OMGSystemException.piOperationNotSupported1(Unknown Source) at com.sun.corba.se.impl.logging.OMGSystemException.piOperationNotSupported1(Unknown Source) at com.sun.corba.se.impl.interceptors.ClientRequestInfoImpl.arguments(Unknown Source) at orb.CustomClientInterceptor.send_request(CustomClientInterceptor.java:23) From Interceptors I'm trying to access arguments and encrypt them like below. public void send_request( ClientRequestInfo ri ) { System.out.println( ri.arguments() ); System.out.println( "Arguments.." ); logger( ri, "send_request" ); } But cannot even access them, it throws above error. Intercepting methods are calling fine. Could you guide me with some code or a link. Thanks in Advance
I found the answer and if someone hits this in future.. We cannot manipulate parameters in interceptors unless the call to CORBA object is either DII or DSI call. So first you need to make a call in either of these. I did it via DII. code is as follows. //-ORBInitialPort 1050 -ORBInitialHost localhost Properties p = new Properties(); p.put("org.omg.PortableInterceptor.ORBInitializerClass.orb.InterceptorORBInitializer", ""); //ORB orb = ORB.init(args, p); String[] orbArgs = { "-ORBInitialHost", "localhost", "-ORBInitialPort", "1050" }; //NO_NEED ORB orb = ORB.init( orbArgs, null ); orb = ORB.init(orbArgs, p); //objRef = orb.resolve_initial_references( "NameService" ); //ncRef = NamingContextExtHelper.narrow( objRef ); //DII Additional configs org.omg.CORBA.Object ncRef = orb.resolve_initial_references ("NameService"); NamingContext nc = NamingContextHelper.narrow (ncRef); NameComponent nComp = new NameComponent ("ABC", ""); NameComponent [] path = {nComp}; objRef = nc.resolve (path); Then do the DII call, I have some mixed code here but you will understand what to do NVList argList = orb.create_list (valueMap.size()); for (Map.Entry<String, String> entry : valueMap.entrySet()) { Any argument = orb.create_any (); argument.insert_string (entry.getValue()); argList.add_value (entry.getKey().toLowerCase(), argument, org.omg.CORBA.ARG_IN.value); } //Result Any result = orb.create_any (); result.insert_string( null ); NamedValue resultVal = orb.create_named_value ("result", result, org.omg.CORBA.ARG_OUT.value); //Invoking Method Request thisReq = objRef._create_request (null, methodName, argList, resultVal); thisReq.invoke (); //Extract Result result = thisReq.result().value (); Now from the interceptors you will need to filter the DII call only and then access the parameters like below. public void send_request( ClientRequestInfo ri ) { if(ri.operation().equals( "processPayment" )) { System.out.println( "################# CLIENT SIDE ###############" ); int count = 0; for(Parameter param : ri.arguments()) { System.out.println( "Arg : "+count ); System.out.println( param.argument.extract_string()); param.argument.insert_string( EncryptionDecryption.encrypt( param.argument.extract_string() ) ); count++; } } System.out.println( "Arguments.." ); logger( ri, "send_request" ); }
JNI attached to program successfully but cant get fields?
stackoverflow! I managed to inject my dll into the game minecraft(made in java) and i did attach to the main thread so i can get classes and field. Total code: #include <Windows.h> #include <jni.h> #include <iostream> #include <string> #include "MCClass.h" /* BOOL WINAPI DllMain( _In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID lpvReserved ); */ typedef jint (*hJNI_GetCreatedJavaVMs )( JavaVM** vmBuf , jsize bufLen , jsize* nVMs ); hJNI_GetCreatedJavaVMs oJNI_GetCreatedJavaVMs; HMODULE jvmHandle; FARPROC func_JNI_GetCreatedJavaVMs; JavaVM *jvm; JNIEnv *jenv; jclass Minecraft; jclass FMLH; jclass FMLHI; jclass launchWrapper; MCClass* mc = new MCClass ( ); using namespace std; void GetAllMinecraft ( ) { jfieldID f = jenv->GetFieldID ( Minecraft , "serverName" , "Ljava/lang/String;" ); if ( f != NULL ) { jstring str = (jstring)jenv->GetObjectField ( Minecraft , f ); mc->serverName = (char*)jenv->GetStringUTFChars( str , 0 ); cout << mc->serverName << endl; } else { MessageBox ( NULL , "serverName is null", "ERROR" , MB_OK ); } } /* void start ( ) { MessageBox ( NULL , "Initialization has completed." , "Works" , MB_OK ); FMLH = jenv->FindClass ( "net/minecraftforge/fml/relauncher/FMLLaunchHandler" ); if ( FMLH != nullptr ) { MessageBox ( NULL , "FMLLaunchHandler found successfully" , "OK" , MB_OK ); jfieldID f = jenv->GetStaticFieldID ( (jclass) FMLH , "INSTANCE" , "Lnet/minecraftforge/fml/relauncher/FMLLaunchHandler;" ); MessageBox ( NULL , "FMLH passed" , "OK" , MB_OK ); if ( f == nullptr ) { MessageBox ( NULL , "FMLLaunchHandler fieldID couldn't be found successfully" , "OK" , MB_OK ); } else { MessageBox ( NULL , "FMLLaunchHandler fieldID found successfully" , "OK" , MB_OK ); FMLHI = jenv->GetStaticObjectField ( (jclass) FMLH , f ); MessageBox ( NULL , "FMLHI passed" , "OK" , MB_OK ); if ( FMLHI == nullptr ) { MessageBox ( NULL , "FMLLaunchHandler instance couldn't be found successfully" , "OK" , MB_OK ); } else { MessageBox ( NULL , "FMLHI is not nullptr" , "OK" , MB_OK ); jfieldID f1 = jenv->GetFieldID ( ( jclass ) FMLHI , "classLoader" , "Lnet/minecraft/launchwrapper/LaunchClassLoader;" ); //HERE MessageBox ( NULL , "f1 passed" , "OK" , MB_OK ); if ( f1 == nullptr ) { MessageBox ( NULL , "classLoader fieldID couldn't be found successfully" , "OK" , MB_OK ); } else { MessageBox ( NULL , "classLoader fieldID found successfully" , "OK" , MB_OK ); launchWrapper = jenv->GetObjectField ( ( jclass ) FMLHI , f1 ); MessageBox ( NULL , "launchWrapper passed" , "OK" , MB_OK ); if ( launchWrapper == nullptr ) { MessageBox ( NULL , "classLoader class couldn't be found successfully" , "OK" , MB_OK ); } else { MessageBox ( NULL , "classLoader class found successfully" , "OK" , MB_OK ); jmethodID mmid = jenv->GetMethodID ( ( jclass ) launchWrapper , "findClass" , "(Ljava/lang/String;)Ljava/lang/Class;" ); MessageBox ( NULL , "findClass passed" , "OK" , MB_OK ); if ( mmid != NULL ) { Minecraft = ( jclass ) jenv->CallNonvirtualObjectMethod ( launchWrapper , ( jclass ) launchWrapper , mmid , "net.minecraft.client.Minecraft" ); MessageBox ( NULL , "Minecraft class found successfully" , "OK" , MB_OK ); // GetAllMinecraft ( ); } else { MessageBox ( NULL , "findClass method ID couldn't be found successfully" , "OK" , MB_OK ); } } } } } } else { MessageBox ( NULL , "FMLLaunchHandler couldn't be found successfully" , "OK" , MB_OK ); } } */ const char* GetObjName ( jobject cls ) { jclass clsClazz = jenv->GetObjectClass ( cls ); jmethodID methodId = jenv->GetMethodID ( clsClazz , "getName" , "()Ljava/lang/String;" ); jstring className = ( jstring ) jenv->CallObjectMethod ( cls , methodId ); return jenv->GetStringUTFChars ( className , NULL ); jenv->DeleteLocalRef ( clsClazz ); } void start ( ) { jclass preMC = jenv->FindClass ( "net/minecraftforge/fml/relauncher/FMLLaunchHandler" ); if ( preMC != NULL ) { /*Section intercept custom findClassStart*/ jfieldID iID = jenv->GetStaticFieldID ( preMC , "INSTANCE" , "Lnet/minecraftforge/fml/relauncher/FMLLaunchHandler;" ); cout << "IID: " << iID << endl; jobject instance = jenv->GetStaticObjectField ( preMC , iID ); cout << "INSTANCE: " << instance << endl; jfieldID lID = jenv->GetFieldID ( preMC , "classLoader" , "Lnet/minecraft/launchwrapper/LaunchClassLoader;" ); cout << "LID: " << lID << endl; jobject classLoader = jenv->GetObjectField ( instance , lID ); cout << "classLoader: " << classLoader << endl; jmethodID fid = jenv->GetMethodID ( jenv->GetObjectClass(classLoader) , "findClass" , "(Ljava/lang/String;)Ljava/lang/Class;" ); cout << "FID: " << fid << endl; jobject a = jenv->CallNonvirtualObjectMethod ( classLoader , jenv->GetObjectClass(classLoader), fid , "net/minecraft/client/Minecraft" ); preMC = ( jclass ) a; cout << "preMC: " << preMC << endl; /*Section intercept custom findClassEND*/ /*Section getDisplayWidthStart*/ jfieldID mid = jenv->GetStaticFieldID ( jenv->GetObjectClass(preMC) , "theMinecraft" , "Lnet/minecraft/client/Minecraft;" ); cout << "MID: " << mid << endl; jobject MC = jenv->GetStaticObjectField ( jenv->GetObjectClass(preMC) , mid ); cout << "MC: " << MC << endl; jfieldID mid2 = jenv->GetFieldID ( jenv->GetObjectClass(MC) , "displayWidth" , "I" ); cout << "MID2: " << mid2 << endl; int displayWidth = jenv->GetIntField ( MC , mid2 ); cout << "DisplayWidth: " << displayWidth << endl; /*Section getDisplayWidthEND*/ } } void init ( ) { jvmHandle = GetModuleHandleA ( "jvm.dll" ); func_JNI_GetCreatedJavaVMs = GetProcAddress ( jvmHandle , "JNI_GetCreatedJavaVMs" ); oJNI_GetCreatedJavaVMs = ( hJNI_GetCreatedJavaVMs ) func_JNI_GetCreatedJavaVMs; jint returnOF = oJNI_GetCreatedJavaVMs ( &jvm , 1 , NULL ); jint returnOf1 = jvm->AttachCurrentThread ( ( void ** ) &jenv , NULL ); if ( jenv != nullptr ) { start ( ); } if ( jenv->ExceptionCheck ( ) ) { jenv->ExceptionDescribe ( ); } jvm->DetachCurrentThread ( ); } BOOL WINAPI DllMain ( HINSTANCE hinstDLL , DWORD fdwReason , LPVOID lpvReserved ) { switch ( fdwReason ) { case DLL_PROCESS_ATTACH: init ( ); //case DLL_PROCESS_DETACH: //case DLL_THREAD_ATTACH: //case DLL_THREAD_DETACH: } } NOTE: this game uses a custom class launcher, + i use the forge api on it. I looked at the cout debugs and looks like the cout's stop at : cout << "FID: " << fid << endl; After that no more cout's get called. then the game stops responding. Thank you for reading and hopefully i was descriptive enough. EDIT: The whole code stops the game minecraft from responding after some time or instantly idk its random. I use standard injection with extreme injector for now. This is some information i got from debugging: IID: 0000000024D1FE80 INSTANCE: 00000000191813F8 LID: 0000000000000032 classLoader: 0000000019181400 FID: 0000000016176C90 # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000002d7688e, pid=6048, tid=0x0000000000001648 # # JRE version: Java(TM) SE Runtime Environment (8.0_92-b14) (build 1.8.0_92-b14) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.92-b14 mixed mode windows-amd64 compressed oops) # Problematic frame: # J 3576 C2 net.minecraft.launchwrapper.LaunchClassLoader.findClass(Ljava/lang/String;)Ljava/lang/Class; (695 bytes) # 0x0000000002d7688e [0x0000000002d76820+0x6e] # # Failed to write core dump. Minidumps are not enabled by default on client versions of Windows # # An error report file with more information is saved as: # C:\Users\Balen\Desktop\ForgeMod\eclipse\hs_err_pid6048.log # # If you would like to submit a bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # AL lib: (EE) alc_cleanup: 1 device not closed :runClient FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':runClient'. > Process 'command 'C:\Program Files\Java\jdk1.8.0_92\bin\java.exe'' finished with non-zero exit value 1 * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 8 mins 50.128 secs Edit: This is to better explain everything: I inject this dll into the game after everything in the game has initialized. The games uses a custom class loader(LaunchClassLoader) i try to retrieve a instance of that, to do so i get the FMLLaunchHandler there i get a instanceof FMLLaunchHandler then from that instance i get classLoader and from that instance i use the classLoaders findClass to get the class. Someone told me that i need to get a initialized version of a class to use non static methods or get non static fields. I use a injector called extreme injector for now and use standard injection which is loadlibrary. I also do not create my own vm, i attach to the running minecraft vm and get the env from that thru a dll and init function handles the attaching. Thanks for reading, have nice day.
Downloading artifacts from remote maven repo programmatically
I am using Aether utility library to manage deppendencies. When I try to download the transitive dependencies for a maven artifact I get a java.io.IOException: Invalid Content-Range header for partial download error. I am using almost the same code from the aether example here https://github.com/eclipse/aether-demo/blob/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ResolveTransitiveDependencies.java /** * Resolves the transitive (compile) dependencies of an artifact. */ public class ResolveTransitiveDependencies { public static void main( String[] args ) throws Exception { System.out.println( "------------------------------------------------------------" ); System.out.println( ResolveTransitiveDependencies.class.getSimpleName() ); RepositorySystem system = Booter.newRepositorySystem(); RepositorySystemSession session = Booter.newRepositorySystemSession( system ); Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" ); DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE ); CollectRequest collectRequest = new CollectRequest(); collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) ); collectRequest.setRepositories( Booter.newRepositories( system, session ) ); DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter ); List<ArtifactResult> artifactResults = system.resolveDependencies( session, dependencyRequest ).getArtifactResults(); for ( ArtifactResult artifactResult : artifactResults ) { System.out.println( artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile() ); } } }
I resolved this problem by removing the artifact jars in local repository, however I'm still not sure why this exception happens, it seems to occur when the network is not stable. Hope it will help.
Writing Excel data to database in Java
This is my method that I use to write excel file data to a database. public static void executeSQLUpdate(String sql, List<Object> arguments) { Connection con = null; PreparedStatement pstmt = null; try { con = getConnection(); //a method that returns a java.sql.Connection to your database System.out.println("\n01)conection :"+con); pstmt = con.prepareStatement(sql); System.out.println("\n02)pstn :"+pstmt); System.out.println( "\n03)arguments size :"+arguments.size()); if (arguments != null) { int i = 1; System.out.println( "\n04)if :"+arguments); for(Object o : arguments) { System.out.println( "\n05)executeSQLUpdate"); System.out.println( "\n06)object."+o); System.out.println("\n07)................... :"+i + o); pstmt.setObject(i, o); System.out.println("\n08)____________________"+i+o); } } System.out.print("\n09)errorchk........... :"); //method to execute insert, update, delete statements... pstmt.executeUpdate(); System.out.print("\n10)+++++++++++++++++ :"); } catch(SQLException e) { System.out.println("\n11)************* :"+e); //handle the error... } finally { //closing the resources (always in finally block, not in the try!) try { if (pstmt != null) { pstmt.close(); } if (con != null) { con.close(); } } catch (SQLException e) { } } } Up to no 07 all the system out are working. But after that any system out are not working. What is the reason for that? Is there any error in this one? This is my out put: run: AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM NNN OOO PPP QQQ RRR 01)conection :com.mysql.jdbc.JDBC4Connection#6e70c7 02)pstn :com.mysql.jdbc.JDBC4PreparedStatement#29428e: INSERT INTO files_1 VALUES(** NOT SPECIFIED , NOT SPECIFIED , NOT SPECIFIED **) 03)arguments size :6 04)if :[[AAA, BBB, CCC], [DDD, EEE, FFF], [GGG, HHH, III], [JJJ, KKK, LLL], [MMM, NNN, OOO], [PPP, QQQ, RRR]] 05)executeSQLUpdate : 06)object :[AAA, BBB, CCC] 07)................... :1[AAA, BBB, CCC] 08)__________ :1[AAA, BBB, CCC] 05)executeSQLUpdate : 06)object :[DDD, EEE, FFF] 07)................... :1[DDD, EEE, FFF] 08)__________ :1[DDD, EEE, FFF] 05)executeSQLUpdate : 06)object :[GGG, HHH, III] 07)................... :1[GGG, HHH, III] 08)__________ :1[GGG, HHH, III] 05)executeSQLUpdate : 06)object :[JJJ, KKK, LLL] 07)................... :1[JJJ, KKK, LLL] 08)__________ :1[JJJ, KKK, LLL] 05)executeSQLUpdate : 06)object :[MMM, NNN, OOO] 07)................... :1[MMM, NNN, OOO] 08)__________ :1[MMM, NNN, OOO] 05)executeSQLUpdate : 06)object :[PPP, QQQ, RRR] 07)................... :1[PPP, QQQ, RRR] 08)__________ :1[PPP, QQQ, RRR] 09)errorchk........... : 11)***** :No value specified for parameter 2 java.sql.SQLException: No value specified for parameter 2 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:989) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984) at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:929) at com.mysql.jdbc.PreparedStatement.checkAllParametersSet(PreparedStatement.java:2560) at com.mysql.jdbc.PreparedStatement.fillSendPacket(PreparedStatement.java:2536) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2383) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2327) at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2312) at com.project.bulk.ReadExcelFile.executeSQLUpdate(ReadExcelFile.java:112) at com.project.bulk.ReadExcelFile.MethodToData(ReadExcelFile.java:138) at com.project.bulk.ReadExcelFile.main(ReadExcelFile.java:39) BUILD SUCCESSFUL (total time: 3 seconds)
One error for sure is that you increment i two times!!! System.out.println("\n07)..................."+i++ + o); // one pstmt.setObject(i++, o); // two This means that you don't set the even indices, just the odd ones: 1, 3, 5... This should correct this error: System.out.println("\n07)..................."+i + o); pstmt.setObject(i++, o); // only once, and after the evaluation! EDIT *Second, but also big mistake* } catch(SQLException e) { System.out.println("\n11)************* :"+e); //WTF? //handle the error... } excuse me for shouting, this has to happen now! Please, for our and your (future) colleagues' mental health's sake, DO NOT EVER DO THIS AGAIN! Printing exceptions must happen in one of two ways: logger.error("message", e); e.printStackTrace(); As these reserve the stack trace, and thus enable proper debugging of the code but should never, ever, ever, never! happen in any of these ways: System.out.print(e) System.out.print(e.getMessage) System.out.print("message " + e.getMessage) logger.error(e.getMessage) So correctly this should be: } catch(SQLException e) { System.out.println("\n11)************* :"+e.getMessage()); e.printStackTrace(); //TODO: handle the error... } By the way: using proper logging like log4j is well worth the time! It consumes much more time to clean up all the System.out.*, than to set a proper loglevel... EDIT2 As for the SQL error: String sql = "INSERT INTO files_1 VALUES(?)"; This SQL line tells the DBMS that it will have one parameter to deal with. The table has 3 columns, so you need to specify 3 values. Either constants, or parameters (by using ?). So you should have: String sql = "INSERT INTO files_1 VALUES(?,?,?)";
As indicated by your error java.sql.SQLException: Invalid argument value: java.io.NotSerializableException you're trying to set a value with a parameter that's not serializable in this line: pstmt.setObject(i++, o); Please make sure that all of your values are either primitives or values that can be mapped to database columns like String or Date. You can find out which data you're trying to set by putting in a line like this (using a logging framework or System.out.println: System.out.println("setObject: " + o + ", Class: " + o.getClass());