Package java.net

Examples of java.net.HttpURLConnection


    Model model = ModelFactory.createDefaultModel();
    model.read(new File("testdata/danbri-20060920123618661.rdf").toURL()
        .toString());
    model = LeanDiffPatch.leanify(model);
    HttpURLConnection connection = (HttpURLConnection) sourceURL
        .openConnection();
    connection.addRequestProperty("Cookie", "login=beta:tester");
    connection.setDoOutput(true);
    connection.setRequestMethod("PUT");
    OutputStream out = connection.getOutputStream();
    model.write(out);
    int responseCode = connection.getResponseCode();
    assertEquals(200, responseCode);
    connection.disconnect();
    Model retrievedModel = ModelFactory.createDefaultModel();
    retrievedModel.read(sourceURL.toString());
    assertTrue("Retrieved model isomorphic to equals", model.isIsomorphicWith(retrievedModel));
    webServer.stop();
View Full Code Here


    Model model = ModelFactory.createDefaultModel();
    model.read(new File("testdata/danbri-20060920123618661.rdf").toURL()
        .toString());
    model = LeanDiffPatch.leanify(model);
    HttpURLConnection connection = (HttpURLConnection) sourceURL
        .openConnection();
    connection.addRequestProperty("Cookie", "login=beta:wrong");
    connection.setDoOutput(true);
    connection.setRequestMethod("PUT");
    OutputStream out = connection.getOutputStream();
    model.write(out);
    int responseCode = connection.getResponseCode();
    assertEquals(403, responseCode);
    connection.disconnect();
    webServer.stop();

  }
