Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.kevoree.library.client;
 
 
 import java.net.URL;

Created by duke on 8/26/14.
public class KevoreeRestClient {
    private String url;
    public KevoreeRestClient(String url) {
        this. = url;
        if (this..endsWith("/")) {
            this. = this..substring(0, this..length() - 1);
        }
    }
    public String send2Channel(String channelNameString payloadthrows Exception {
        return send(. + channelNamepayload);
    }
    public String send2Port(String componentNameString portNameString payloadthrows Exception {
        return send(. + componentName + "/" + portNamepayload);
    }
    private String send(String pathString payloadthrows Exception {
        URL obj = new URL( + path);
        HttpURLConnection con = (HttpURLConnectionobj.openConnection();
        con.setRequestMethod("POST");
        con.setRequestProperty("User-Agent""KevoreeClient");
        con.setRequestProperty("Accept-Language""en-US,en;q=0.5");
        con.setDoOutput(true);
        DataOutputStream wr = new DataOutputStream(con.getOutputStream());
        wr.writeBytes(payload);
        wr.flush();
        wr.close();
        int responseCode = con.getResponseCode();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(con.getInputStream()));
        String inputLine;
        StringBuffer response = new StringBuffer();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        return response.toString();
    }
New to GrepCode? Check out our FAQ X