1 package org.kuali.ole.describe.service;
2
3
4 import org.kuali.rice.core.api.config.property.ConfigContext;
5
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
8 import java.io.OutputStreamWriter;
9 import java.io.Writer;
10 import java.net.URL;
11 import java.net.URLConnection;
12 import java.net.URLEncoder;
13
14
15
16
17
18
19
20
21 public class MockDocstoreHelperService {
22
23 private static final String DOCSTORE_URL = "docstore.url";
24 private final String ROLLBACK_DATA_FROM_DOCSTORE = "docAction=deleteWithLinkedDocs&requestContent=";
25
26 public void rollbackData(String xmlForRollback) throws Exception {
27 String queryString = ROLLBACK_DATA_FROM_DOCSTORE + URLEncoder.encode(xmlForRollback, "UTF-8");
28 String docstoreURL = ConfigContext.getCurrentContextConfig().getProperty(DOCSTORE_URL);
29 postData(docstoreURL, queryString + queryString);
30 }
31
32 public static String postData(String target, String content) throws Exception {
33 String response = "";
34 URL url = new URL(target);
35 URLConnection conn = url.openConnection();
36 conn.setDoInput(true);
37 conn.setDoOutput(true);
38 conn.setUseCaches(false);
39 conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
40
41 Writer w = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
42 w.write(content);
43 w.close();
44 BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
45 String temp;
46 while ((temp = in.readLine()) != null) {
47 response += temp + "\n";
48 }
49 in.close();
50 return response;
51 }
52 }