Examples of HttpURLConnection


Examples of java.net.HttpURLConnection

    model.read(new File("testdata/danbri-20060920123618661.rdf").toURL()
        .toString());
    URL serverURL = new URL("http://"
        + serverBinding.getInetAddress().getHostName() + ":"
        + serverBinding.getPort() + "/danbri");
    HttpURLConnection connection = (HttpURLConnection) serverURL
        .openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("PUT");
    OutputStream out = connection.getOutputStream();
    model.write(out);
    int responseCode = connection.getResponseCode();
    assertEquals(403, responseCode);
    webServer.stop();

  }
View Full Code Here

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

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: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

Examples of java.net.HttpURLConnection

   */
  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

Examples of java.net.HttpURLConnection

  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

Examples of java.net.HttpURLConnection

            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

Examples of java.net.HttpURLConnection

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

Examples of java.net.HttpURLConnection

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

Examples of java.net.HttpURLConnection

     *
     * @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

Examples of java.net.HttpURLConnection

     * @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
TOP
Copyright © 2018 www.massapi.com. 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.