How to connect ObjectBox to server instance? - java

I have a use-case wherein I have to connect objectbox from Java to server instance.
I tried with Sync but getting error stating "sync not supported". Below is my code,
BoxStore boxStore = MyObjectBox.builder().name("TestEntity-db").build();
Box<TestEntity> box = boxStore.boxFor(TestEntity.class);
boolean syncAvailable = Sync.isAvailable();
System.out.println("ObjectBox Sync is " + syncAvailable);
SyncClient syncClient = Sync.client( boxStore, "ws://12.456.672.89:9999", SyncCredentials.none() ).buildAndStart();
Can someone help in this?

Related

Can someone please explain me what could be the solution for this error “Unable to create a XML-RPC client”?

I was on integrating testlink (version 1.9.20-12) with the selenium webdriver by using this blog https://www.softwaretestinghelp.com/testlink-tutorial-3/
I have done all the preequisites and all the steps. But I am getting this error "Unable to create a XML-RPC client". I have also came to know that my API is not getting connected as isConnected method from TestlinkApiClient is giving me false value.
I have gone and check the solutions given on What is solution for this error "Unable to create a XML-RPC client"? and TestLink XML-RPC The call to the xml-rpc client failed but still my error was not resolved.
here is the code snippet.
TestLinkAPIClient tlApi = new TestLinkAPIClient(URL, DEVKEY);
boolean value = tlApi.isConnected;
System.out.println("API Connected : " + value);
tlApi.reportTestCaseResult(testProject, testPlan, testCase, build, notes, result);
providing DEVKEY from Testlink from user profile and URL as "http://127.0.0.1:81/testlink/lib/api/xmlrpc/v1/xmlrpc.php"
Can someone explain what caused this error and how to fix it.

Hyperledger fabric endorsement policy error using Java SDK

I am working on golang version of fabcar smart contract while seeking to implement a Java-SDK API which enrolls an admin, registers a user and performs query-update value operations based on https://github.com/hyperledger/fabric-samples/tree/master/fabcar/java
I have successfully set up a 3 org-9 peers blockchain network, installed, instantiated and invoked chaincode on peers.
However, as i am working on implementing the relative API, i am only able to successfully query blockchain database, while getting a "Could not meet endorsement policy for chaincode mycc"
Please find below screenshot of relative error
Endorsement policy is "OR ('Org1MSP.member','Org2MSP.member', 'Org3MSP.member')".
Should registered user somehow get an Org1/Org2/Org3.member attribute? Any leads would be appreciated!
Like #Ikar Pohorský said, for me this got resolved after I used correct method name. Also, ensure that you delete 'wallet' folder in order to regenerate the user if your HLF n/w was recreated.
#Test
public void testMyMethodToBeInvoked() throws Exception {
deleteDirectory(".\\wallet");
EnrollAdmin.main(null);
RegisterUser.main(null);
// Load a file system based wallet for managing identities.
final Path walletPath = Paths.get("wallet");
final Wallet wallet = Wallet.createFileSystemWallet(walletPath);
// load a CCP
final Path networkConfigPath = Paths
.get("C:\\sw\\hlf146-2\\fabric-samples\\first-network\\connection-org1.yaml");
final Gateway.Builder builder = Gateway.createBuilder();
builder.identity(wallet, "user1").networkConfig(networkConfigPath).discovery(true);
// create a gateway connection
try (Gateway gateway = builder.connect()) {
final Network network = gateway.getNetwork("mychannel");
final Contract contract = network.getContract("mycc");
String myJSONString="{\"a\":\"b\"}";
byte[] result;
// Following did NOT work. Control goes directly to 'invoke' when 'submitTransaction' is done directly. 'invoke' need not be mentioned here.
// result = contract.submitTransaction("invoke", myJSONString);
// Following DID work. In chaincode (my chain code was Java) I had a method named 'myMethodToBeInvoked'. The chain code was written similar to https://github.com/hyperledger/fabric-samples/blob/release-1.4/chaincode/chaincode_example02/java/src/main/java/org/hyperledger/fabric/example/SimpleChaincode.java
result = contract.submitTransaction("myMethodToBeInvoked", my);
System.out.println(new String(result));
}
}
EDIT: Also, please remember that if your chaincode throws errorResponse, even then we can have this endorsement fail issue. So, check if your chain code is working without any issues.

Getting all users from Openfire server using smack 4.2.2

