Skip to content
This repository has been archived by the owner on Jan 25, 2022. It is now read-only.

Commit

Permalink
[88198736] - Added server name to access token error messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nieraj Singh committed Feb 12, 2015
1 parent 9cbf29c commit 09f58a3
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
Expand Up @@ -185,6 +185,8 @@ public class Messages extends NLS {

public static String CONSOLE_STOPPING_APPLICATION;

public static String LocalServerRequest_SERVER_LABEL;

public static String ManifestParser_NO_APP_NAME;

public static String REFRESHING_MODULES;
Expand Down
Expand Up @@ -65,10 +65,10 @@ WARNING_SELF_SIGNED_PROMPT_USER=Failed to connect to {0}, probably because the s
TITLE_SELF_SIGNED_PROMPT_USER=Failed to connect
TunnelServiceCommandStore_ERROR_SERIALIZE_JAVAMAP=Error while serializing Java Map from JSON response:
TunnelServiceCommandStore_ERROR_VALUE_CANNOT_SERILIZE=Value of type {0} can not be serialized to JSON.
ClientRequest_RETRY_REQUEST=Initial client request - {0} - failed due to possible access error. Attempting login again and retrying the request. Please wait while the operation completes.
ClientRequest_SECOND_ATTEMPT_FAILED=Client request failure - {0}. Second attempt to perform operation failed after trying to refresh access token. Please check your connection and retry the operation again. Cause: {1}
ClientRequest_TOKEN_EXPIRED=Obtained expired access token while attempting to refresh access token.
ClientRequest_NO_TOKEN=Null access token when attempting to refresh access token.
ClientRequest_RETRY_REQUEST=Initial Cloud request - {0} - failed due to possible connection error. Retrying the request. Please wait while the operation completes.
ClientRequest_SECOND_ATTEMPT_FAILED=Cloud request failure - {0}. Second operation attempt failed after trying to reconnect. Please check your connection and retry the operation again. Cause: {1}
ClientRequest_TOKEN_EXPIRED=Obtained expired access token while attempting to reconnect.
ClientRequest_NO_TOKEN=Obtained null access token while attempting to reconnect.
CloudFoundryApplicationModule_STATE_DEPLOYABLE=Deployable
CloudFoundryApplicationModule_STATE_DEPLOYED=Deployed
CloudFoundryApplicationModule_STATE_LAUNCHED=LAUNCHED
Expand Down Expand Up @@ -102,6 +102,7 @@ CONSOLE_PREPARING_APP=Checking application - {0}
CONSOLE_STILL_WAITING_FOR_APPLICATION_TO_START=Still waiting for application to start...
CONSOLE_WAITING_FOR_APPLICATION_TO_START=Waiting for application to start...
CONSOLE_STOPPING_APPLICATION=Stopping application - {0}
LocalServerRequest_SERVER_LABEL=[server: {0}]
ManifestParser_NO_APP_NAME=No application name read from the manifest file.
REFRESHING_MODULES=Initializing and refreshing modules for - {0}
RefreshModulesHandler_REFRESH_FAILURE=Refresh failure
Expand Down
Expand Up @@ -65,11 +65,11 @@ public String getRequestLabel() {
*/
public T run(IProgressMonitor monitor) throws CoreException {

SubMonitor subProgress = SubMonitor.convert(monitor, label, 100);
SubMonitor subProgress = SubMonitor.convert(monitor, getRequestLabel(), 100);

CloudFoundryOperations client = getClient(subProgress);
if (client == null) {
throw CloudErrorUtil.toCoreException(NLS.bind(Messages.ERROR_NO_CLIENT, label));
throw CloudErrorUtil.toCoreException(NLS.bind(Messages.ERROR_NO_CLIENT, getRequestLabel()));
}

HttpTracer.getCurrent().trace(client);
Expand Down
Expand Up @@ -75,7 +75,8 @@ protected T runAndWait(CloudFoundryOperations client, SubMonitor subProgress) th
String accessErrorMessage = null;

if (handler.shouldAttemptClientLogin(ce)) {
CloudFoundryPlugin.logWarning(NLS.bind(Messages.ClientRequest_RETRY_REQUEST, getRequestLabel()));
CloudFoundryPlugin.logWarning(NLS.bind(Messages.ClientRequest_RETRY_REQUEST,
getTokenAccessErrorLabel()));
accessError = ce;

int attempts = 3;
Expand All @@ -101,12 +102,20 @@ else if (token.isExpired()) {
if (accessErrorMessage == null) {
accessErrorMessage = accessError.getMessage();
}
accessErrorMessage = NLS.bind(Messages.ClientRequest_SECOND_ATTEMPT_FAILED, getRequestLabel(),
accessErrorMessage);
accessErrorMessage = NLS.bind(Messages.ClientRequest_SECOND_ATTEMPT_FAILED,
getTokenAccessErrorLabel(), accessErrorMessage);

throw CloudErrorUtil.toCoreException(accessErrorMessage, cause);
}
throw ce;
}
}

/**
* Return a label used to indicate the request type and other additional
* information, like server name.
*/
protected String getTokenAccessErrorLabel() {
return getRequestLabel();
}
}
Expand Up @@ -23,9 +23,11 @@
import org.cloudfoundry.ide.eclipse.server.core.internal.CloudErrorUtil;
import org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryPlugin;
import org.cloudfoundry.ide.eclipse.server.core.internal.CloudFoundryServer;
import org.cloudfoundry.ide.eclipse.server.core.internal.Messages;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.osgi.util.NLS;
import org.eclipse.wst.server.core.IServer;
import org.eclipse.wst.server.core.internal.Server;

Expand All @@ -41,10 +43,39 @@
@SuppressWarnings("restriction")
public abstract class LocalServerRequest<T> extends ClientRequest<T> {

private String accessTokenErrorLabel;

public LocalServerRequest(String label) {
super(label);
}

@Override
protected String getTokenAccessErrorLabel() {
if (accessTokenErrorLabel == null) {
String label = super.getRequestLabel();
String serverName = null;
try {
CloudFoundryServer cloudServer = getCloudServer();
if (cloudServer != null && cloudServer.getServer() != null) {
serverName = NLS.bind(Messages.LocalServerRequest_SERVER_LABEL, cloudServer.getServer().getId());
}
}
catch (Throwable e) {
// Don't log as the label may be called multiple times. If the
// server failed to resolve, the request itself
// will fail and will log the error accordingly
}
if (serverName != null) {
accessTokenErrorLabel = label + " - " + serverName; //$NON-NLS-1$
}
else {
accessTokenErrorLabel = label;
}

}
return accessTokenErrorLabel;
}

@Override
public T runAndWait(CloudFoundryOperations client, SubMonitor monitor) throws CoreException {
CloudFoundryServer cloudServer = getCloudServer();
Expand Down

0 comments on commit 09f58a3

Please sign in to comment.