View Full Code Here

   */
  private SliceResponse getSlice(URL remoteService, String source, Date date) {
    try {
      log.info("getting slice of " + source + " at " + date);
      URL sliceURL = getSliceURL(remoteService, source, date);
      HttpURLConnection connection = (HttpURLConnection) sliceURL
          .openConnection();
      String gvsFollowing = connection.getHeaderField("X-GVS-Following");
      Date nextFollowing = null;
      if (gvsFollowing != null) {
        StringTokenizer tokenizer = new StringTokenizer(gvsFollowing,
            ",");
        try {
          String nextFollowingString = tokenizer.nextToken();
          nextFollowing = millisDateFormat.parse(nextFollowingString);
        } catch (NoSuchElementException e) {
        } catch (ParseException e) {
          throw new RuntimeException(e);
        }
      }
      Model model = ModelFactory.createDefaultModel();
      model.read(connection.getInputStream(), sliceURL.toExternalForm());
      // model.write(System.out);
      return new SliceResponse(model, nextFollowing);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
View Full Code Here

  private void downloadSource(Source source) {
    log.info("Spidering: "+source);
    Model downloadModel = ModelFactory.createDefaultModel();
    try {
      URL url = new URL(source.getURIRef());
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setInstanceFollowRedirects(false);
      connection.addRequestProperty(HeaderName.ACCEPT.toString(), "application/rdf+xml; q=1, application/xml; q=.9, text/xml; q=.8, */*; q=.1");
      connection.setReadTimeout(3000);
      connection.connect();
      int responseCode = connection.getResponseCode();
      if (responseCode != 200) {
        log.info("Response code: "+connection.getResponseCode());
        if ((responseCode >= 300) && (responseCode < 400)) {
          String location = connection.getHeaderField(HeaderName.LOCATION.toString());
          if (location != null) {
            connection.disconnect();
            downloadSource(new SourceImpl(location));
          }
        }
       
        return;
      }
      downloadModel.read(connection.getInputStream(), source.getURIRef());
      store.assertGraph(source, new FCAGraphImpl(downloadModel));
      connection.disconnect();
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
View Full Code Here

            for (String parameter : keys) {
                URL = URL + parameter + "=" + workItem.getParameter(parameter) + "&";
            }


            HttpURLConnection connection;
           
            URL getUrl = new URL(URL);
            connection = (HttpURLConnection) getUrl.openConnection();
            connection.setRequestMethod("GET");
            System.out.println("Content-Type: " + connection.getContentType());

            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

            String line = reader.readLine();
            String response = "";
            while ((line = reader.readLine()) != null) {
                response +=line;
            }

            setHttpResponseCode(connection.getResponseCode());

           
            this.results = parseResults(response);
           
            System.out.println("" + response);
            connection.disconnect();

        } catch (MalformedURLException ex) {
            Logger.getLogger(RestGeoCodeApiCallWorkItemHandler.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(RestGeoCodeApiCallWorkItemHandler.class.getName()).log(Level.SEVERE, null, ex);
View Full Code Here

public class JSONCodecTest extends TestCase {
  public static final String END_POINT = "http://localhost:8080/album/json/picasa";
 
  protected String postOnEndPoint(String postBody) throws MalformedURLException, IOException {
    HttpURLConnection connection = (HttpURLConnection) new URL(END_POINT).openConnection();
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    connection.getOutputStream().write(postBody.getBytes());
    BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getResponseCode() < 300 ? connection.getInputStream() :
      connection.getErrorStream()));
    StringBuffer buf = new StringBuffer();
    String str = bufReader.readLine();
    while(str != null){
      buf.append(str);
      str = bufReader.readLine();
View Full Code Here

import com.jsonws.JSONCodecTest;

public class TestCheckEndPonitDocument extends JSONCodecTest{
 
  public void testEndpointDocument() throws MalformedURLException, IOException{
    HttpURLConnection connection = (HttpURLConnection) new URL(END_POINT).openConnection();
    assertEquals(connection.getResponseCode(), 200);
   
    connection = (HttpURLConnection) new URL(END_POINT + "?config").openConnection();
    assertEquals(connection.getResponseCode(), 200);
  }
View Full Code Here

     *
     * @param url the HTTP URL
     * @return the HTML as a string
     */
    String get(String url) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestMethod("GET");
        conn.setInstanceFollowRedirects(true);
        if (acceptLanguage != null) {
            conn.setRequestProperty("accept-language", acceptLanguage);
        }
        conn.connect();
        int code = conn.getResponseCode();
        contentType = conn.getContentType();
        if (code != HttpURLConnection.HTTP_OK) {
            throw new IOException("Result code: " + code);
        }
        InputStream in = conn.getInputStream();
        String result = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
        conn.disconnect();
        return result;
    }
View Full Code Here

     * @param fileName the file name to post
     * @param in the input stream
     * @return the result
     */
    String upload(String url, String fileName, InputStream in) throws IOException {
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setDoOutput(true);
        conn.setDoInput(true);
        conn.setUseCaches(false);
        conn.setRequestMethod("POST");
        conn.setRequestProperty("Connection", "Keep-Alive");
        String boundary = UUID.randomUUID().toString();
        conn.setRequestProperty("Content-Type", "multipart/form-data;boundary="+boundary);
        conn.connect();
        DataOutputStream out = new DataOutputStream(conn.getOutputStream());
        out.writeBytes("--" + boundary + "--\r\n");
        out.writeBytes("Content-Disposition: form-data; name=\"upload\";"
                + " filename=\"" + fileName +"\"\r\n\r\n");
        IOUtils.copyAndCloseInput(in, out);
        out.writeBytes("\r\n--" + boundary + "--\r\n");
        out.close();
        int code = conn.getResponseCode();
        if (code != HttpURLConnection.HTTP_OK) {
            throw new IOException("Result code: " + code);
        }
        in = conn.getInputStream();
        String result = IOUtils.readStringAndClose(new InputStreamReader(in), -1);
        conn.disconnect();
        return result;
    }
View Full Code Here

            System.setProperty("http.proxyHost", "");
            System.setProperty("http.proxyPort", "" + -1);
        }

        try {
            HttpURLConnection uc = (HttpURLConnection) url.openConnection();
            if (useProxy && username.trim().length() > 0) {
            String proxyUPB64 = Base64.encode(username + ":" + password);
            uc.setRequestProperty("Proxy-Authorization", "Basic " + proxyUPB64);
            }
           
            uc.setRequestMethod("GET");
            uc.setDoOutput(true);
            uc.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR2.0.50727)");
           
            return uc;
        } catch (IOException ie) {
            throw new HttpConnectionException(ie);
        }
View Full Code Here

TOP

Related Classes of java.net.HttpURLConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.