14 package cz.vutbr.fit.knot.annotations.modules.suggestionManager;
 
   20 import java.io.BufferedReader;
 
   21 import java.io.IOException;
 
   22 import java.io.InputStream;
 
   23 import java.io.InputStreamReader;
 
   24 import java.io.OutputStreamWriter;
 
   25 import java.net.HttpURLConnection;
 
   26 import java.net.MalformedURLException;
 
   27 import java.net.ProtocolException;
 
   29 import java.util.logging.Level;
 
   30 import java.util.logging.Logger;
 
   40   private HttpURLConnection 
conn;
 
   42   private OutputStreamWriter 
outW;
 
   44   private BufferedReader 
inR;
 
   56     catch (MalformedURLException e) {
 
   58         String msg = 
"Unable to create connection from provided URI.";
 
   59         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
   62     catch (IOException e){
 
   64         String msg = 
"Error opening a connection to provided URI.";
 
   65         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
   81     catch (MalformedURLException e) {
 
   83         String msg = 
"Malformed SEC Store API server URI.";
 
   84         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
   89         String msg = 
"Error opening a connection to provided SEC Store API server URI.";
 
   90         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  103     StringBuilder ret = 
new StringBuilder(
"");
 
  105       conn = (HttpURLConnection) 
secServ.openConnection();
 
  107     catch (IOException e) {
 
  108       if(requestInfo != null){
 
  109         int langNum = requestInfo.getSession().getLanguageNum();
 
  110         int lod = requestInfo.getSession().getProtocolLOD();    
 
  114         String msg = 
"Unable to open connection to the SEC API server.";
 
  115         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  120       if(requestInfo != null){
 
  121         int langNum = requestInfo.getSession().getLanguageNum();
 
  122         int lod = requestInfo.getSession().getProtocolLOD();    
 
  126         String msg = 
"Unable to open connection to the SEC API server.";
 
  127         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  134       conn.setRequestMethod(
"POST");
 
  135       conn.setDoOutput(
true);
 
  136       conn.setDoInput(
true);
 
  137       conn.addRequestProperty(
"Content-Length", Integer.toString(requestData.length()));
 
  139     catch (ProtocolException e) {
 
  140       if(requestInfo != null){
 
  141         int langNum = requestInfo.getSession().getLanguageNum();
 
  142         int lod = requestInfo.getSession().getProtocolLOD();    
 
  146         String msg = 
"Unable to set protocol request method for SEC API connection.";
 
  147         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  154       outW = 
new OutputStreamWriter(
conn.getOutputStream(), 
"UTF-8");
 
  155       outW.write(requestData);
 
  158     catch (IOException e) {
 
  159       if(requestInfo != null){
 
  160         int langNum = requestInfo.getSession().getLanguageNum();
 
  161         int lod = requestInfo.getSession().getProtocolLOD();    
 
  165         String msg = 
"Unable to get output stream for SEC API connection.";
 
  166         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  174       is = conn.getInputStream();
 
  176     catch (Exception e)  {
 
  177       if(requestInfo != null){
 
  178         int langNum = requestInfo.getSession().getLanguageNum();
 
  179         int lod = requestInfo.getSession().getProtocolLOD();    
 
  183         String msg = 
"Unable to get input stream for SEC API connection.";
 
  184         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  188     InputStreamReader isr = 
new InputStreamReader(is);
 
  189     inR = 
new BufferedReader(isr);
 
  192       while((inputLine = 
inR.readLine()) != null) {
 
  193         ret.append(inputLine);
 
  197     catch (IOException e) {
 
  198       if(requestInfo != null){
 
  199         int langNum = requestInfo.getSession().getLanguageNum();
 
  200         int lod = requestInfo.getSession().getProtocolLOD();    
 
  204         String msg = 
"Unable to read from input stream connected to SEC API server.";
 
  205         Logger.getLogger(SECAPIConn.class.getName()).log(Level.SEVERE, msg);
 
  210     return ret.toString();
 
String sendReqToSECAPI(String requestData, RequestInfo requestInfo)
static String getSecApiServerUri()
Singleton for storing global variables. 
SECAPIConn(String secUri)
static final int ERROR_60_SEC_NOT_AVAILABLE
static final int LOG_LEVEL
static final int LOG_LEVEL_SERVER_ERRORS
Class implementing functions for communication with remote SEC API. 
Processed informations about client request. 
Class responsible for localised strings.