ページの先頭行へ戻る
Interstage Mobile Application Server V1.1.0 アプリケーション開発ガイド
FUJITSU Software

9.4.4 例

web.xmlの定義例

<web-app version="3.0" xmlns=http://java.sun.com/xml/ns/javaee
                       xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
                       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
・・・
  <error-page>
    <exception-type>com.fujitsu.imaps.auth.IMAPSTimeoutException</exception-type>
    <location>/timeout/timeout.jsp</location>
  </error-page>
</web-app>

タイムアウトを通知するサーバアプリケーションのコンテンツの実装例(timeout/timeout.jsp)

<%@ page contentType="text/html;charset=UTF-8" isErrorPage="true" %>
<%
  response.setHeader("X-IMAPS-TIMEOUT", "true");
  response.setStatus(200);
%>
<html>
<head>
    <title>401 Unauthorized</title>
</head>
<body>
    <b>401 Unauthorized</b><br>
</body>
</html>

Androidでの実装例

private void connection() {
	new AsyncConnectTask(接続URL).execute();
}

class AsyncConnectTask extends AsyncTask<String, String, String> {
	LoginManager mLoginManager = null;
	String mURL = null;
	・・・・

	public AsyncConnectTask(String url) {
		mLoginManager = new LoginManager(getApplicationContext());
		mURL = url;
		・・・・
	}

	protected String doInBackground(String... params) {
		try{
			URL url = new URL(mURL);
			DefaultHttpClient httpClient = new DefaultHttpClient();
			HttpPost httpPost = new HttpPost(url);
			・・・
			mLoginManager.setRequestAuth(httpPost, httpClient);
			HttpResponse response = httpClient.execute(httpPost);
			mLoginManager.checkServerTimeout(response);
			・・・
			mLoginManager.saveResponseAuth(url, httpClient);
			・・・
		} catch (IMAPSAuthTimeOutException e) {
			// ログアウト処理の実装を行うことを推奨します。
		} catch (例外キャッチ) {
			// キャッチした例外の内容に応じて、例外処理を実装します。
		}
	}
}

iOSでの実装例

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
	IMALoginManager *loginManager = [[IMALoginManager alloc] init];
	NSError *anError = nil;
	BOOL result = [loginManager checkServerTimeout:response error:&anError];
	if(result == NO) {
		// それぞれのエラーの実装.
	}
}

JavaScriptでの実装例

function getContent(url) {
    var xmlHttp;
    xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET", url, false);
    imaps.auth.setRequestHeader(resultHandler, errorHandler, xmlHttp);
}
function resultHandler(result) {
    xmlHttp.send(null);
    if(imaps.auth.checkResponseHeader(xmlHttp)) {
        alert("SERVER TIME OUT");
    } else {
        alert(xmlHttp.responseText);
    }
}
function errorHandler(error) {
    alert("Error: \r\n"+error );
}