Examples of HttpURLConnection


Examples of java.net.HttpURLConnection

         */
        public Response putBucketLogging(String bucket, String loggingXMLDoc, Map headers) throws IOException {
            Map pathArgs=new HashMap();
            pathArgs.put("logging", null);
            S3Object object=new S3Object(loggingXMLDoc.getBytes(), null);
            HttpURLConnection request=makeRequest("PUT", bucket, "", pathArgs, headers, object);

            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

Examples of java.net.HttpURLConnection

            S3Object object=new S3Object(aclXMLDoc.getBytes(), null);

            Map pathArgs=new HashMap();
            pathArgs.put("acl", null);

            HttpURLConnection request=
                    makeRequest("PUT", bucket, Utils.urlencode(key), pathArgs, headers, object);

            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

Examples of java.net.HttpURLConnection

            }

            // build the domain based on the calling format
            URL url=format.getURL(isSecure, server, this.port, bucket, key, pathArgs);

            HttpURLConnection connection=(HttpURLConnection)url.openConnection();
            connection.setRequestMethod(method);

            // subdomain-style urls may encounter http redirects.
            // Ensure that redirects are supported.
            if(!connection.getInstanceFollowRedirects()
                    && format.supportsLocatedBuckets())
                throw new RuntimeException("HTTP redirect support required.");

            addHeaders(connection, headers);
            if(object != null) addMetadataHeaders(connection, object.metadata);
View Full Code Here

Examples of java.net.HttpURLConnection

            return connection;
        }

        private HttpURLConnection makePreSignedRequest(String method, String preSignedUrl, Map headers) throws IOException {
            URL url = new URL(preSignedUrl);
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod(method);

            addHeaders(connection, headers);

            return connection;
        }
View Full Code Here

