Package javax.microedition.io

Examples of javax.microedition.io.HttpConnection


                }
            }

            if (resource != null) {

                final HttpConnection connection =
                        Utilities.makeConnection(resource.getUrl(), resource
                                .getRequestHeaders(), null);
                resource.setHttpConnection(connection);

                // Signal to the browser field that resource is ready.
View Full Code Here


            return null;
        }

        // If referrer is null we must return the connection.
        if (referrer == null) {
            final HttpConnection connection =
                    Utilities.makeConnection(resource.getUrl(), resource
                            .getRequestHeaders(), null);
            return connection;
        } else {
            // If referrer is provided we can set up the connection on a
View Full Code Here

     * Connects to the url associated with this object
     *
     * @see java.lang.Thread#run()
     */
    public void run() {
        final HttpConnection connection =
                Utilities.makeConnection(_url, _requestHeaders, _postData);
        _application.processConnection(connection, _event);
    }
View Full Code Here

            return null;
        }

        // If referrer is null we must return the connection.
        if (referrer == null) {
            final HttpConnection connection =
                    Utilities.makeConnection(resource.getUrl(), resource
                            .getRequestHeaders(), null);

            return connection;
View Full Code Here

     * Connects to the url associated with this object
     *
     * @see java.lang.Thread#run()
     */
    public void run() {
        final HttpConnection connection =
                Utilities.makeConnection(_url, _requestHeaders, _postData);
        _application.processConnection(connection, _event);
    }
View Full Code Here

                String content = "";

                // Open the connection and extract the data
                try {
                    final HttpConnection httpConn =
                            (HttpConnection) Connector.open(getUrl());

                    final int status = httpConn.getResponseCode();

                    if (status == HttpConnection.HTTP_OK) {
                        // Is this html?
                        final String contentType =
                                httpConn.getHeaderField(HEADER_CONTENTTYPE);
                        final boolean htmlContent =
                                contentType != null
                                        && contentType
                                                .startsWith(CONTENTTYPE_TEXTHTML);

                        final InputStream input = httpConn.openInputStream();

                        final byte[] bytes = IOUtilities.streamToBytes(input);

                        final StringBuffer raw =
                                new StringBuffer(new String(bytes));
                        raw.insert(0, "bytes received]\n");
                        raw.insert(0, bytes.length);
                        raw.insert(0, '[');

                        content = raw.toString();

                        if (htmlContent) {
                            content = prepareData(raw.toString());
                        }
                        input.close();
                    } else {
                        content = "response code = " + status;
                    }
                    httpConn.close();
                } catch (final IOCancelledException e) {
                    System.out.println(e.toString());
                    return;
                } catch (final IOException e) {
                    errorDialog(e.toString());
View Full Code Here

                                                  int connType,
                                                  String requestMethod,
                                                  TweetPhoto tweetPhoto,
                                                  boolean uploadData)
  {
    HttpConnection conn = null;
    OutputStream out    = null;

    if (StringUtilities.startsWithIgnoreCase(url, "www.")) {
      url = "http://" + url;
      }
 
  String login = tweetPhoto.m_tokenIdentifier+":"+tweetPhoto.m_tokenSecret;

    try {
      byte[] encoded = Base64OutputStream.encode(login.getBytes(), 0, login.length(), false, false);
     
      if (url.indexOf(";deviceside=") == -1) {
        switch (connType) {
          case CONNECTION_BES:
            url = url + ";deviceside=false";
            break;
          case CONNECTION_BIS:
            url = url + ";XXXXXXXXXXXXXXXX";
            break;
          case CONNECTION_TCPIP:
            url = url + ";deviceside=true";
            break;
          case CONNECTION_WIFI:
            url = url + ";interface=wifi";
        }
      }

      conn = (HttpConnection) Connector.open(url);

      if (requestHeaders != null) {
        String referer = requestHeaders.getPropertyValue("referer");

        boolean sendReferrer = true;

        if (referer != null &&

            StringUtilities.startsWithIgnoreCase(referer, "https:") &&

            !StringUtilities.startsWithIgnoreCase(url, "https:"))
        {
          sendReferrer = false;
        }

        int size = requestHeaders.size();
        for (int i = 0; i < size;) {
          String header = requestHeaders.getPropertyKey(i);
          if (!sendReferrer && header.equals("referer")) {
            requestHeaders.removeProperty(i);
            --size;
            continue;
          }

          String value = requestHeaders.getPropertyValue(i++);
          if (value != null) {
            conn.setRequestProperty(header, value);
          }
        }
      }

      conn.setRequestProperty("Authorization", "Basic " + new String(encoded));    
      conn.setRequestProperty("TPSERVICE", tweetPhoto.m_ServiceName);
      conn.setRequestProperty("TPISOAUTH", tweetPhoto.m_isOAuth ? "True" : "False");
      conn.setRequestProperty("TPAPIKEY", tweetPhoto.m_APIKey);
      conn.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
      conn.setRequestMethod(requestMethod);
     
      System.out.println("URL: " + url);
      System.out.println("Request Method: " + requestMethod);
      System.out.println("Service Name: " + tweetPhoto.m_ServiceName);
      System.out.println("is OAuth?: " + (tweetPhoto.m_isOAuth ? "True" : "False"));
      System.out.println("TweetPhoto API Key: " + tweetPhoto.m_APIKey);
      System.out.println("Authorization: " + "Basic " + new String(encoded));

      if (requestMethod.equalsIgnoreCase("PUT") || requestMethod.equalsIgnoreCase("POST")) {
       
        if (uploadData) {
          conn.setRequestProperty("TPPOST",    "True");
          conn.setRequestProperty("TPMIMETYPE", tweetPhoto.m_mimeType);
          conn.setRequestProperty("TPUTF8",    "True");
          conn.setRequestProperty("TPMSG",     Base64Coder.encodeString(tweetPhoto.m_comment));
           
        if (tweetPhoto.m_latitude!=0.0 && tweetPhoto.m_longitude!=0.0) {
          conn.setRequestProperty("TPLAT", "" +tweetPhoto.m_latitude);
          conn.setRequestProperty("TPLONG", "" + tweetPhoto.m_longitude);
          }
           
        if (tweetPhoto.m_tags!=null && tweetPhoto.m_tags.length()>0) {
          conn.setRequestProperty("TPTAGS", Base64Coder.encodeString(tweetPhoto.m_tags));
          }
          }
       
        if (postData!=null) {
        conn.setRequestProperty(HttpProtocolConstants.HEADER_CONTENT_LENGTH, String.valueOf(postData.length));
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
          out = conn.openOutputStream();
          out.write(postData);
          out.flush();
          }
        }
    }
View Full Code Here

  // Get the social feed
  SocialFeed socialFeed(long userId, int ps, int ind, String sort) {
   
    String urlToRequest       = "http://tweetphotoapi.com/api/tpapi.svc/users/" + userId + "/feed?ps=" + ps + "&ind=" + ind + "&sort=" + sort + ";deviceside=true";
    try {
      HttpConnection httpConn = HttpUtils.makeHttpConnection(urlToRequest, new HttpHeaders(), null, getCoverageBasedConnectionType(), "GET", this, false);             
      m_httpStatus = httpConn.getResponseCode();
    
      if (m_httpStatus != 200) {
               System.out.println("Error: " + m_httpStatus);
      } else {
        InputStream content = httpConn.openInputStream();
        String xml = convertStreamToString(content);
        DomSocialFeedParser profileParser = new DomSocialFeedParser();
        profileParser.m_Xml = xml;
        SocialFeed feed = profileParser.parse();
        content.close();
View Full Code Here

  // Get the public feed
  SocialFeed publicFeed(int ps, int ind, String sort) {
   
    String urlToRequest       = "http://tweetphotoapi.com/api/tpapi.svc/socialfeed?ps=" + ps + "&ind=" + ind + "&sort=" + sort + ";deviceside=true";
    try {
      HttpConnection httpConn = HttpUtils.makeHttpConnection(urlToRequest, new HttpHeaders(), null, getCoverageBasedConnectionType(), "GET", this, false);             
      m_httpStatus = httpConn.getResponseCode();
    
      if (m_httpStatus != 200) {
               System.out.println("Error: " + m_httpStatus);
      } else {
        InputStream content = httpConn.openInputStream();
        String xml = convertStreamToString(content);
        DomSocialFeedParser profileParser = new DomSocialFeedParser();
        profileParser.m_Xml = xml;
        SocialFeed feed = profileParser.parse();
        content.close();
View Full Code Here

  // Get Next Photo
  Photo next(long photoId) {
   
    String urlToRequest       = "http://tweetphotoapi.com/api/tpapi.svc/photos/" + photoId + "/next" + ";deviceside=true";
    try {
      HttpConnection httpConn = HttpUtils.makeHttpConnection(urlToRequest, new HttpHeaders(), null, getCoverageBasedConnectionType(), "GET", this, false);             
      m_httpStatus = httpConn.getResponseCode();
    
      if (m_httpStatus != 200) {
               System.out.println("Error: " + m_httpStatus);
      } else {
        InputStream content = httpConn.openInputStream();
        String xml = convertStreamToString(content);
        DomPhotoParser photoParser = new DomPhotoParser();
        photoParser.m_Xml = xml;
        Photo photo = photoParser.parse();
        content.close();
View Full Code Here

TOP

Related Classes of javax.microedition.io.HttpConnection

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.