Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
PiMixedClient.java
Go to the documentation of this file.
1 /* Copyright 2013 Eric Ptak - trouch.com
2  * Licensed under the Apache License, Version 2.0 (the "License");
3  * you may not use this file except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS,
10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11  * See the License for the specific language governing permissions and
12  * limitations under the License.
13 */
14 
15 package com.trouch.webiopi.client;
16 
17 public class PiMixedClient extends PiClient {
18  private PiHttpClient http;
19  private PiCoapClient coap;
20 
21  private int tries = 0;
22  private int maxTries = 3;
23 
24  public PiMixedClient(String host) {
25  super("", "", 0);
26  http = new PiHttpClient(host);
27  coap = new PiCoapClient(host);
28  }
29 
30  public PiMixedClient(String host, int httpPort, int coapPort) {
31  super("", "", 0);
32  http = new PiHttpClient(host, httpPort);
33  coap = new PiCoapClient(host, coapPort);
34  }
35 
36  @Override
37  public void setCredentials(String login, String password) {
38  http.setCredentials(login, password);
39  coap.setCredentials(login, password);
40  }
41 
42  @Override
43  public String sendRequest(String method, String path) throws Exception {
44  if (tries < maxTries) {
45  String response = coap.sendRequest(method, path);
46  if (response != null) {
47  tries = 0;
48  return response;
49  }
50  tries++;
51  }
52 
53  return http.sendRequest(method, path);
54  }
55 
56 }
tuple response
Definition: coap-client.py:9
void setCredentials(String login, String password)
String sendRequest(String method, String path)
PiMixedClient(String host, int httpPort, int coapPort)
String sendRequest(String method, String path)
void setCredentials(String login, String password)
Definition: PiClient.java:32
String sendRequest(String method, String path)