Examples of java.net.HttpURLConnection

    @Override
    public DataSource invoke(DataSource msg) {
      try {
        final URL url = new URL(endpoint);
        final HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        httpConn.setRequestMethod((String) requestContext.get(MessageContext.HTTP_REQUEST_METHOD));
        Map<String, List<String>> header = (Map<String, List<String>>)requestContext.get(MessageContext.HTTP_REQUEST_HEADERS);
        for (Map.Entry<String, List<String>> entry : header.entrySet()) {
          String value = StringUtil.join(entry.getValue(), ","); //$NON-NLS-1$
          httpConn.setRequestProperty(entry.getKey(), value);
        }
        String username = (String) requestContext.get(Dispatch.USERNAME_PROPERTY);
        String password = (String) requestContext.get(Dispatch.PASSWORD_PROPERTY);
 
        if (username != null) {
          httpConn.setRequestProperty("Authorization", "Basic " + Base64.encodeBytes((username + ':' + password).getBytes())); //$NON-NLS-1$ //$NON-NLS-2$
        }
       
        if (msg != null) {
          httpConn.setDoOutput(true);
          OutputStream os = httpConn.getOutputStream();
          InputStream is = msg.getInputStream();
          ObjectConverterUtil.write(os, is, -1);
        }
       
        return new HttpDataSource(url, httpConn);
View Full Code Here

Examples of java.net.HttpURLConnection

      }

      url = (URL)http_properties.get( ClientIDGenerator.PR_URL );
     
    
      HttpURLConnection con = (HttpURLConnection)url.openConnection();
     
      con.connect();
     
      ByteArrayOutputStream message = new ByteArrayOutputStream();
      InputStream is = con.getInputStream();
     
      byte[] data = new byte[ 1024 ];
     
      int  expected_length = -1;
           
View Full Code Here

Examples of java.net.HttpURLConnection

            new AEThread( "TorrentDownloader:statusreader" )
        {
              public void
          runSupport()
              {
                HttpURLConnection http_con = (HttpURLConnection)con;
               
                boolean changed_status  = false;
                String  last_status    = "";
               
                boolean  sleep = false;
               
                long  last_progress_update = SystemTime.getMonotonousTime();
               
                while( true ){
                 
                  try{
                    if ( sleep ){
                   
                      Thread.sleep(50);
                     
                      sleep = false;
                    }
                   
                    try{
                      this_mon.enter();
                     
                      if ( !status_reader_run[0] ){
                     
                        break;
                      }
                    }finally{
                     
                      this_mon.exit();
                    }
                   
                    String  s = http_con.getResponseMessage();
                     
                    if ( s.equals( last_status )){
                     
                      sleep = true;
                     
                    }else{
                     
                      last_status = s;
                     
                      String lc_s = s.toLowerCase();
                     
                      if ( !lc_s.startsWith("error:")){
                       
                        if ( s.toLowerCase().indexOf( "alive" ) != -1 ){
                         
                          if ( percentDone < 10 ){
                           
                            percentDone++;
                          }
                        }
                       
                        boolean progress_update = false;
                       
                           int  pos = s.indexOf( '%' );
                           
                            if ( pos != -1 ){
                             
                              int   i;
                             
                              for ( i=pos-1;i>=0;i--){
                               
                                char  c = s.charAt(i);
                               
                                if ( !Character.isDigit( c ) && c != ' ' ){
                                 
                                  i++;
                                 
                                  break;
                                }
                              }
                             
                              try{
                                percentDone = Integer.parseInt( s.substring( i, pos ).trim());
                               
                                progress_update = true;
                               
                              }catch( Throwable e ){
                               
                              }
                            }
                           
                            if ( lc_s.startsWith("received")){
                             
                              progress_update = true;
                            }
                           
                            if ( progress_update ){
                             
                              long now = SystemTime.getMonotonousTime();
                             
                              if ( now - last_progress_update < 250 ){
                               
                                continue;
                              }
                           
                              last_progress_update = now;
                            }
                           
                        setStatus(s);
                      }else{
                       
                        error(http_con.getResponseCode(), s.substring(6));
                      }
                     
                      changed_status  = true;
                    }
                  }catch( Throwable e ){
View Full Code Here

Examples of java.net.HttpURLConnection

        lastUpdate = mLastGroupUpdate.get(hydraGroup);
      }

      mLog.log(Level.ALL, "Loading URL : " + url.toString());

      HttpURLConnection con = (HttpURLConnection) url.openConnection();
      con.setReadTimeout(Plugin.getPluginManager().getTvBrowserSettings()
              .getDefaultNetworkConnectionTimeout());
      con.setIfModifiedSince(lastUpdate);

      int responseCode = con.getResponseCode();

      if (responseCode == 200) {
        if (monitor != null) {
          monitor.setMessage(mLocalizer.msg("Progressmessage.30",
                  "Parsing channel list"));
        }
        int fileSize = con.getContentLength();
        if (fileSize == 0) {
          throw new TvBrowserException(SweDBTvDataService.class,
              "errorEmptyChannelList",
              "Channel list file for group \"{0}\" is empty: {1}.", group.getName(), url);
        }
        else {
          DataHydraChannelContainer[] DataHydracontainers = DataHydraChannelParser.parse(IOUtilities.openSaveGZipInputStream(con.getInputStream()));

          if (monitor != null) {
            monitor.setMessage(mLocalizer.msg("Progressmessage.40", "Found {0} channels, downloading channel icons...", DataHydracontainers.length));
          }

          mLastGroupUpdate.put(hydraGroup, con.getLastModified());
          con.disconnect();

          ArrayList<Channel> loadedChannels = new ArrayList<Channel>();

          for (DataHydraChannelContainer container : DataHydracontainers) {
            initializeIconLoader(hydraGroup);
View Full Code Here

Examples of java.net.HttpURLConnection

      Date testDay = testStart.addDays(b);
      String fileDate = createFileName(testDay);
      try {
        String urlString = internalChannel.getBaseUrl() + internalChannel.getId() + "_" + fileDate + ".xml.gz";
        URL url = new URL(urlString);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(Plugin.getPluginManager().getTvBrowserSettings().getDefaultNetworkConnectionTimeout());
        conn.setIfModifiedSince(internalChannel.getLastUpdate(testDay));
        conn.setRequestMethod("HEAD"); // Only make a HEAD request, to
        // see if the file has been
        // changed (only get the HTTP
        // Header fields).
        if (conn.getResponseCode() == 200) {
          modifiedDates.add(testDay);
        }
        mLog.info("mInternalChannel.lastModified=" + internalChannel.getLastUpdate(testDay));
      } catch (Exception e) {
        throw new TvBrowserException(SweDBTvDataService.class,
                "An error occurred in updateTvData",
                "Please report this to the developer", e);
      }
    } // int b
    mLog.info("Number of modified days for channel " + internalChannel.getName() + ":" + modifiedDates.size());
    monitor.setMessage(mLocalizer.msg("updateTvData.progressmessage.20",
            "{0}: Retrieving updated/new programs.", channel.getName()));

    /*********************************************************************
     * IF we found any modified/missing data, we have to download the
     * files before and after each date, since the XMLTV-data files are
     * split in UTC-time while provider is in a different timezone. This
     * procedure ensures that we get all of the data. (There is a small
     * risk that we miss updated data, since we do not verify if the files
     * before and after the actual date has been modified - but we do not
     * care for now)
     ********************************************************************/
    if (modifiedDates.size() > 0) {
      Date prevDate;
      Date currDate;

      Hashtable<String, Date> fileDates = new Hashtable<String, Date>();
      prevDate = new Date((modifiedDates.get(0)).addDays(-1));
      fileDates.put(prevDate.getDateString(), prevDate);
      for (Date modifiedDate : modifiedDates) {
        currDate = modifiedDate;
        if (currDate.equals(prevDate.addDays(1))) {
          if (!fileDates.containsKey(currDate.getDateString())) {
            fileDates.put(currDate.getDateString(), currDate);
          }
        } else {
          Date tempDate = new Date(prevDate.addDays(1));
          if (!fileDates.containsKey(tempDate.getDateString())) {
            fileDates.put(tempDate.getDateString(), tempDate);
          }
          tempDate = new Date(currDate.addDays(-1));
          if (!fileDates.containsKey(tempDate.getDateString())) {
            fileDates.put(tempDate.getDateString(), tempDate);
          }
          if (!fileDates.containsKey(currDate.getDateString())) {
            fileDates.put(currDate.getDateString(), currDate);
          }

        }
        prevDate = currDate;
      }// for j
      currDate = new Date(prevDate.addDays(1));
      if (!fileDates.containsKey(currDate.getDateString())) {
        fileDates.put(currDate.getDateString(), currDate);
      }
      mLog.info(currDate.getDateString());

      /*******************************************************************
       * OK... So now we are ready to start parsing the selected data
       * files
       ******************************************************************/
      Hashtable<String, MutableChannelDayProgram> dataHashtable = new Hashtable<String, MutableChannelDayProgram>();
      Enumeration<Date> en = fileDates.elements();
      monitor.setMessage(mLocalizer.msg(
              "updateTvData.progressmessage.30", "{0}: Reading datafiles",
              channel.getName()));
      while (en.hasMoreElements()) {
        try {
          Date date = (en.nextElement());
          String strFileDate = createFileName(date);
          mLog.info("getting: " + internalChannel.getBaseUrl()
                  + internalChannel.getId() + "_" + strFileDate
                  + ".xml.gz");
          URL url = new URL(internalChannel.getBaseUrl()
                  + internalChannel.getId() + "_" + strFileDate
                  + ".xml.gz");
          HttpURLConnection con = (HttpURLConnection) url
                  .openConnection();
          con.setReadTimeout(Plugin.getPluginManager()
                  .getTvBrowserSettings()
                  .getDefaultNetworkConnectionTimeout());

          if (con.getResponseCode() == 200) {
            DataHydraDayParser.parseNew(IOUtilities.openSaveGZipInputStream(con
                    .getInputStream()), channel, date, dataHashtable, service);
            if (modifiedDates.contains(date)) {
              mLog.info("Updating lastUpdate property for date "
                      + date.toString());
              internalChannel.setLastUpdate(date, con
                      .getLastModified());
            }
          }
        } catch (Exception e) {
          throw new TvBrowserException(SweDBTvDataService.class,
View Full Code Here

Examples of java.net.HttpURLConnection

                .append("&channel=")
                .append(channel.getId());
        System.out.println(buf);
        URL url = new URL(buf.toString());

        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        InputStream in = con.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        Matcher matcher;
        Pattern pattern = Pattern.compile("<tr><td>(\\d+):(\\d+)</td><td>(.*?)</td><td>(.*?)</td><td>(.*?)</td></tr>");
 
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.