Package javax.microedition.io

Examples of javax.microedition.io.HttpConnection


        }
        return conn;
    }

    protected OutputStream getOutputStream(Object context) throws IOException {
        HttpConnection conn = (HttpConnection) context;
        conn.setRequestMethod(HttpConnection.POST);
        conn.setRequestProperty("Content-Type", "application/hprose");
        OutputStream ostream = conn.openOutputStream();
        return ostream;
    }
View Full Code Here


        ostream.flush();
        ostream.close();
    }

    protected InputStream getInputStream(Object context) throws IOException {
        HttpConnection conn = (HttpConnection) context;
        int i = 1;
        String key = null;
        Vector cookieList = new Vector();
        while((key=conn.getHeaderFieldKey(i)) != null) {
            if (key.toLowerCase().equals("set-cookie") ||
                key.toLowerCase().equals("set-cookie2")) {
                cookieList.addElement(conn.getHeaderField(i));
            }
            i++;
        }
        cookieManager.setCookie(cookieList, conn.getHost());
        InputStream istream = conn.openInputStream();
        return istream;
    }
View Full Code Here

    public void setKeepAliveTimeout(int keepAliveTimeout) {
        this.keepAliveTimeout = keepAliveTimeout;
    }

    protected Object getInvokeContext() throws IOException {
        HttpConnection conn = (HttpConnection)Connector.open(uri, Connector.READ_WRITE);
        if (keepAlive) {
            conn.setRequestProperty("Connection", "Keep-Alive");
            conn.setRequestProperty("Keep-Alive", Integer.toString(keepAliveTimeout));
        }
        else {
            conn.setRequestProperty("Connection", "Close");
        }
        conn.setRequestProperty("Cookie", cookieManager.getCookie(conn.getHost(),
                                                                  conn.getFile(),
                                                                  conn.getProtocol().equals("https")));
        for (Iterator iter = headers.entrySet().iterator(); iter.hasNext();) {
            Entry entry = (Entry) iter.next();
            conn.setRequestProperty((String) entry.getKey(), (String) entry.getValue());
        }
        return conn;
    }
View Full Code Here

        }
        return conn;
    }

    protected OutputStream getOutputStream(Object context) throws IOException {
        HttpConnection conn = (HttpConnection) context;
        conn.setRequestMethod(HttpConnection.POST);
        conn.setRequestProperty("Content-Type", "application/hprose");
        OutputStream ostream = conn.openOutputStream();
        return ostream;
    }
View Full Code Here

        ostream.flush();
        ostream.close();
    }

    protected InputStream getInputStream(Object context) throws IOException {
        HttpConnection conn = (HttpConnection) context;
        int i = 1;
        String key = null;
        ArrayList cookieList = new ArrayList();
        while((key=conn.getHeaderFieldKey(i)) != null) {
            if (key.equalsIgnoreCase("set-cookie") ||
                key.equalsIgnoreCase("set-cookie2")) {
                cookieList.add(conn.getHeaderField(i));
            }
            i++;
        }
        cookieManager.setCookie(cookieList, conn.getHost());
        InputStream istream = conn.openInputStream();
        return istream;
    }
View Full Code Here

*/
public class ServicioCorreo {

