I have searched for the solution but couldn't make it work. Here is the summary. I am trying to implement a webservice which runs on Glassfish 2.1 that implements a synchronous JMS Request-Response using Temporary queue. It sends a message to another Glassfish application running on remote server. I am able to send the message and process it but when the final message is sent back to temporary queue, the webservice gets the response as null. Here is the code:
private Message requestReply(String msg, Queue jmsRequestResponse, ConnectionFactory jmsRequestRespConnFactory) {
javax.jms.Connection conn = null;
javax.jms.MessageConsumer consumer = null;
javax.jms.Message replyMsg = null;
javax.jms.Session sess = null;
try {
logger.debug("[requestreply input message[" + msg);
conn = jmsRequestRespConnFactory.createConnection();
conn.start();
sess = conn.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
javax.jms.Message reqMessage = sess.createTextMessage(msg);
javax.jms.Destination replyDestination = (jmsRequestResponse instanceof javax.jms.Queue) ? sess.createTemporaryQueue() : sess.createTemporaryTopic();
reqMessage.setJMSReplyTo(replyDestination);
sess.createProducer(jmsRequestResponse).send(reqMessage);
replyMsg = consumer.receive(60000);
consumer.close();
sess.close();
conn.close();
} catch (JMSException ex) {
logger.debug("exception in requestreply");
} finally {
if (consumer != null) {
try {
consumer.close();
} catch (Exception e) {
}
}
if (conn != null) {
try {
conn.close();
} catch (Exception e) {
}
}
}
return replyMsg;
}
what am I missing here?? When I print the replyMsg, it is always null.
Related
I have client like this :
import org.basex.api.client.ClientSession;
#Slf4j
#Component(value = "baseXAircrewClient")
#DependsOn(value = "baseXAircrewServer")
public class BaseXAircrewClient {
#Value("${basex.server.host}")
private String basexServerHost;
#Value("${basex.server.port}")
private int basexServerPort;
#Value("${basex.admin.password}")
private String basexAdminPassword;
#Getter
private ClientSession session;
#PostConstruct
private void createClient() throws IOException {
log.info("##### Creating BaseX client session {}", basexServerPort);
this.session = new ClientSession(basexServerHost, basexServerPort, UserText.ADMIN, basexAdminPassword);
}
}
It is a singleton injected in a service which run mulitple queries like this :
Query query = client.getSession().query(finalQuery);
return query.execute();
All threads query and share the same session.
With a single thread all is fine but with multiple thread I get some random (and weird) error, like the result of a query to as a result of another.
I feel that I should put a synchronized(){} arround query.execute() or open and close session for each query, or create a pool of session.
But I don't find any documentation how the use the session in parrallel.
Is this implementation fine for multithreading (and my issue is comming from something else) or should I do it differently ?
I ended creating a simple pool by adding removing the client from a ArrayBlockingQueue and it is working nicely :
#PostConstruct
private void createClient() throws IOException {
log.info("##### Creating BaseX client session {}", basexServerPort);
final int poolSize = 5;
this.resources = new ArrayBlockingQueue < ClientSession > (poolSize) {
{
for (int i = 0; i < poolSize; i++) {
add(initClient());
}
}
};
}
private ClientSession initClient() throws IOException {
ClientSession clientSession = new ClientSession(basexServerHost, basexServerPort, UserText.ADMIN, basexAdminPassword);
return clientSession;
}
public Query query(String finalQuery) throws IOException {
ClientSession clientSession = null;
try {
clientSession = resources.take();
Query result = clientSession.query(finalQuery);
return result;
} catch (InterruptedException e) {
log.error("Error during query execution: " + e.getMessage(), e);
} finally {
if (clientSession != null) {
try {
resources.put(clientSession);
} catch (InterruptedException e) {
log.error("Error adding to pool : " + e.getMessage(), e);
}
}
}
return null;
}
I exported a java api abc.war file deployed into the "server", which returns the null([]) values, when I am calling get method from the Postman. This is working fine in local system but not in server.
Connection con= getConnection();
List<QuestionsModel> lstQuestions=new ArrayList<QuestionsModel>();
try
{
if(con!=null)
{
CallableStatement cstmt = null;
ResultSet rs = null;
cstmt = con.prepareCall("{call GetQuestions()}");
cstmt.execute();
rs = cstmt.getResultSet();
while (rs.next()) {
QuestionsModel questionsModel=new QuestionsModel();
questionsModel.setQuestionID(rs.getInt("QuestionID"));
questionsModel.setQuestion(rs.getString("Question"));
lstQuestions.add(questionsModel);
}
con.close();
System.out.println("Hello from GetQuestions Repository");
return lstQuestions;
}
}
catch (SQLException e) {
e.printStackTrace();
}
return lstQuestions;
Expected : Return list of objects(QuestionData)
Errors: No errors.
I tried to use rocksdb to cache information required by a ProcessFunction, and following seems to be the only way to get it to work by far:
(1) load data from datastore (eg. mysql) and put the data into rocksdb then close the rocksdb handle in open().
(2) open & close rocksdb handle whenever the processElement() is invoked.
like this:
public static class MatchFunction extends ProcessFunction<TaxiRide, TaxiRide> {
// keyed, managed state
// holds an END event if the ride has ended, otherwise a START event
private ValueState<TaxiRide> rideState;
private RocksDB rocksdb = null;
private String dbPath = null;
#Override
public void close() throws Exception {
super.close();
if(rocksdb != null) {
rocksdb.close();
}
}
#Override
public void open(Configuration config) {
ValueStateDescriptor<TaxiRide> startDescriptor =
new ValueStateDescriptor<>("saved ride", TaxiRide.class);
rideState = getRuntimeContext().getState(startDescriptor);
if(rocksdb == null) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connect = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connect = DriverManager
.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&"
+ "user=user&password=password");
preparedStatement = connect.prepareStatement("select * from test.feature");
resultSet = preparedStatement.executeQuery();
RocksDB.loadLibrary();
try (final Options options = new Options().setCreateIfMissing(true)) {
// a factory method that returns a RocksDB instance
dbPath = "/tmp/checkpoints/rocksdb/test01_" + UUID.randomUUID();
try (final RocksDB db = RocksDB.open(options, dbPath)) {
rocksdb = db;
System.out.println("db opened: " + dbPath);
String key01 = "key01";
String val01 = "val01";
while (resultSet.next()) {
key01 = resultSet.getString(1);
val01 = resultSet.getString(2);
System.out.println("before put " + key01 + ":" + val01);
rocksdb.put(key01.getBytes(), val01.getBytes());
System.out.println("after put " + key01 + ":" + val01);
}
}
} catch (RocksDBException e) {
// do some error handling
e.printStackTrace();
} finally {
if(rocksdb != null) {
rocksdb.close();
System.out.println("db closed: " + dbPath);
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connect != null) {
try {
connect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
#Override
public void processElement(TaxiRide ride, Context context, Collector<TaxiRide> out) throws Exception {
TimerService timerService = context.timerService();
try (final Options options = new Options().setCreateIfMissing(true)) {
// a factory method that returns a RocksDB instance
try (final RocksDB db = RocksDB.open(options, dbPath)) {
rocksdb = db;
// System.out.println("db opened: " + dbPath);
String val01 = new String(rocksdb.get("f8416af7-b895-4f28-bcea-be1eef6bbdb2".getBytes()));
// System.out.println(">>> val01 = " + val01);
rocksdb.close();
// System.out.println("db closed: " + dbPath);
}
} catch (RocksDBException e) {
// do some error handling
e.printStackTrace();
}
if (ride.isStart) {
// the matching END might have arrived first (out of order); don't overwrite it
if (rideState.value() == null) {
rideState.update(ride);
}
} else {
rideState.update(ride);
}
timerService.registerEventTimeTimer(ride.getEventTime() + 120 * 60 * 1000);
}
#Override
public void onTimer(long timestamp, OnTimerContext context, Collector<TaxiRide> out) throws Exception {
TaxiRide savedRide = rideState.value();
if (savedRide != null && savedRide.isStart) {
out.collect(savedRide);
}
rideState.clear();
}
}
This is very inefficient since lots of IO happens in processElement(). This ProcessFunction was able to process all data in 10 minutes, it takes more then 40 minutes to process partial data after adding the rocksdb related lines. So I tried to resuse the rocksdb handled created in open() with the following implementation.
public static class MatchFunction extends ProcessFunction<TaxiRide, TaxiRide> {
// keyed, managed state
// holds an END event if the ride has ended, otherwise a START event
private ValueState<TaxiRide> rideState;
private RocksDB rocksdb = null;
private String dbPath = null;
#Override
public void close() throws Exception {
super.close();
if(rocksdb != null) {
rocksdb.close();
}
}
#Override
public void open(Configuration config) {
ValueStateDescriptor<TaxiRide> startDescriptor =
new ValueStateDescriptor<>("saved ride", TaxiRide.class);
rideState = getRuntimeContext().getState(startDescriptor);
if(rocksdb == null) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection connect = null;
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
connect = DriverManager
.getConnection("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&"
+ "user=user&password=password");
preparedStatement = connect.prepareStatement("select * from test.feature");
resultSet = preparedStatement.executeQuery();
RocksDB.loadLibrary();
try (final Options options = new Options().setCreateIfMissing(true)) {
// a factory method that returns a RocksDB instance
dbPath = "/tmp/checkpoints/rocksdb/test01_" + UUID.randomUUID();
try (final RocksDB db = RocksDB.open(options, dbPath)) {
rocksdb = db;
System.out.println("db opened: " + dbPath);
String key01 = "key01";
String val01 = "val01";
while (resultSet.next()) {
key01 = resultSet.getString(1);
val01 = resultSet.getString(2);
System.out.println("before put " + key01 + ":" + val01);
rocksdb.put(key01.getBytes(), val01.getBytes());
System.out.println("after put " + key01 + ":" + val01);
}
}
} catch (RocksDBException e) {
// do some error handling
e.printStackTrace();
} finally {
// if(rocksdb != null) {
// rocksdb.close();
// System.out.println("db closed: " + dbPath);
// }
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
if(resultSet != null) {
try {
resultSet.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(preparedStatement != null) {
try {
preparedStatement.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
if(connect != null) {
try {
connect.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
}
}
}
#Override
public void processElement(TaxiRide ride, Context context, Collector<TaxiRide> out) throws Exception {
TimerService timerService = context.timerService();
//try (final Options options = new Options().setCreateIfMissing(true)) {
// // a factory method that returns a RocksDB instance
// try (final RocksDB db = RocksDB.open(options, dbPath)) {
// rocksdb = db;
// System.out.println("db opened: " + dbPath);
String val01 = new String(rocksdb.get("f8416af7-b895-4f28-bcea-be1eef6bbdb2".getBytes()));
// System.out.println(">>> val01 = " + val01);
// rocksdb.close();
// System.out.println("db closed: " + dbPath);
// }
//} catch (RocksDBException e) {
// // do some error handling
// e.printStackTrace();
//}
if (ride.isStart) {
// the matching END might have arrived first (out of order); don't overwrite it
if (rideState.value() == null) {
rideState.update(ride);
}
} else {
rideState.update(ride);
}
timerService.registerEventTimeTimer(ride.getEventTime() + 120 * 60 * 1000);
}
#Override
public void onTimer(long timestamp, OnTimerContext context, Collector<TaxiRide> out) throws Exception {
TaxiRide savedRide = rideState.value();
if (savedRide != null && savedRide.isStart) {
out.collect(savedRide);
}
rideState.clear();
}
}
The problem with this implementation is that it just doesn't work and here is the error message I got:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000012c94cf55, pid=64626, tid=39683
#
# JRE version: Java(TM) SE Runtime Environment (8.0_60-b27) (build 1.8.0_60-b27)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.60-b23 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# [thread 39171 also had an error]
06:52:56.163 [pool-11-thread-1] INFO o.a.flink.contrib.streaming.state.RocksDBKeyedStateBackend - Asynchronous RocksDB snapshot (File Stream Factory # file:/tmp/checkpoints/53224270d2f2be67a9d20f9deac66d09, asynchronous part) in thread Thread[pool-11-thread-1,5,Flink Task Threads] took 10 ms.
06:52:56.163 [pool-16-thread-1] INFO o.a.flink.contrib.streaming.state.RocksDBKeyedStateBackend - Asynchronous RocksDB snapshot (File Stream Factory # file:/tmp/checkpoints/53224270d2f2be67a9d20f9deac66d09, asynchronous part) in thread Thread[pool-16-thread-1,5,Flink Task Threads] took 12 ms.
C06:52:56.163 [pool-13-thread-1] INFO o.a.flink.contrib.streaming.state.RocksDBKeyedStateBackend - Asynchronous RocksDB snapshot (File Stream Factory # file:/tmp/checkpoints/53224270d2f2be67a9d20f9deac66d09, asynchronous part) in thread Thread[pool-13-thread-1,5,Flink Task Threads] took 9 ms.
[librocksdbjni-osx.jnilib+0x3ff55] _Z18rocksdb_get_helperP7JNIEnv_PN7rocksdb2DBERKNS1_11ReadOptionsEPNS1_18ColumnFamilyHandleEP11_jbyteArrayii+0xe5
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
06:52:56.163 [pool-12-thread-1] INFO o.a.flink.contrib.streaming.state.RocksDBKeyedStateBackend - Asynchronous RocksDB snapshot (File Stream Factory # file:/tmp/checkpoints/53224270d2f2be67a9d20f9deac66d09, asynchronous part) in thread Thread[pool-12-thread-1,5,Flink Task Threads] took 13 ms.
[thread 46339 also had an error]
# An error report file with more information is saved as:
# /Users/abc/MyFiles/workspace/flink-java-project/hs_err_pid64626.log
[thread 22279 also had an error]
[thread 33027 also had an error]
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Process finished with exit code 134 (interrupted by signal 6: SIGABRT)
Detail trace from "/Users/abc/MyFiles/workspace/flink-java-project/hs_err_pid64626.log" can be found in this link (http://memyselfandtaco.blogspot.tw/2018/04/how-to-correctly-access-rocksdb-in.html)
I'm playing with Sonarqube plugin for Jenkins. How can I effectively solve this trivial violation he is complaining about without changing the logic?
Note: I need to validate the connections separetely ( ConnectionManager, statistics, keepAlive, .. ).
`
public void executeProcedure( final RequestProcessor consumer ) throws SQLException {
final String procedure = consumer.getProcedure();
final String idUrl = consumer.getIdUrl();
final PreparedStatementRegisterer stmRegisterer = consumer.getRegisterer();
// Autoclosable removed to allow ad hoc connection validation
Connection conn = null;
boolean execSuccess = false;
try{
conn = newConnection();
conn = checkOrChangeConnection(conn, false);
boolean hasResultSet = false;
try( CallableStatement statement = (OracleCallableStatement)conn.prepareCall(procedure) ){
...
stmRegisterer.prepareStatement(statement, idUrl);
statement.setQueryTimeout(QUERY_TIMEOUT);
hasResultSet = statement.execute();
execSuccess = true;
if(hasResultSet){
...
try ( ResultSet rs = statement.getResultSet() ) {
while ( rs.next() ) {
consumer.handleRow( rs );
}
}
}else{
...
consumer.getFieldsFromResult( statement );
}
}
}catch(Exception ex){
LOGGER.log( LogEntries.StorProcErr, ex.getMessage() );
throw new Exception( (!execSuccess ? "Error preparing and executing statement.":"Error during results reading.")+" Cause: "+ex) );
}finally{
try {
if (conn != null) {
conn.close();
}
} catch (SQLException e) {
System.out.println("\n Error closing connection on executeStoredProc. Cause: "+e+" \n"); // log
}
}
}
My idea is to add some more logging and re-throw the same exception after the log "StorProcErr". Is there a better approach?
Thanks
I'm working on a bluetooth-capable application, based on the well-known BluetoothChat example.
Basically with this app a client can send some packets to a server.
I have tested the application using two Xperia smartphones (Xperia X8 and Xperia Sola, android 2.1 and 4.0) and all is working fine: they both can act as client or server.
Unfortunately if I use an HTC Desire (android 2.3) as server, it won't be able to accept incoming connection from one of the Xperia client. It seems that the client connect() returns as if all was fine, but instead the server is blocked on its accept() as if nothing was happened.
Relevant code snippets:
1. "Accept Thread"
private class BluetoothAcceptThread extends Thread
{
private final BluetoothServerSocket serverSocket;
public BluetoothAcceptThread()
{
BluetoothServerSocket tmpSocket = null;
try
{
Method m = bluetoothAdapter.getClass().getMethod("listenUsingRfcommOn", new Class[] {int.class});
tmpSocket = (BluetoothServerSocket) m.invoke(bluetoothAdapter, APP_BT_CHANNEL);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothAcceptThread listen() (with reflection) failed", e);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
serverSocket = tmpSocket;
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread ServerSocket created");
}
#Override
public void run()
{
BluetoothSocket socket = null;
try
{
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread calling accept()...");
socket = serverSocket.accept();
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread accept() returned");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothAcceptThread accept() failed: " + e.getMessage());
}
if (socket != null)
{
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread accept() successfully");
synchronized (BluetoothManager.this)
{
if (currentState == SocketState.LISTENING || currentState == SocketState.CONNECTING)
startBluetoothConnection(socket); // all is ok, it can proceed
else if (currentState == SocketState.INACTIVE || currentState == SocketState.CONNECTED)
cancel(socket);
}
}
}
#Override
public void cancel()
{
try
{
serverSocket.close();
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread ServerSocket closed");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothAcceptThread close() failed", e);
}
}
private void cancel(BluetoothSocket newSocket)
{
try
{
newSocket.close();
Log.d(MainActivity.DEBUG_TAG, "BluetoothAcceptThread client socket closed");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothAcceptThread client socket close() failed", e);
}
}
}
2. "Connect thread"
private class BluetoothConnectThread extends Thread
{
private final BluetoothSocket socket;
private final BluetoothDevice device;
public BluetoothConnectThread(BluetoothDevice d)
{
device = d;
BluetoothSocket tmpSocket = null;
try
{
Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmpSocket = (BluetoothSocket) m.invoke(device, APP_BT_CHANNEL);
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothConnectThread create() (with reflection) failed", e);
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
socket = tmpSocket;
Log.d(MainActivity.DEBUG_TAG, "BluetoothConnectThread client socket created");
}
#Override
public void run()
{
stopBluetoothDiscovery(); // otherwise it will slow down the connection
try
{
socket.connect();
Log.d(MainActivity.DEBUG_TAG, "BluetoothConnectThread connect() successfully");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothConnectThread connect() failed", e);
String deviceName = device != null ? device.getName() : "none";
connectionFailed(deviceName); // notify UI thread
return;
}
synchronized (BluetoothManager.this)
{
bluetoothConnectThread = null;
}
startBluetoothConnection(socket); // create the "Communication" Thread
}
#Override
public void cancel()
{
try
{
socket.close();
Log.d(MainActivity.DEBUG_TAG, "BluetoothConnectThread client socket closed");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothConnectThread close() failed", e);
}
}
}
3. "Communication Thread" (aka ConnectedThread in BluetoothChat sample)
private class BluetoothCommunicationThread extends Thread
{
private final BluetoothSocket socket;
private final InputStream inputStream;
private final OutputStream outputStream;
public BluetoothCommunicationThread(BluetoothSocket s)
{
socket = s;
InputStream in = null;
OutputStream out = null;
try
{
in = socket.getInputStream();
out = socket.getOutputStream();
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothCommunicationThread failed to get streams", e);
}
inputStream = in;
outputStream = out;
}
#Override
public void run()
{
byte[] buffer = new byte[BT_BUFF_SIZE];
int readBytes;
while (true)
{
try
{
readBytes = inputStream.read(buffer, 0, buffer.length);
if (readBytes != -1)
{
Message message = messageHandler.obtainMessage(DATA_MSG, readBytes, -1, buffer);
message.sendToTarget(); // notify to UI thread the bytes counter
}
else
{
BluetoothDevice device = socket.getRemoteDevice();
String deviceName = device != null ? device.getName() : "none";
connectionLost(deviceName);
break;
}
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothCommunicationThread read() failed", e);
BluetoothDevice device = socket.getRemoteDevice();
String deviceName = device != null ? device.getName() : "none";
connectionLost(deviceName);
break;
}
}
}
public void write(byte[] buffer)
{
try
{
outputStream.write(buffer);
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothCommunicationThread write() failed", e);
}
}
#Override
public void cancel()
{
try
{
socket.close();
Log.d(MainActivity.DEBUG_TAG, "BluetoothCommunicationThread socket closed");
}
catch (IOException e)
{
Log.e(MainActivity.ERROR_TAG, "BluetoothCommunicationThread close() failed", e);
}
}
}
So the steps of the problem are the following:
HTC Desire server calls accept()
Xperia client calls connect()
The connect returns as if the connection was established
Nothing is happening on the HTC, always blocked on accept()
Xperia client thinks that it's connected, so it creates the CommunicationThread and calls the blocking read(); this function throws java.io.IOException: Software caused connection abort, probably because the socket is not connected.
Finally these are the relevant logcats:
Xperia client:
09-20 00:44:23.562 9106-9106/com.powertester D/[PowerTester Debug]﹕ BluetoothConnectThread client socket created
09-20 00:44:25.704 9106-9579/com.powertester D/[PowerTester Debug]﹕ BluetoothConnectThread connect() successfully
09-20 00:44:25.734 9106-9579/com.powertester D/[PowerTester Debug]﹕ BluetoothCommunicationThread started and I/O streams ready
09-20 00:44:25.764 9106-9589/com.powertester E/[PowerTester Error]﹕ BluetoothCommunicationThread read() failed
java.io.IOException: Software caused connection abort
at android.bluetooth.BluetoothSocket.readNative(Native Method)
at android.bluetooth.BluetoothSocket.read(BluetoothSocket.java:333)
at android.bluetooth.BluetoothInputStream.read(BluetoothInputStream.java:96)
at com.powertester.net.BluetoothManager$BluetoothCommunicationThread.run(BluetoothManager.java:518)
09-20 00:44:25.844 9106-9106/com.powertester D/[PowerTester Debug]﹕ BluetoothCommunicationThread socket closed
HTC server:
09-19 15:47:07.591 2422-2422/com.powertester D/[PowerTester Debug]﹕ BluetoothAcceptThread ServerSocket created
09-19 15:47:07.591 2422-2484/com.powertester D/[PowerTester Debug]﹕ BluetoothAcceptThread calling accept()...
The really strange thing is that the HTC Desire works if used as client with one of the Xperia used as server.
So, is a problem of my app or a problem in the HTC Desire bluetooth stack?
After some troubles I have realized that the problem is the reflection itself and the explicit use of a Bluetooth Channel.
Using the normal way (i.e. the not-hidden bluetooth methods) my app works perfectly.