List of usage examples for java.net HttpURLConnection setDoInput
public void setDoInput(boolean doinput)
From source file:org.jboss.pnc.buildagent.server.TestGetRunningProcesses.java
private HttpURLConnection retrieveProcessList() throws IOException { URL url = new URL("http://" + HOST + ":" + PORT + "/processes"); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true);/*w w w. j a v a2 s .c o m*/ connection.setDoInput(true); return connection; }
From source file:com.spotify.helios.system.APITest.java
private HttpURLConnection post(final String path, final byte[] body) throws IOException { final URL url = new URL(masterEndpoint() + path); final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setDoInput(true); connection.setDoOutput(true);/* w w w.jav a 2 s . c om*/ connection.getOutputStream().write(body); return connection; }
From source file:edu.pdx.cecs.orcycle.Uploader.java
private boolean uploadOneSegment(long currentNoteId) { boolean result = false; final String postUrl = mCtx.getResources().getString(R.string.post_url); try {/* w w w .j a va 2s .c o m*/ URL url = new URL(postUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); // Allow Inputs conn.setDoOutput(true); // Allow Outputs conn.setUseCaches(false); // Don't use a Cached Copy conn.setRequestMethod("POST"); conn.setRequestProperty("Connection", "Keep-Alive"); conn.setRequestProperty("ENCTYPE", "multipart/form-data"); conn.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary); conn.setRequestProperty("Cycleatl-Protocol-Version", "4"); SegmentData segmentData = SegmentData.fetchSegment(mCtx, currentNoteId); JSONObject json = segmentData.getJSON(); String deviceId = userId; DataOutputStream stream = new DataOutputStream(conn.getOutputStream()); stream.writeBytes(makeContentField("ratesegment", json.toString())); stream.writeBytes(makeContentField("version", String.valueOf(kSaveNoteProtocolVersion))); stream.writeBytes(makeContentField("device", deviceId)); stream.writeBytes(contentFieldPrefix); stream.flush(); stream.close(); int serverResponseCode = conn.getResponseCode(); String serverResponseMessage = conn.getResponseMessage(); Log.v(MODULE_TAG, "HTTP Response is : " + serverResponseMessage + ": " + serverResponseCode); if (serverResponseCode == 201 || serverResponseCode == 202) { segmentData.updateSegmentStatus(SegmentData.STATUS_SENT); result = true; } } catch (IllegalStateException e) { e.printStackTrace(); return false; } catch (IOException e) { e.printStackTrace(); return false; } catch (JSONException e) { e.printStackTrace(); return false; } return result; }
From source file:it.openyoureyes.test.panoramio.Panoramio.java
public List<GeoItem> examinePanoramio(Location current, double distance, Drawable myImage, Intent intent) { ArrayList<GeoItem> result = new ArrayList<GeoItem>(); /*/* w w w . ja va2 s . c om*/ * var requiero_fotos = new Json.Remote( * "http://www.panoramio.com/map/get_panoramas.php?order=popularity& * set= * full&from=0&to=10&minx=-5.8&miny=42.59&maxx=-5.5&maxy=42.65&size= * medium " */ Location loc1 = new Location("test"); Location loc2 = new Location("test_"); AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 225, distance / 2, loc1); AbstractGeoItem.calcDestination(current.getLatitude(), current.getLongitude(), 45, distance / 2, loc2); try { URL url = new URL( "http://www.panoramio.com/map/get_panoramas.php?order=popularity&set=full&from=0&to=10&minx=" + loc1.getLongitude() + "&miny=" + loc1.getLatitude() + "&maxx=" + loc2.getLongitude() + "&maxy=" + loc2.getLatitude() + "&size=thumbnail"); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); conn.connect(); InputStream is = conn.getInputStream(); String line; BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuffer buf = new StringBuffer(); while ((line = reader.readLine()) != null) { buf.append(line + " "); } reader.close(); is.close(); conn.disconnect(); // while (is.read(buffer) != -1); String jsontext = buf.toString(); Log.d("Json Panoramio", jsontext); JSONObject entrie = new JSONObject(jsontext); JSONArray arr = entrie.getJSONArray("photos"); for (int i = 0; i < arr.length(); i++) { JSONObject panoramioObj = arr.getJSONObject(i); double longitude = panoramioObj.getDouble("longitude"); double latitude = panoramioObj.getDouble("latitude"); String urlFoto = panoramioObj.getString("photo_file_url"); String idFoto = panoramioObj.getString("photo_id"); Bundle bu = intent.getExtras(); if (bu == null) bu = new Bundle(); bu.putString("id", idFoto); intent.replaceExtras(bu); BitmapDrawable bb = new BitmapDrawable(downloadFile(urlFoto)); PanoramioItem item = new PanoramioItem(latitude, longitude, false, bb, intent); result.add(item); } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } return result; }
From source file:org.wisdom.openid.connect.request.UserInfoRequest.java
public UserInfoResponse execute() throws IOException { HttpURLConnection connection = (HttpURLConnection) userInfoEndpoint.openConnection(); connection.addRequestProperty("Authorization", format("Bearer %s", accessToken)); connection.setUseCaches(false);//from w w w .j a va 2 s . com connection.setDoInput(true); connection.setDoOutput(true); //Get Response JsonNode node = new ObjectMapper().readTree(connection.getInputStream()); return new UserInfoResponse(node.get("sub").asText(), node); }
From source file:gov.medicaid.verification.BaseSOAPClient.java
/** * Invokes the web service using the request provided. * * @param serviceURL the end point reference * @param original the payload//from www . j a v a2 s. com * @return the response * @throws IOException for IO errors while executing the request * @throws TransformerException for any transformation errors */ protected String invoke(String serviceURL, String original) throws IOException, TransformerException { URL url = new URL(serviceURL); HttpURLConnection rc = (HttpURLConnection) url.openConnection(); rc.setRequestMethod("POST"); rc.setDoOutput(true); rc.setDoInput(true); rc.setRequestProperty("Content-Type", "text/xml; charset=utf-8"); System.out.println("before transform:" + original); String request = transform(requestXSLT, original); System.out.println("after transform:" + request); int len = request.length(); rc.setRequestProperty("Content-Length", Integer.toString(len)); rc.connect(); OutputStreamWriter out = new OutputStreamWriter(rc.getOutputStream()); out.write(request, 0, len); out.flush(); InputStreamReader read; try { read = new InputStreamReader(rc.getInputStream()); } catch (IOException e) { read = new InputStreamReader(rc.getErrorStream()); } try { String response = IOUtils.toString(read); System.out.println("actual result:" + response); String transformedResponse = transform(responseXSLT, response); System.out.println("transformed result:" + transformedResponse); return transformedResponse; } finally { read.close(); rc.disconnect(); } }
From source file:cz.vutbr.fit.xzelin15.dp.consumer.WSDynamicClientFactory.java
private String transferWSDL(String wsdlURL, String userPassword, WiseProperties wiseProperties) throws WiseConnectionException { String filePath = null;//from ww w . ja va2 s . c o m try { URL endpoint = new URL(wsdlURL); // Create the connection HttpURLConnection conn = (HttpURLConnection) endpoint.openConnection(); conn.setDoOutput(false); conn.setDoInput(true); conn.setUseCaches(false); conn.setRequestMethod("GET"); conn.setRequestProperty("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"); // set Connection close, otherwise we get a keep-alive // connection // that gives us fragmented answers. conn.setRequestProperty("Connection", "close"); // BASIC AUTH if (userPassword != null) { conn.setRequestProperty("Authorization", "Basic " + (new BASE64Encoder()).encode(userPassword.getBytes())); } // Read response InputStream is = null; if (conn.getResponseCode() == 200) { is = conn.getInputStream(); } else { is = conn.getErrorStream(); InputStreamReader isr = new InputStreamReader(is); StringWriter sw = new StringWriter(); char[] buf = new char[200]; int read = 0; while (read != -1) { read = isr.read(buf); sw.write(buf); } throw new WiseConnectionException("Remote server's response is an error: " + sw.toString()); } // saving file File file = new File(wiseProperties.getProperty("wise.tmpDir"), new StringBuffer("Wise").append(IDGenerator.nextVal()).append(".xml").toString()); OutputStream fos = new BufferedOutputStream(new FileOutputStream(file)); IOUtils.copyStream(fos, is); fos.close(); is.close(); filePath = file.getPath(); } catch (WiseConnectionException wce) { throw wce; } catch (Exception e) { throw new WiseConnectionException("Wsdl download failed!", e); } return filePath; }
From source file:de.onelogic.android.weatherdemo.WeatherFetchTask.java
private String downloadUrl(String urlString) throws IOException { URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(10000 /* milliseconds */); conn.setConnectTimeout(15000 /* milliseconds */); conn.setRequestMethod("GET"); conn.setDoInput(true); // Starts the query conn.connect();/*from w ww. j ava 2 s . com*/ InputStream is = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = null; StringBuilder sb = new StringBuilder(); while ((line = reader.readLine()) != null) { sb.append(line); } return sb.toString(); }
From source file:ee.ria.xroad.proxy.clientproxy.WsdlRequestProcessor.java
HttpURLConnection createConnection(SoapMessageImpl message) throws Exception { URL url = new URL("http://127.0.0.1:" + SystemProperties.getClientProxyHttpPort()); HttpURLConnection con = (HttpURLConnection) url.openConnection(); con.setDoInput(true); con.setDoOutput(true);//from w ww .j ava 2 s . co m // Use the same timeouts as client proxy to server proxy connections. con.setConnectTimeout(SystemProperties.getClientProxyTimeout()); con.setReadTimeout(SystemProperties.getClientProxyHttpClientTimeout()); con.setRequestMethod("POST"); con.setRequestProperty(HttpHeaders.CONTENT_TYPE, MimeUtils.contentTypeWithCharset(MimeTypes.TEXT_XML, StandardCharsets.UTF_8.name())); IOUtils.write(message.getBytes(), con.getOutputStream()); if (con.getResponseCode() != HttpURLConnection.HTTP_OK) { throw new RuntimeException( "Received HTTP error: " + con.getResponseCode() + " - " + con.getResponseMessage()); } return con; }
From source file:org.openmeetings.app.rss.LoadAtomRssFeed.java
public LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, Object>>> parseRssFeed( String urlEndPoint) {//from www . j a v a2s . co m try { LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, Object>>> lMap = new LinkedHashMap<String, LinkedHashMap<String, LinkedHashMap<String, Object>>>(); URL url = new URL(urlEndPoint); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setDoInput(true); conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322)"); conn.setRequestProperty("Referer", "http://incubator.apache.org/openmeetings/"); conn.connect(); SAXReader reader = new SAXReader(); Document document = reader.read(conn.getInputStream()); Element root = document.getRootElement(); int l = 0; for (@SuppressWarnings("unchecked") Iterator<Element> i = root.elementIterator(); i.hasNext();) { Element item = i.next(); LinkedHashMap<String, LinkedHashMap<String, Object>> items = new LinkedHashMap<String, LinkedHashMap<String, Object>>(); boolean isSubElement = false; for (@SuppressWarnings("unchecked") Iterator<Element> it2 = item.elementIterator(); it2.hasNext();) { Element subItem = it2.next(); LinkedHashMap<String, Object> itemObj = new LinkedHashMap<String, Object>(); itemObj.put("name", subItem.getName()); itemObj.put("text", subItem.getText()); LinkedHashMap<String, String> attributes = new LinkedHashMap<String, String>(); for (@SuppressWarnings("unchecked") Iterator<Attribute> attr = subItem.attributeIterator(); attr.hasNext();) { Attribute at = attr.next(); attributes.put(at.getName(), at.getText()); } itemObj.put("attributes", attributes); // log.error(subItem.getName()+ ": " +subItem.getText()); items.put(subItem.getName(), itemObj); isSubElement = true; } if (isSubElement) { l++; lMap.put("item" + l, items); } } return lMap; } catch (Exception err) { log.error("[parseRssFeed]", err); } return null; }