I'm using the Paho Android Client.
https://eclipse.org/paho/clients/java/
This is probably THE go to library for MQTT on Android, yet it doesn't support secure MQTT websockets (wss://), giving me IllegalArgument exceptions for the server uri.
I have been looking for a solution to connect to my MQTT websocket which has a wss:// path scheme, and so far there's only one library:
https://github.com/inventit/mqtt-websocket-java
Which also doesn't work! I'm getting Jetty SSL exceptions.
If you have an implementation you've used before, please share them with me, this has taken a lot of my time, and I'm still clueless, thanks!
For both libraries, I've tried using the sample code they offer in their documentations.
I think Paho Android Client doesn't support websocket ssl but you can use MqttAsyncClient instead MqttAndroidClient like this :
The libraries are the same :
dependencies {
...
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0'
compile 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.0'
...
}
Use MqttAsyncClient instead MqttAndroidClient like this :
private MqttAsyncClient mMqttAndroidClient;
try {
mMqttAndroidClient = new MqttAsyncClient("wss://...", MqttClient.generateClientId(), new MemoryPersistence());
} catch (MqttException e) {
e.printStackTrace();
}
I used "WSS://" without any problem. Make a MqttAndroidClient object with "WSS" schema and port 443.
mqttConnectOptions = new MqttConnectOptions();
mqttConnectOptions.setKeepAliveInterval(MqttConfig.KEEPALIVE);
mqttConnectOptions.setUserName("username");
mqttConnectOptions.setPassword("pass");
mqttConnectOptions.setCleanSession(false);
mqttConnectOptions.setAutomaticReconnect(true);
mqttConnectOptions.setMaxInflight(1024);
..
uri="wss://broker.hivemq.com:443"
MqttAndroidClient client = new MqttAndroidClient(context, uri, clientId,persistence);
..
getClient().connect(mqttConnectOptions,applicationContext,mqttActionListener;
Related
I am writing a client that manages Kubernetes objects. Is it possible to update ReplicaSets using a Java client?
Yes, you can update ReplicaSet using Java Kubernetes Client. Depending on which Kubernetes client you use here are the code snippets.
Kubernetes Java Client
AppsV1Api api = new AppsV1Api();
api.patchNamespacedReplicaSet(...);
Fabric8 Kubernetes & OpenShift Java Client
KubernetesClient client = new DefaultKubernetesClient();
client.apps().replicaSets().createOrReplace(...);
I was just doing this this morning!
Yes you can do that. Checkout Fabric8 Kubernetes client for Java (https://github.com/fabric8io/kubernetes-client/blob/master/kubernetes-tests/src/test/java/io/fabric8/kubernetes/client/mock/ReplicaSetTest.java)
An example of the change would be:
try (KubernetesClient k8sClient = new DefaultKubernetesClient()) {
ReplicaSetList list = k8sClient.apps().replicaSets().inNamespace("default").list();
for (ReplicaSet next : list.getItems()) {
next.getSpec().setReplicas(10);
k8sClient.apps().replicaSets().create(next);
}
} catch (Exception e) {
//TODO: logging
}
Just be sure to use the correct one. In this example I am changing all of them in the default namespace.
Using grpc from either nodejs or java, what are the properties or configuration necessary to get a grpc client to connect to a server through a proxy?
I have been unable to find either an example or a document explaining the settings. Do I need to do something in the code itself?
I am behind a proxy and I am not sure if the issue is that my settings are incorrect or that my proxy does not support grpc. It supports http/2 as a protocol upgrade.
My proxy settings in java are:
-Dhttp.proxyHost=xxx.xxx.xxx
-Dhttp.proxyPort=8888
-Dhttp.nonProxyHosts="*.nowhere.nothing"
-Dhttps.proxyHost=xxx.xxx.com
-Dhttps.proxyPort=8888
-Dhttps.nonProxyHosts="*.nowhere.nothing"
-Dsocks.proxyHost=xxx.xxx.xxx
-Dsocks.proxyPort=8888
-Dsocks.nonProxyHosts="*.nowhere.nothing"
Since grpc-java 1.0.3 you can specify the environment variable GRPC_PROXY_EXP with a value in the form host:port. The "EXP" means experimental, as it will be removed after grpc-java observes the normal Java settings (like https.proxyHost).
In later releases (I think since 1.8.0+) you need:
System.setProperty("http.proxyHost", "http-ip-address-hostname");
System.setProperty("http.proxyPort", "http-port-value");
System.setProperty("https.proxyHost", "https-ip-address-hostname");
System.setProperty("https.proxyPort", "https-port-value");
If you prefer to not use the global https.proxyHost, https.proxyPort properties, you could use the StubSettings of your client to specify a ChannelConfigurator. It might then look like this:
InetSocketAddress proxyAddress = new InetSocketAddress("my.proxy.local", 8080);
InstantiatingGrpcChannelProvider transportProvider = SessionsStubSettings.defaultGrpcTransportProviderBuilder()
.setChannelConfigurator(new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
#Override
public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
return input.proxyDetector(new ProxyDetector() {
#Override
public ProxiedSocketAddress proxyFor(SocketAddress targetServerAddress) throws IOException {
if (!(targetServerAddress instanceof InetSocketAddress) || targetServerAddress == null) {
return null;
}
return HttpConnectProxiedSocketAddress.newBuilder()
.setTargetAddress((InetSocketAddress) targetServerAddress)
.setProxyAddress(proxyAddress)
.build();
}
});
}
})
.build();
and then you could use the stubSettings bellow to create your GRPC client:
stubSettings = XYZStubSettings.newBuilder().setTransportChannelProvider(transportProvider);
I can connect to socket.io web service no problem using this library https://github.com/nkzawa/socket.io-client.java . I cannot quite figure out how to connect to a specific namespace though. I have looked through the test code and think I might need to create a Manager class.
Any help would be appreciated. Thank you very much.
Manager manager = new Manager(new URI("http://socket.com"));
Socket socket = manager.socket("/my-namespace");
socket.connect();
The above answer is not working for me.
Actually this code works, please use latest version of socket.io client version :
https://github.com/socketio/socket.io-client-java
Add this in your build.graddle :
compile ('io.socket:socket.io-client:1.0.0') {
// excluding org.json which is provided by Android
exclude group: 'org.json', module: 'json'
}
Then you can connect to your namespace with this snippet :
Socket socket;
try {
socket = IO.socket(socket_host + "/your_namespace");
} catch (URISyntaxException e) {
Log.d("ERROR :", e.toString());
}
socket.connect();
Check this github issue where there are more explanation :
https://github.com/nkzawa/socket.io-android-chat/issues/8
I'm trying to access online .Net Webservice through Java Webservice client.
But unfortunately, am getting an error "Connection timed out: connect"
Below is my code:
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;
public class WebServiceMain {
public static void main(String[] args) {
try {
String endpoint = "http://wsf.cdyne.com/SpellChecker/check.asmx";
Service service = new Service();
Call call = (Call)service.createCall();
call.setProperty(Call.SOAPACTION_USE_PROPERTY, new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "http://ws.cdyne.com/CheckTextBodyV2");
call.setTargetEndpointAddress( new java.net.URL(endpoint) );
call.setPortName(new QName("http://ws.cdyne.com/", "check"));
call.setOperationName(new QName("http://ws.cdyne.com/", "CheckTextBodyV2"));
System.out.println(call.invoke(new Object[] {"helo is my name"}));
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Connection timeout comes because of network issues.try to acess URL in browser.also try to append ?wsdl at the end of URL,you should see the wsdl.if this doesn't work troubleshoot network settings.
Connection timed out: connect
This means that your client application cannot even talk to the Web Service. This is not a programmatic issue.
Check and see whether you can access the end-point through your web browser. If not, then that service is not available. So it doesn't work.
If your browser can access it, and if you are connecting to Internet through a proxy, then you need to specify the proxy details to Java Client. To do that, you can use -Dhttp.proxyHost=10.2.240.11 and -Dhttp.proxyPort=8080 (replace with your values) system properties when you start up your client application.
Download the soapui software and get installed it.
then load the wsdl file and create the project.
Then test your web service via soap ui.
you can edit the connection timeout value of the soap ui. chane it for big vlue and test.still your getiong time out ping to the ip addres of the service
I'm testing an application in a Pearl 9100. My app uses ConnectionFactory in order to get an available connection an perform an HTTP request.
I'm setting up the ConnectionFactory like this
protected int[] preferredTransportTypes = { TransportInfo.TRANSPORT_TCP_WIFI,
TransportInfo.TRANSPORT_MDS, TransportInfo.TRANSPORT_TCP_CELLULAR };
protected int[] disallowedTransportTypes = { TransportInfo.TRANSPORT_BIS_B,
TransportInfo.TRANSPORT_WAP,
TransportInfo.TRANSPORT_WAP2 };
Because I cannot use WAP or WAP2. Then I open the connection like this:
ConnectionDescriptor connd = cf.getConnection(url);
conn = (HttpConnection) connd.getConnection();
If I set WiFi ON and conneted to a WiFi Network, everything goes fine. But If I only leave the Mobile Network using 3G, the variable "connd" is Null when passing line number 1.
Why can this be possible?
Which should be the standard transport for a 3rd party app that wants to use the internet service?
Thanks!
Ezequiel
Why can this be possible?
Do you have your APN settings configured on device? They are wireless provider specific. Try googling on "BlackBerry APN settings " to find those settings.
Which should be the standard transport for a 3rd party app that wants to use the internet service?
Unfortunatelly, there is no simple answer. It depends, as they say. Check this tutorial for best practices and ideas. In the tutorial there is an approach on what transports and in what order to support.