List of usage examples for java.net ProtocolException printStackTrace
public void printStackTrace()
From source file:HttpClient1.java
/** * Methode to upload a Metadata file/* w w w . jav a 2 s .c o m*/ * * @param file */ public void addMetadata(File file) { logger.info("PUT Metadata on " + url + " as: " + prop.getProperty("user")); logger.info("Uploading Metadata file: " + file); httpConn.setRequestProperty("content-type", "text/plain; charset=utf-8"); httpConn.setDoOutput(true); try { httpConn.setRequestMethod("PUT"); } catch (ProtocolException e) { e.printStackTrace(); } try { httpConn.connect(); } catch (IOException e) { e.printStackTrace(); } OutputStream out = null; try { out = httpConn.getOutputStream(); fileToOutputStream(file, out); } catch (IOException e) { e.printStackTrace(); } try { out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } httpConn.disconnect(); try { logger.info( "Server respond: " + httpConn.getResponseCode() + " , " + httpConn.getResponseMessage() + "\n"); } catch (IOException e) { e.printStackTrace(); } }
From source file:HttpClient1.java
/** * Methode to upload a data file.//from w w w . j a va 2 s. co m * * @param uploadFile */ public void putData(File uploadFile) { String fileName = uploadFile.getName(); String fieldName = "data"; String boundary = "" + System.currentTimeMillis() + ""; httpConn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); httpConn.setRequestProperty("file", fileName); httpConn.setUseCaches(false); httpConn.setDoOutput(true); httpConn.setDoInput(true); logger.info("PUT Data file on " + url); logger.info("Uploading Data file: " + uploadFile); logger.info("Writing header:" + httpConn.getRequestProperties()); try { httpConn.setRequestMethod("PUT"); } catch (ProtocolException e1) { e1.printStackTrace(); } OutputStream outputStream = null; try { outputStream = (httpConn.getOutputStream()); } catch (IOException e) { e.printStackTrace(); } PrintWriter writer = null; try { writer = new PrintWriter(new OutputStreamWriter(outputStream, "UTF-8"), true); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String LINE_FEED = "\r\n"; logger.debug("Writing body"); writer.append("--" + boundary).append(LINE_FEED); logger.debug("Boundary: " + boundary); writer.append("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\"") .append(LINE_FEED); logger.debug("Content-Disposition: form-data; name=\"" + fieldName + "\"; filename=\"" + fileName + "\""); writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(fileName)).append(LINE_FEED); logger.debug("Content-Type: " + URLConnection.guessContentTypeFromName(fileName)); writer.append("Content-Transfer-Encoding: binary").append(LINE_FEED); logger.debug("Content-Transfer-Encoding: binary"); writer.append(LINE_FEED); writer.flush(); fileToOutputStream(uploadFile, outputStream); try { outputStream.flush(); } catch (IOException e) { e.printStackTrace(); } writer.append(LINE_FEED); writer.flush(); writer.close(); httpConn.disconnect(); try { logger.info( "Server respond: " + httpConn.getResponseCode() + " , " + httpConn.getResponseMessage() + "\n"); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.boxupp.utilities.PuppetUtilities.java
public List<SearchModuleBean> searchModule(HttpServletRequest request) { List<SearchModuleBean> moduleList = new ArrayList<SearchModuleBean>(); String module = request.getParameter("query"); String url = "https://forgeapi.puppetlabs.com:443/v3/modules?query=" + module; try {//from w ww .ja va 2 s.co m HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("owner", request.getParameter("owner")); con.setRequestProperty("tag", request.getParameter("tag")); con.setRequestProperty("show+deleted", request.getParameter("show+deleted")); con.setRequestProperty("sort_by", request.getParameter("sort_by")); con.setRequestProperty("operatingsystem", request.getParameter("operatingsystem")); con.setRequestProperty("supported", request.getParameter("supported")); con.setRequestProperty("pe_requirement", request.getParameter("pe_requirement")); con.setRequestProperty("puppet_requirement", request.getParameter("puppet_requirement")); con.setRequestProperty("limit", request.getParameter("limit")); con.setRequestProperty("offset", request.getParameter("offset")); con.setRequestProperty("If-Modified-Since", request.getParameter("If-Modified-Since")); con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); JSONObject o = new JSONObject(response.toString()); JSONArray jsonArray = o.getJSONArray("results"); for (int i = 0; i < jsonArray.length(); i++) { SearchModuleBean searchModule = new SearchModuleBean(); Gson moduleData = new GsonBuilder().setDateFormat("yyyy'-'MM'-'dd HH':'mm':'ss").create(); searchModule = moduleData.fromJson(jsonArray.get(i).toString(), SearchModuleBean.class); moduleList.add(searchModule); } } catch (ProtocolException e) { logger.error("Error in searching module :" + e.getMessage()); e.printStackTrace(); } catch (IOException e) { logger.error("Error in searching module :" + e.getMessage()); e.printStackTrace(); } catch (JSONException e) { logger.error("Error in searching module :" + e.getMessage()); e.printStackTrace(); } return moduleList; }
From source file:tetujin.nikeapi.core.JNikeLowLevelAPI.java
/** * /*from w w w .j a v a2 s . co m*/ * @param con ?HttpsURLConnection * @return con option??HttpsURLConnection */ protected HttpsURLConnection setHttpHeader(HttpsURLConnection con) { try { con.setRequestMethod(this.method); con.setDoOutput(true); con.setInstanceFollowRedirects(false); con.setRequestProperty("Accept-Language", this.lang); con.setRequestProperty("Accept", this.accept); con.setRequestProperty("appid", this.appid); System.out.println("Accept: " + con.getRequestProperty("Accept")); System.out.println("appid: " + con.getRequestProperty("appid")); return con; } catch (ProtocolException e) { e.printStackTrace(); return con; } }
From source file:UploadTest.java
@Test public void upload_metas_test() { httpCon.setRequestProperty("content-type", "text/plain; charset=utf-8"); httpCon.setDoOutput(true);/* w w w. ja v a 2s. c om*/ try { httpCon.setRequestMethod("PUT"); } catch (ProtocolException e) { e.printStackTrace(); } try { httpCon.connect(); } catch (IOException e) { e.printStackTrace(); } OutputStream out = null; try { out = httpCon.getOutputStream(); File uploadFile = new File("/home/raul/test/frl%3A6376984/6376984_metadata.nt"); fileToOutputStream(uploadFile, out); } catch (IOException e) { e.printStackTrace(); } try { out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } httpCon.disconnect(); try { System.out.println(httpCon.getResponseCode()); } catch (IOException e) { e.printStackTrace(); } }
From source file:utility.DeviceUtility.java
private Boolean RqsLocation(int cid, int lac) { Boolean result = false;/*from ww w . j ava 2 s . c o m*/ String urlmmap = "http://www.google.com/glm/mmap"; try { if (simPresent() == 1) { if (!inAirplaneMode()) { if (CheckNetConnectivity(mactivity)) { URL url = new URL(urlmmap); URLConnection conn = url.openConnection(); HttpURLConnection httpConn = (HttpURLConnection) conn; httpConn.setRequestMethod("POST"); httpConn.setDoOutput(true); httpConn.setDoInput(true); httpConn.setReadTimeout(60000); httpConn.connect(); OutputStream outputStream = httpConn.getOutputStream(); WriteData(outputStream, cid, lac); InputStream inputStream = httpConn.getInputStream(); DataInputStream dataInputStream = new DataInputStream(inputStream); dataInputStream.readShort(); dataInputStream.readByte(); int code = dataInputStream.readInt(); System.out.println("code--->>" + code); if (code == 0) { myLatitude = dataInputStream.readInt(); myLongitude = dataInputStream.readInt(); System.out.println("myLatitude--->>" + myLatitude); System.out.println("myLongitude--->>" + myLongitude); result = true; } /*else { OpenCellID opencellid=new OpenCellID(); try { opencellid.GetOpenCellID(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }*/ } } } } catch (ProtocolException e) { // TODO: handle exception System.out.println("In Protocol Exception"); latitude = "0"; longitude = "0"; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("In IO Exception"); latitude = "0"; longitude = "0"; } return result; }