    public boolean enviarTweet(String usuario, String mensaje, String destino) throws IOException {
    boolean ret =false;
        HttpConnection httpConn = null;
        String url = "http://192.168.1.199:8080/TwitterMail/SMTP";
        InputStream is = null;
        OutputStream os = null;

        try {
            // Open an HTTP Connection object
            httpConn = (HttpConnection) Connector.open(url);
            // Setup HTTP Request to POST
            httpConn.setRequestMethod(HttpConnection.POST);

            httpConn.setRequestProperty("User-Agent",
                    "Profile/MIDP-1.0 Confirguration/CLDC-1.0");
            httpConn.setRequestProperty("Accept_Language", "en-US");
            //Content-Type is must to pass parameters in POST Request
            httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

         

            os = httpConn.openOutputStream();

            String params;
            params = "usuario=" + usuario + "&mensaje=" + mensaje + "&destino=" + destino;

            os.write(params.getBytes());

            /**Caution: os.flush() is controversial. It may create unexpected behavior
            on certain mobile devices. Try it out for your mobile device **/
            //os.flush();
            // Read Response from the Server
            StringBuffer sb = new StringBuffer();
            is = httpConn.openDataInputStream();
            int chr;
            while ((chr = is.read()) != -1) {
                sb.append((char) chr);
            }
            ret=sb.toString().indexOf("true")>-1;


        } finally {
            if (is != null) {
                is.close();
            }
            if (os != null) {
                os.close();
            }
            if (httpConn != null) {
                httpConn.close();
            }

        }

        return ret;
View Full Code Here

    }
    do {
      if (!ended) {
        InputStream is = null;
        try {
          HttpConnection httpconn = conn[connIdx];
          int rc = ((HttpConnection)httpconn).getResponseCode();
          if (rc == 404)
            return null;
             
          if (rc != 200)
          {
            is = httpconn.openInputStream();
            int code;
            while ((code = is.read()) != -1)
              System.out.print((char)code);
            throw new Exception("Exception response code: " + rc);
          }
          is = httpconn.openInputStream();
                 
          x.parse("", is);
   
        } catch (Exception e) {
     
View Full Code Here

      return;
    }
    OutputStream out = null;
    try {
      byte[] bout = unicodeToServer(mess);
      HttpConnection httpconn = (HttpConnection) Connector.open(httpburl);
      conn[connIdx] = httpconn;
     
      if (!httpburl.startsWith("https://")) {
       
        httpconn.setRequestProperty("User-Agent",
            "Profile/MIDP-2.0 Configuration/CLDC-1.1");
       
      }
      httpconn.setRequestMethod("POST");
      httpconn.setRequestProperty("Content-Length", ""
          + bout.length);
      out = httpconn.openOutputStream();
      if (out != null) {
        out.write(bout);
       
      }
      System.out.println("writtenToAir ["+connIdx+"]: " + mess);
View Full Code Here

    public String sendMessage(final String request) throws Exception,
                                                           IOException,
                                                           NetworkException {
        StaticDataHelper.log("*************************************************");
       
        HttpConnection   httpCon = null;     
        DataInputStream  inputStream  = null;
        DataOutputStream outputStream = null;
       
        int rc = 0;
        StringBuffer b = null;
        byte[] data    = null;    
       
        synchronized (this) {
            boolean signal = true;
               
            if ((RadioInfo.getState() != RadioInfo.STATE_ON) ||
                (RadioInfo.getSignalLevel() == RadioInfo.LEVEL_NO_COVERAGE)) {
                signal = false;
            }
       
            if (!signal) {
                throw new NetworkException();
            }
      
            try {
                StaticDataHelper sdh = new StaticDataHelper();
               
                byte[] dataToSend = request.getBytes();//the SyncML message to send in byte form
                   
                // ----------------------------------------------------------------------------------------------------------              
                String sessionId = SyncManagerImpl.session_id;
                StaticDataHelper.log("### Opening the connection nr. " + ++(SyncManagerImpl.c) + " in session " + sessionId);
               
                httpCon = (HttpConnection)Connector.open(requestURL + ";deviceside=true");//'true' direct TCP, 'false' proxy TCP (MDS)
               
                String url = httpCon.getURL();
                String jsessionid;
                String jsessionidParam = "jsessionid=";
                String devicesideParam = ";deviceside=";
                //StaticDataHelper.log("[DEBUG] URL: " + url);
                int startIndex = url.indexOf(jsessionidParam) + jsessionidParam.length();
                int endIndex = url.indexOf(devicesideParam);
                //StaticDataHelper.log("[DEBUG] startIndex: " + startIndex);
                //StaticDataHelper.log("[DEBUG] endIndex: " + endIndex);
                if (url.indexOf(jsessionidParam) != -&& endIndex != -1) {
                    jsessionid = url.substring(startIndex, endIndex);
                } else {
                    jsessionid = "jsessionid from server not yet available";
                }
                               
                StaticDataHelper.log("### Connection nr. " + SyncManagerImpl.c + " in session " + sessionId + " [" + jsessionid + "] opened");
                // --------------------------------------------------------------------------------------------------------------------------------------
               
                httpCon.setRequestMethod(HttpConnection.POST);
               
                httpCon.setRequestProperty (PROP_USER_AGENT,
                                            "BlackBerry/" + sdh.getOS());
                httpCon.setRequestProperty (PROP_CONTENT_LENGTH,
                                            String.valueOf(dataToSend.length));
                httpCon.setRequestProperty (PROP_CONTENT_TYPE,
                                            "application/vnd.syncml+xml");
           
                String locale = System.getProperty(PROP_MICROEDITION_LOCALE);

                if (locale != null) {
                    httpCon.setRequestProperty(PROP_CONTENT_LANGUAGE, locale);
                }
               
                outputStream = httpCon.openDataOutputStream();
                outputStream.write(dataToSend);
                outputStream.flush();
               
                inputStream = httpCon.openDataInputStream();
               
                int size = (int)httpCon.getLength();//in an HTTP connection it has to be the value of the
                                                    //'content-length' header field. When not known, -1
               
                b = new StringBuffer(size >= 0 ? (int)size : 4096);
                if (size != -1) {
                    // Read content-Length bytes, or until max is reached.
                    int ch = 0;
                    for (int i = 0; i < size; i++) {
                        if ((ch = inputStream.read()) != -1) {
                            b.append((char)ch);
                        }
                    }
                } else {
                    // Read til the connection is closed, or til max is reached.
                    // (Typical HTTP/1.0 script generated output)
                    int ch = 0;
                    size = 0;
                    while ((ch = inputStream.read()) != -1) {
                        b.append((char)ch);
                    }
                }
               
                data = b.toString().getBytes();   
            }//end try
            catch (Exception e) {
                StaticDataHelper.log(">>> Exception in SyncMLClientImpl.sendMessage(request): " + e.toString());
                throw e;
            }
            finally {
                if (inputStream != null) {
                    inputStream.close();
                    inputStream = null;
                }
                if (outputStream != null) {
                    outputStream.close();
                    outputStream = null;
                }
                if (httpCon != null) {
                    // ----------------------------------------------------------------------------------------------------
                    String url = httpCon.getURL();
                    String sessionId = SyncManagerImpl.session_id;
                    String jsessionid;
                    String jsessionidParam = "jsessionid=";
                    String devicesideParam = ";deviceside=";
                    //StaticDataHelper.log("[DEBUG] URL: " + url);
                    int startIndex = url.indexOf(jsessionidParam) + jsessionidParam.length();
                    int endIndex = url.indexOf(devicesideParam);
                    //StaticDataHelper.log("[DEBUG] startIndex: " + startIndex);
                    //StaticDataHelper.log("[DEBUG] endIndex: " + endIndex);
                    if (url.indexOf(jsessionidParam) != -1 && endIndex != -1) {
                        jsessionid = url.substring(startIndex, endIndex);
                    } else {
                        jsessionid = "jsessionid from server not yet available";
                    }
                   
                    StaticDataHelper.log("### Closing connection nr. " + SyncManagerImpl.c + " for session " + sessionId + " [" + jsessionid + "]");
                    httpCon.close();
                    StaticDataHelper.log("### Connection nr. " + SyncManagerImpl.c + " closed");
                    // ----------------------------------------------------------------------------------------------------
                   
                    httpCon = null;
                }
View Full Code Here

    m_comment   = comment;
    m_tags      = tags;
    m_mimeType  = mimeType;
   
    try {         
      HttpConnection httpConn = HttpUtils.makeHttpConnection(urlToRequest, new HttpHeaders(), photo, getCoverageBasedConnectionType(), "POST", this, true);
     
      m_httpStatus = httpConn.getResponseCode();
    
      if (m_httpStatus != 201) {
               System.out.println("Error: " + m_httpStatus);
      } else {
        InputStream content = httpConn.openInputStream();
        String xml = convertStreamToString(content);
        DomTweetPhotoResponseParser responseParser = new DomTweetPhotoResponseParser();
        responseParser.m_Xml = xml;
        TweetPhotoResponse response = (TweetPhotoResponse)responseParser.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.