List of usage examples for java.net URLConnection setRequestProperty
public void setRequestProperty(String key, String value)
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * Requests a standard CDA Document object for the given participation status * /* w w w .j a v a 2s . c o 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 ww . j a v a 2s .com*/ */ 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 *///from w ww . ja v a 2 s . com 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 ww w . j a v a 2s .co m */ 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 . j a v a 2s .co m*/ */ 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 *//*ww w .j a v a2 s.co 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 * // w ww.jav a2s . c o m * @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(); } }
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * Requests that the Rule with the current parameter selection be added to the PolicySet of the user * // w w w .java2 s.c om * @return */ private boolean requestAddRule() { try { String toBeURL = strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=addRule&" + "&organisation=" + organisation + "&persons=" + persons + "&affectedOID=" + affectedOID + "&documents=" + documents + "&documentsOID=" + documentsOID + "&accessType=" + accessType + "&grantAccess=" + grantAccess; System.out.println(organisation); System.out.println(persons); System.out.println(affectedOID); System.out.println(documents); System.out.println(documentsOID); System.out.println(accessType); System.out.println(grantAccess); toBeURL = encodeString(toBeURL); URL url = new URL(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 ss = new JSONObject(s); if (ss.getBoolean("added")) { requestRuleList(); cap.setRuleList(ruleListModel, null); return true; } } catch (Exception e) { return false; } return false; }
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * Requests the root of the organisations tree and it's children *///from w w w . j av a2s.com private void requestTreeRoot() { try { URL url = new URL(strRelURL + "/" + privilegedServlet + "CreateConsentServiceServlet?type=treeroot"); 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); OIDObject root = new OIDObject(jso.getString("identifier"), jso.getString("name"), jso.getBoolean("isActive")); root.setHasChildren(jso.getBoolean("hasChildren")); LazyOIDTreeNode rootNode = new LazyOIDTreeNode(root); JSONArray jsa = jso.getJSONArray("children"); 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); rootNode.add(oin); } oidTreeModel = new DefaultTreeModel(rootNode); cap.setOIDTree(oidTreeModel, null, new OIDTreeSelectionListener()); cap.mainPanel.mp.cp.tp.orgaTree.collapseRow(1); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.baracuda.piepet.nexusrelease.nexus.StageClient.java
/** * Add the BASIC Authentication header to the HTTP connection. * /*from w w w. j av a2 s .com*/ * @param conn the HTTP URL Connection */ private void addAuthHeader(URLConnection conn) { // java.net.Authenticator is brain damaged as it is global and no way to delegate for just one server... try { String auth = username + ":" + password; // there is a lot of debate about password and non ISO-8859-1 characters... // see https://bugzilla.mozilla.org/show_bug.cgi?id=41489 // Base64 adds a trailing newline - just strip it as whitespace is illegal in Base64 String encodedAuth = new Base64().encodeToString(auth.getBytes("ISO-8859-1")).trim(); conn.setRequestProperty("Authorization", "Basic " + encodedAuth); log.debug("Encoded Authentication is: " + encodedAuth); } catch (UnsupportedEncodingException ex) { String msg = "JVM does not conform to java specification. Mandatory CharSet ISO-8859-1 is not available."; log.error(msg); throw new RuntimeException(msg, ex); } }