Well, I'm trying to get all users from Openfire server using Smack, unfortunately I don't know how - I'm using Smack 4.2.2.
UserSearchManager usm= new UserSearchManager(connection);
DomainBareJid domainJid =
JidCreate.domainBareFrom(connection.getServiceName());
Form searchForm = usm.getSearchForm(domainJid);
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", "*");
ReportedData data = usm.getSearchResults(answerForm, domainJid);
if (data.getRows() != null) {
for (ReportedData.Row row: data.getRows()) {
for (String jid:row.getValues("jid")) {
System.out.println(jid);
}
}
}
This code doesn't work because of:
java.lang.IllegalArgumentException: Must have a local (user) JID set. Either you didn't configure one or you where not connected at least once
You can't get all users through XEP-0055: Jabber Search, just can be used with a filter you sure that the users don't have it (like a special character). Only way I know is to use Rest API Plugin of openfire. You can read more about this plugin from the link. Good luck.
Error is obvious. Either you did not connect at least once (or got disconnected and did not reconnect) or your username is wrong.
Maybe you are trying to connect without local jid. Please check this explanation of XMPP address formats:
https://xmpp.org/rfcs/rfc6122.html#addressing-localpart
hope you have solved the problem. I got my code working with this little change
DomainBareJid domainJid =
JidCreate.domainBareFrom("search." + connection.getServiceName());
in your openfire go to Plugins and select available-plugins > then choose rest Api > then you can use following url to Get All users in Group:
http://localhost:9090/plugins/restapi/v1/users
Note: All Rest EndPoints you can find in following link:
https://www.igniterealtime.org/projects/openfire/plugins/1.2.1/restAPI/readme.html

Handle asynchronous messages in ejabberd

I have ejabberd as my local server and smack as the android side api.
When user comes online and there is number of offline messages to deliver , the ejabberd server just floods me with the messages .and i get every message but the order is just not perfect. the order in which message is sent and saved in server is not how i receive the messages.
I can handle the offline messages on smack by the OfflineMessageManager class . but this is not supported in ejabberd. i used supportsFlexibleRetrieval() to check it and it returned false.
I also checked it with the Xabber android app and surprisingly here i get all the messages in correct order from the ejabberd server. so the problem is at my android client side. my receiver is as follows-
PacketListener myListener;
String new_msg_body, new_msg_from;
final StanzaFilter filter = new AndFilter(new StanzaTypeFilter(Message.class));
PacketCollector myCollector = conn1.createPacketCollector(filter);
myListener = new PacketListener() {
#Override
public void processPacket(Stanza packet) throws SmackException.NotConnectedException {
Message msg = (Message) packet;
new_msg_body = msg.getBody();
new_msg_from = msg.getFrom();
Log.i("log", "message recived :" + new_msg_body + " from : " + new_msg_from +" msg id : " + msg.getStanzaId());
}
};
conn1.addPacketListener(myListener, filter);
Do any one have any suggestion for this problem.
Progress
Till now i have found that each message has its id and the ids of each message is in order if their sending time. so i can may be do a sorting here to get the messages in order.
got to know that each packet that comes that fires its own receiver instance. and this will make the device flood with number of messages at a time . this might be causing the problem.
ejabberd 16.02 or latest version support Flexible Offline Message Retrieval (XEP-0013) .download and install latest version of ejabberd. check this link
XEP-0013: Flexible Offline Message Retrieval is from 2003, maybe it is time to move to the much more modern XEP-0313: Message Archive Management? It is far better for multiple devices environments, such as the concurrent use of mobile and web apps.
MongooseIM has a strong support for MAM: MongooseIM 1.6.2 supports MAM v0.2, but our master branch (next version) supports MAM v0.5.1. You can store your message archive in MySQL, PostgreSQL, Riak KV, and Cassandra!

Randomly Channel.Connect.Failed error when calling to a Java server from Flex application using AMF protocol

I have a project published in the Internet that is used by thousands of users every day. Basically, I'm using a server in AmazonAWS with the server part compiled in Java 6 running in a Tomcat. I'm using AMF to publish the services and my client is built in Flex 4.6 using Flash Builder to generate the classes to connect to the AMF services. The code I'm using to connect to the services is this:
public var cpcService:RemotingServicesImpl;
private function callService():void
{
FlexGlobals.topLevelApplication.callingService=true;
encryptedSession=ResourcesUtil.buildSessionId(globalSettings.sessionId, globalSettings);
var responder:Responder=new Responder(gameStateLoaded, gameStateFailed);
var token:AsyncToken=cpcService.getGameState(encryptedSession, taskKey);
token.addResponder(responder);
}
private function gameStateFailed(ev:FaultEvent=null):void
{
DisplayUtil.trackErrorInfoEvent("FATAL - FatalError", "getGameState-" + FlexGlobals.topLevelApplication.mainView.currentState, ev, encryptedSession);
}
private function gameStateLoaded(ev:Object):void
{
// my fantastic code when everything is ok
}
Normally, everything is ok and my application is working, but some calls (like 1 every 500) are not working, I know it because in the trackErrorInfoEvent function I'm registering an event in the Google Analytics, so I know this is randomly happening. This is the error:
faultCode = "Client.Error.MessageSend"
faultDetail = "Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Failed: url: 'https://appcog.cognifit.com/messagebroker/amf'"
faultString = "Send failed"
rootCause = (null)
Of course the URL is correct and is working all times.
I have seen in some blogs that adding this line:
<add-no-cache-headers>false</add-no-cache-headers>
the problem is fixed, but I have that line in my config file and is still happening.
I have checked my server logs and I have no records for service interruptions at any time.
I really apreciate any help, thanks in advance!

Categories