1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.module.purap.dataaccess.impl;
17
18 import org.kuali.ole.module.purap.dataaccess.B2BDao;
19 import org.kuali.ole.module.purap.exception.B2BConnectionException;
20 import org.kuali.rice.core.framework.persistence.ojb.dao.PlatformAwareDaoBaseOjb;
21
22 import java.io.*;
23 import java.net.HttpURLConnection;
24 import java.net.MalformedURLException;
25 import java.net.ProtocolException;
26 import java.net.URL;
27
28 public class B2BDaoImpl extends PlatformAwareDaoBaseOjb implements B2BDao {
29 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(B2BDaoImpl.class);
30
31
32
33
34 public String sendPunchOutRequest(String request, String punchoutUrl) {
35 LOG.debug("sendPunchOutRequest() started");
36
37 try {
38 URL url = new URL(punchoutUrl);
39 HttpURLConnection conn = (HttpURLConnection) url.openConnection();
40
41 conn.setDoInput(true);
42 conn.setDoOutput(true);
43 conn.setRequestMethod("POST");
44 conn.setRequestProperty("Content-type", "text/xml");
45
46 OutputStream out = conn.getOutputStream();
47 OutputStreamWriter outw = new OutputStreamWriter(out, "UTF-8");
48 outw.write(request);
49 outw.flush();
50 outw.close();
51 out.flush();
52 out.close();
53
54 InputStream inp = conn.getInputStream();
55
56 StringBuffer response = new StringBuffer();
57 int i = inp.read();
58 while (i >= 0) {
59 if (i >= 0) {
60 response.append((char) i);
61 }
62 i = inp.read();
63 }
64 return response.toString();
65 } catch (MalformedURLException e) {
66 LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
67 throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
68 } catch (ProtocolException e) {
69 LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
70 throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
71 } catch (UnsupportedEncodingException e) {
72 LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
73 throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
74 } catch (IOException e) {
75 LOG.error("postPunchOutSetupRequestMessage() Error posting setup", e);
76 throw new B2BConnectionException("Unable to connect to remote site for punchout.", e);
77 }
78 }
79 }