Example usage for java.net URLConnection setDoInput

List of usage examples for java.net URLConnection setDoInput

Introduction

In this page you can find the example usage for java.net URLConnection setDoInput.

Prototype

public void setDoInput(boolean doinput) 

Source Link

Document

Sets the value of the doInput field for this URLConnection to the specified value.

Usage

From source file:savant.view.swing.Savant.java

private static void logUsageStats() {
    try {// w ww.  ja  v  a  2  s. c o m
        URLConnection urlConn;
        DataOutputStream printout;
        // URL of CGI-Bin script.
        // URL connection channel.
        urlConn = BrowserSettings.LOG_USAGE_STATS_URL.openConnection();
        // Let the run-time system (RTS) know that we want input.
        urlConn.setDoInput(true);
        // Let the RTS know that we want to do output.
        urlConn.setDoOutput(true);
        // No caching, we want the real thing.
        urlConn.setUseCaches(false);
        // Specify the content type.
        urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        // Send POST output.
        printout = new DataOutputStream(urlConn.getOutputStream());

        DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date = new Date();
        Locale locale = Locale.getDefault();

        String content = post("time", dateFormat.format(date)) + "&"
                + post("language", locale.getDisplayLanguage()) + "&"
                + post("user.timezone", System.getProperty("user.timezone")) + "&"
                + post("savant.version", BrowserSettings.VERSION) + "&"
                + post("savant.build", BrowserSettings.BUILD)
                //+ "&" + post("address", InetAddress.getLocalHost().getHostAddress())
                + "&" + post("java.version", System.getProperty("java.version")) + "&"
                + post("java.vendor", System.getProperty("java.vendor")) + "&"
                + post("os.name", System.getProperty("os.name")) + "&"
                + post("os.arch", System.getProperty("os.arch")) + "&"
                + post("os.version", System.getProperty("os.version")) + "&"
                + post("user.region", System.getProperty("user.region"));

        printout.writeBytes(content);
        printout.flush();
        printout.close();
        urlConn.getInputStream();
    } catch (Exception ex) {
        //LOG.error("Error logging usage stats.", ex);
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Removes the given Rule from the PolicySet which is stored on the server
 * /*from w  ww.ja  v  a 2 s.co  m*/
 * @param oo
 * @return
 */
private boolean requestRemoveRule(OIDObject oo) {

    try {
        URL url = new URL(strRelURL + "/" + privilegedServlet
                + "CreateConsentServiceServlet?type=removeRule&id=" + oo.getIdentifier());
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        is.close();

        JSONObject ack = new JSONObject(s);

        return ack.getBoolean("removed");
    } catch (Exception e) {
        return false;
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests a newly created CDA Document from the server
 * //from w w  w . jav a  2  s . co  m
 */
private void requestDocument() {
    try {

        URL url = new URL(
                strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=newconsentcda");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();
        is.close();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        cda = db.parse(new InputSource(new ByteArrayInputStream(s.getBytes("utf-8"))));

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests a standard CDA Document object for the given participation status
 * /*from  www  . j  av  a 2s .co m*/
 * @param participation
 */
private void requestStandardConsentDocument(boolean participation) {
    try {

        URL url = new URL(strRelURL + "/" + privilegedServlet
                + "CreateConsentServiceServlet?type=standardconsentCDA&participation=" + participation);
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        cda = db.parse(new InputSource(new ByteArrayInputStream(s.getBytes("utf-8"))));

        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests a Rule description for the currently selected data from the server
 * @return/*from  w  w  w.j av a  2  s .c  om*/
 */
private String requestRuleDescription() {
    try {
        String toBeUrl = strRelURL + "/" + privilegedServlet
                + "CreateConsentServiceServlet?type=ruleDescription" + "&organisation=" + organisation
                + "&persons=" + persons + "&affectedOID=" + affectedOID + "&documents=" + documents
                + "&documentsOID=" + documentsOID + "&accessType=" + accessType + "&grantAccess=" + grantAccess;

        URL url = new URL(encodeString(toBeUrl));

        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        is.close();

        JSONObject jsoo = new JSONObject(s);

        return jsoo.getString("description");

    } catch (Exception e) {
        //e.printStackTrace();
        return "";
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests the list of Rule descriptions belonging to the currently worked on user
 *//*ww w  . j  a v a  2 s.c o  m*/
private void requestRuleList() {
    try {
        URL url = new URL(strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=rulelist");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        JSONArray jsa = new JSONArray(s);

        ruleListModel = new DefaultListModel();

        for (int i = 0; i < jsa.length(); i++) {

            JSONObject jsoo = (JSONObject) jsa.get(i);

            OIDObject oi = new OIDObject(jsoo.getString("ruleID"), jsoo.getString("description"), true);

            ruleListModel.addElement(oi);
        }

        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests the currently available document-types
 * //from w  ww  . ja v a  2s. c  om
 */
private void requestDocumentList() {
    try {
        URL url = new URL(
                strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=documenttypes");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        JSONArray jsa = new JSONArray(s);

        documentComboBoxModel = new DefaultComboBoxModel();

        for (int i = 0; i < jsa.length(); i++) {

            JSONObject jsoo = (JSONObject) jsa.get(i);

            OIDObject oi = new OIDObject(jsoo.getString("identifier"), jsoo.getString("name"), true);

            documentComboBoxModel.addElement(oi);
        }
        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests the currently supported personnel-types from the server
 * /*from w  w w  .java 2 s  .  c  om*/
 */
private void requestPersonnelList() {
    try {

        URL url = new URL(strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=persons");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        JSONArray jsa = new JSONArray(s);

        personsComboxBoxModel = new DefaultComboBoxModel();

        for (int i = 0; i < jsa.length(); i++) {

            JSONObject jsoo = (JSONObject) jsa.get(i);

            OIDObject oi = new OIDObject(jsoo.getString("identifier"), jsoo.getString("name"), true);

            personsComboxBoxModel.addElement(oi);
        }

        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests that the created consent be stored as an uncleared consent
 *//*from w w w .jav a2s  . c o m*/
private void requestStoreUnclearedConsent() {

    try {
        URL url = new URL(
                strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=storeunclearedconsent");
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        is.close();

        JSONObject jso = new JSONObject(s);

        boolean success = jso.getBoolean("success");
        String message = jso.getString("message");

        if (success) {

            JOptionPane.showMessageDialog(null, message, "Erfolg", JOptionPane.INFORMATION_MESSAGE);

        } else {

            JOptionPane.showMessageDialog(null, message, "Fehler", JOptionPane.ERROR_MESSAGE);

        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java

/**
 * Requests the children of the given treenode from the server
 * /*from  w w w . j a va2s  . c om*/
 * @param lzynde
 */
private void requestTreeNode(LazyOIDTreeNode lzynde) {

    try {
        URL url = new URL(
                strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=expandtree&identifier="
                        + ((OIDObject) lzynde.getUserObject()).getIdentifier());
        URLConnection conn = url.openConnection();
        conn.setRequestProperty("cookie", strCookie);
        conn.setDoInput(true);

        InputStream is = conn.getInputStream();
        StringWriter writer = new StringWriter();
        IOUtils.copy(new InputStreamReader(is, "UTF8"), writer);
        String s = writer.toString();

        is.close();

        JSONArray jsa = new JSONArray(s);

        for (int i = 0; i < jsa.length(); i++) {

            JSONObject jsoo = (JSONObject) jsa.get(i);

            OIDObject oi = new OIDObject(jsoo.getString("identifier"), jsoo.getString("name"),
                    jsoo.getBoolean("isActive"));

            oi.setHasChildren(jsoo.getBoolean("hasChildren"));

            LazyOIDTreeNode oin = new LazyOIDTreeNode(oi);

            lzynde.add(oin);
            oidTreeModel.insertNodeInto(oin, lzynde, i);
        }

        cap.setOIDTree(oidTreeModel, null, new OIDTreeSelectionListener());

    } catch (Exception e) {
        e.printStackTrace();
    }
}