I'm developing a web app in Java (with Spark) and I want it to use JmDNS to be able to find this server in my Android app. I was following steps from JmDNS page with service registration, and my code looks like this:
try {
// Create a JmDNS instance
JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());
// Register a service
ServiceInfo serviceInfo = ServiceInfo.create("_http._tcp.local.", "smart_dom", 4567, "path=index.html");
jmdns.registerService(serviceInfo);
} catch (IOException e) {
System.out.println(e.getMessage());
} catch (InterruptedException e) {
e.printStackTrace();
}
I implemented the part about discovering services in my Android app, but it finds nothing. I made some changes according to this question, and even downloaded ZeroConf Browser (it relies on JmDNS), but even this app doesn't see my web app.
My server runs on Windows PC. I know that Windows doesn't support mDNS, but Java should be independant from the platform. What can I be doing wrong?
If anyone was wondering what was wrong, I found the answer.
In my case the problem was with JmDNS jmdns = JmDNS.create(InetAddress.getLocalHost());, especially with InetAddress.getLocalHost() which returned 127.0.0.1 not my LAN adapter wi-fi address. The problem was solved using this solution. It bases on looking for the correct interface via NetworkInterface.getNetworkInterfaces().
Related
Does anyone know of an MQTT broker that runs on an Android smartphone? I tried to Google and found nothing, and on the app store there seems to be only one app with just 10 downloads, so I'm not sure how well it works.
Add these dependencies to the gradle
dependencies{
compile 'io.moquette:moquette-netty-parser:0.8.1'
compile 'io.moquette:moquette-broker:0.8.1'
compile 'io.moquette:moquette-parser-commons:0.8.1'
}
And use
io.moquette.server.Server server = new io.moquette.server.Server();
server.startServer();
to start broker server. the default URI is tcp://localhost:1883
For me server.startServer(); gave me exception as it is unable to create a file BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME.
So, I changed the destination of the BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME
using this code below code and it worked for me.
try {
MemoryConfig memoryConfig = new MemoryConfig(new Properties());
memoryConfig.setProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME, Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator + BrokerConstants.DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME);
server.startServer(memoryConfig);
// server.startServer();//is not working due to DEFAULT_MOQUETTE_STORE_MAP_DB_FILENAME;
Log.d(TAG,"Server Started");
}
catch (IOException e) { e.printStackTrace(); }
catch (Exception e){ e.printStackTrace(); }
And Use Paho libraries for android
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
To create a client and connect to tcp://localhost:1883 and subscribe for a topic and start publishing and receiving messages.
moquette library for android.
I have developed an App specifically for this , please download here -
It has inbuilt broker and client too..all for free , connect your
devices to android phone via hotspot or wifi.
https://play.google.com/store/apps/details?id=server.com.mqtt
You can run the mosquitto mqtt broker within the Termux terminal.
Install Termux using e.g. F-Droid
Open/run the Termux Terminal emulator
Install mosquitto
pkg install mosquitto
Start mosquitto within the terminal
mosquitto
That's it. The server will listen on the default port 1883.
Configuration see at mosquitto.
Here is an MQTT broker library I have adapted to Android: https://github.com/interaktionsbyran/moquette
You'll have to make your own Android app though, it is just a library.
I have already developed a grizzly-based-HTTP-Server. In order to test my Server I also developed a grizzly-based-Client, which can comunicate with my Server using http-Messages. I instantiate my http-Server using grizzly as following:
HttpServer server = HttpServer.createSimpleServer();
server.addListener(new NetworkListener("server","127.0.01",8081);
server.getServerConfiguration().addHttpHandler(new Handler());
try {
server.start();
Thread.currentThread().join();
} catch (IOException e) {
e.printStackTrace();
}catch (InterruptedException e) {
e.printStackTrace();
}
Now I want to secure the communication between them. When I am searching for Informations about possible implementation of ssl in grizzly, I found this link SSL with Grizzly and Jersey. I noticed that I should use SSLContextConfigurator combined with Jersey. This means for me that I must modify my grizzly based Server, which is totally based on grizzly. Before doing this step, I must be sure that I can implement my AES-preshared-key using Jersey Combined with grizzly. Till now I found no example that Shows how to use AES-preshared-key in Java.
According to my readings about preshared-key-method, I knew that I should use javax.crypto.Cipher. Now I am confused about adding this functinality(ssl with preshared key) to my Server. Any idea?
Have you checked SSLEngineConfigurator docs? You can add TLS v1.2 ciphers from this page to enabledCipherSuites in your ssl configuration. That page also gives you the list including compatibility with different JDK versions.
This should give you an idea how to proceed with SSL using Grizzly.
Ok, I'm attempting unsuccessfully to connect to a remote datastore and populate from my local machine using the steps outlined here: https://cloud.google.com/appengine/docs/java/tools/remoteapi#Configuring_Remote_API_on_the_Client
public static void main(String[] args) {
String username = "myemail#gmail.com";
String password = "mygmailpassword";
RemoteApiOptions options = new RemoteApiOptions()
.server("myappname.appspot.com", 443)
.credentials(username, password);
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
...
I'm getting a 404 in installer.install(options):
java.io.IOException: can't get appId from remote api; status code = 404
Am I missing something here? I enabled the remote api in my web.xml and deployed to GAE. I am the owner of the project.
Run your service locally (with remote api enabled) and try running same code using 'localhost' and 8888 (port) and check if your code can access locally running service. Your code seems right. There are 2 possibilities -
1. RemoteApi is not enabled correctly.
2. app-name is not spelled correctly.
Other than this, I also use following code to access remote api-
installer.install(options);
try {
// Update the options with reusable credentials so we can skip
// authentication on subsequent calls.
options.reuseCredentials(username, installer.serializeCredentials());
} finally {
installer.uninstall();
}
However, that shouldn't give you the error you're getting.
I realize this is coming a bit late, but I just found this when googling because I had a similar problem, and I solved it for myself. For me the problem was, that my AppEngine app that was serving the remote API, was a python app, and the python docs instruct configuring the remote api endpoint as /remoteapi.*
However my remote api client is a java application, and apparently the remote api call it makes, goes to an endpoit like this: /remote_api. So adding that to the server route configuration (in my case app.yaml) solved the problem. Please note also, that if your remote api serving appengine app is not in the default module, the url should be something like my-module-name-dot-my-project.appspot.com
Also, you should use useApplicationDefaultCredential() instead of credentials(), it is deprecated.
Having called into the NetBeans library with :-
try {
Object[] argss = new String[] {"--branding", "assetwatch_platform"};
Class c = loader.loadClass("org.netbeans.Main");
Method m = c.getMethod("main", new Class[] { String[].class });
m.invoke(null, new Object[] {argss});
} catch (Exception ex) {
ex.printStackTrace();
}
}
NetBeans creates the platform window but fails to pass control onto user code and cannot connect over the RMI port 80. There is nothing in the webstart client logs. I have read all the questions about the class loader and have applied the workarounds to no effect. I have tried getting hold of the source for 5.5.1 but the CVS server no longer responds. Any ideas?
I 'bit-the-bullet' and used the ant build here [Netbeans platform][1]https://platform.netbeans.org/tutorials/nbm-ant.html#rcp to get the latest platform. After some 'frigging in the rigging' the web-start application was resurrected with very little change to the source or the application. This has to be testament to the quality of the NetBeans framework. The Web Browser module is still not adequate for modern webapps and I have to find a way of disabling modules but generally a cloud has lifted from above me.
We're writing a web application that is trying to replace all ReportManager functionality using calls to Reporting Services SOAP API.
We started working with SSRS 2008 and had our Java code working correctly. We've since had to downgrade to SSRS 2005 and now we're having problems connecting to the Server to get the list of reports available.
We make the following call:
catalog = _reportingService.listChildren(_reportCredentials.getFolder(), false);
which returns an exception - (401)Unauthorized
_reportCredentials just holds information from a properties file (like the folder to use, the username and password, etc.). _reportService is defined as:
private ReportingService2005Soap _reportingService;
...
_reportingServiceLocator = new ReportingService2005Locator();
_reportingServiceLocator.setReportingService2005SoapEndpointAddress(soapURL);
try {
_reportingService = _reportingServiceLocator.getReportingService2005Soap();
} catch (Exception e) {
throw new ReportServicesException("Could not retrieve SOAP Reporting Service.");
}
I can also connect to ReportManager as the user/password we're connecting with in the code.
All of the 'documentation' I can find is just .NET code that doesn't seem to apply to the Java code. Has anybody experienced problems like this, or know of a good resource for Java developers using these services?
We traced the problem back to having SSRS 2005 installed on Windows Server 2008. Following the steps here: http://www.omegaprojex.com/index.php/2008/10/10/ssrs-2005-on-windows-server-2008/ fixed our problem.