if (logger.isLoggable(Level.FINEST)) {
logger.entering(sourceClass, "createJsonForEndpoint", new Object[] { request, endpoint,
endpointAlias, endpointName });
}
JsonObject jsonEndpoint = new JsonJavaObject();
// use the base url from the endpoint
if (isValid(request, endpoint)) {
// set the endpoint api version
String apiVersion = endpoint.getApiVersion();
if (StringUtil.isNotEmpty(apiVersion)) {
jsonEndpoint.putJsonProperty(PROP_API_VERSION, apiVersion);
}
jsonEndpoint.putJsonProperty(PROP_ENDPOINT_ALIAS, endpointAlias);
// set the endpoint url
jsonEndpoint.putJsonProperty(PROP_BASE_URL, endpoint.getUrl());
try {
jsonEndpoint.putJsonProperty(IS_AUTHENTICATED, endpoint.isAuthenticated());
} catch (ClientServicesException e) {
jsonEndpoint.putJsonProperty(IS_AUTHENTICATED, false);
}
jsonEndpoint.putJsonProperty(PROP_SERVICE_MAPPINGS, endpoint.getServiceMappings());
// configure endpoint to use proxy
if (endpoint.isUseProxy()) {
JsonReference proxyRef = createProxyRef(request, endpoint, endpointName);
if (proxyRef != null) {
jsonEndpoint.putJsonProperty(PROP_PROXY, proxyRef);
String moduleName = getProxy(request, endpoint, endpointName).getModuleName();
jsonEndpoint.putJsonProperty(PROP_MODULE_PROXY, moduleName);
}
String proxyPath = endpoint.getProxyPath(endpointName);
if (!StringUtil.isEmpty(proxyPath)) {
jsonEndpoint.putJsonProperty(PROP_PROXY_PATH, proxyPath);
}
}
// configure endpoint to use authenticator
JsonReference authenticatorRef = createAuthenticatorRef(request, endpoint, endpointName);
if (authenticatorRef != null) {
jsonEndpoint.putJsonProperty(PROP_AUTHENTICATOR, authenticatorRef);
String moduleName = endpoint.getAuthenticator(endpointName, request.getToolkitJsUrl()).getModuleName();
jsonEndpoint.putJsonProperty(PROP_MODULE_AUTHENTICATOR, moduleName);
}
// configure the transport
JsonReference transportRef = createTransportRef(request, endpoint, endpointName);
if (transportRef != null) {
jsonEndpoint.putJsonProperty(PROP_TRANSPORT, transportRef);
String moduleName = getTransport(request, endpoint, endpointName).getModuleName();
jsonEndpoint.putJsonProperty(PROP_MODULE_TRANSPORT, moduleName);
}
// configure the authentication
jsonEndpoint.putJsonProperty(PROP_AUTH_TYPE, AuthUtil.INSTANCE.getAuthValue(endpoint));
if (endpoint.getLoginPage() != null) {
jsonEndpoint.putJsonProperty(PROP_LOGIN_PAGE, endpoint.getLoginPage());
}
if (endpoint.getDialogLoginPage() != null) {
jsonEndpoint.putJsonProperty(PROP_LOGIN_DIALOG_PAGE, endpoint.getDialogLoginPage());
}
if (endpoint.getLoginUi() != null) {
jsonEndpoint.putJsonProperty(PROP_LOGIN_UI, endpoint.getLoginUi());
}
if (endpoint.getAutoAuthenticate() != null) {
jsonEndpoint.putJsonProperty(PROP_AUTO_AUTHENTICATE, endpoint.getAutoAuthenticate());
}
if (endpoint.getPlatform() != null) {
jsonEndpoint.putJsonProperty(PROP_PLATFORM, endpoint.getPlatform());
}
jsonEndpoint.putJsonProperty(PROP_AUTHENTICATION_ERROR_CODE,
endpoint.getAuthenticationErrorCode());
// configure client properties
Map<String, Object> params = endpoint.getClientParams();
Iterator<String> keys = params.keySet().iterator();
while(keys.hasNext()) {
String key = keys.next();
Object value = params.get(key);
jsonEndpoint.putJsonProperty(key, value);
}
} else {
// set the endpoint url
jsonEndpoint.putJsonProperty(PROP_INVALID, "true");
// configure a error transport
String message = getInvalidEndpointMessage(request, endpoint, endpointName);
jsonEndpoint.putJsonProperty(PROP_TRANSPORT, new JsonReference("new ErrorTransport('"
+ endpointName + "','" + message + "')"));
}
if (logger.isLoggable(Level.FINEST)) {
logger.exiting(sourceClass, "createJsonForEndpoint", jsonEndpoint);