@pararc uri URI, указывающий выбранный ресурс.

*/

public HttpResource (String uri)

{

super ();

this.uri = uri;

}

private String userAgentID ()

{

StringBuffer buf = new StringBuffer();

String config =

System.get Property("microedition.configuration");

String profile =

System.get Property("microedition.profiles");

buf.append("Configuration/"); buf.append(config); buf.append!" Profile/");

buf.append(profile); return buf. toStrir.g ();)

/**

Запускает данный объект. Соединяется с URI, посылает запрос, получает отклик и анализирует ответное сообщение.

*/

public void run()

System.out.println("Connection class name = " + conn.getClass(). getName ());

connect (); parse ();

System.out.println(gecResourceMetalnfo());

try conn.close();

}

catch (lOException ioe) System.out.println(ioe.getMessage());

ioe.printStackTrace();

}

}

/**

Соединяется с исходным сервером, который поддерживает URI.

Если произошло исключение во время соединения, этот метод Перехватит его и не выдаст указания на ошибку, за исключением Записи в стандартном результате диагностики.

*/

protected void connect!)

}

try

}

while (true)

{

// Соединение находится в состоянии «установка». conn = Connector.open(uri);

httpConn = (HttpConnection) conn;

httpConn.setRequestProperty("method", HttpConnection.HEAD);

httpConn.setRequestProperty("User-Agent", userAgentID());

// Соединение находится в состоянии «установлено». if (resourceRelocated())

{

uri = httpConn.getHeaderField("location");

// Соединение находится в состоянии «отключено» после

// вызова close().

conn.close();

}

else

}

breaX;

*/

if (serverError())

{

conn.close (); return;

}

// Соединение находится в состоянии «установлено», is = httpConn.openlnputStream ();

System.out.println("Input stream class name = " + is.getClassO.get Name ());

int responseCode = httpCcnn.getResponseCode ();

printResponseCode (responseCode); catch (lOExceptior. ioe)

{

contents.append(ioe.getMessage());

System.out.println(ioe.getMessage());

ioe.printStackTrace();

}

}

private boolean resourceRelocated()

{

boolean relocated = false; try

}

status = httpConn.getResponseCode();

if (status == HttpConnection.HTTP_MOVED_TEMP II

status == HttpConnection.HTTP_MOVED_PERM II

status == HttpConnection.HTTP_TEMP_REDIRECT)

{

relocated = true;

}

}

catch (lOException ioe)

}

System.out.println(ioe.getMessage());

ioe.printStackTrace();

}

return relocated;

}

private boolean serverError ()

{

boolean error = false;

try

{

status = httpConn.getResponseCode();

if ((status == HttpConnection.HTTP_NOT_IMPLEMENTED)

If (status == HttpConnection.HTTP_VERSION)

If (status == HttpConnection.HTTP_INTERNAL_ERROR)

If (status = = HttpConnection.HTTP_GATEWAY_TIMEOUT)

If (status == HttpConnection.HTTP_BAD_GATEWAY))

}

error = true; } }

catch (lOException ioe)

{

error = true;

System.out.println(ioe.getMessage());

ioe.printStackTrace();

}

return error;

}

private void parse()

(

if (httpConn == null) return;

String protocol = httpConn.getProtocol();

contents.append("Protocol: " t protocol + "\n");

String type = httpConn.getType();

content's. append ("Type: " + type + "\n");

String encoding = httpConn.getEncoding ();

contents.append("Encoding: " + encoding + "\n");

long length = httpConn.getLength ();

contents.append("Length: " + length + "\n");

String uri = httpConn.getURL();

contents.append("URL: " + uri + "\n");

String host = httpConn.getHost();

contents.append("Host: " + host + "\n");

String query = httpConn.getQuery();

contents.append("Query: " + query + "\n");


Логин
Пароль
Запомнить меня