private static Logger log = Logger.getLogger(SelectTargetAction.class);
public FlowResult processSelectTarget(Context context, Request request, DSpaceSwordClient DSClient)
{
FlowResult result = new FlowResult();
result.setContinue(false);
// Get all our request parameters
String url = request.getParameter("url").trim();
String otherUrl = request.getParameter("otherUrl").trim();
String username = request.getParameter("username").trim();
String password = request.getParameter("password").trim();
String onBehalfOf = request.getParameter("onBehalfOf").trim();
// If we have errors, the form needs to be resubmitted to fix those problems
String chosenUrl = "";
if (!StringUtils.isEmpty(otherUrl))
{
// If otherUrl has been entered then it will take precedence.
try
{
new URL(otherUrl);
chosenUrl = otherUrl;
}
catch (MalformedURLException e)
{
result.addError("otherUrl");
}
}
else
{
if (!StringUtils.isEmpty(url))
{
chosenUrl = url;
}
else
{
result.addError("url");
}
}
if (StringUtils.isEmpty(username))
{
result.addError("username");
}
if (StringUtils.isEmpty(password))
{
result.addError("password");
}
// No errors, the input parameters look healthy.
if (result.getErrors() == null)
{
try
{
DSClient.setRemoteServer(chosenUrl);
DSClient.setCredentials(username, password, onBehalfOf);
ServiceDocument serviceDoc = DSClient.getServiceDocument();
result.setParameter("serviceDoc", serviceDoc);
result.setContinue(true);
result.setOutcome(true);
}
catch (MalformedURLException e)
{
log.error("Malformed URL : " + chosenUrl);
result.setOutcome(false);
result.setMessage(T_url_error);
}
catch (HttpException e)
{
log.error("HttpException encountered", e);
result.setOutcome(false);
result.setMessage(T_serviceDoc_error.parameterize(e.getMessage()));
}
catch (SWORDClientException e)
{
log.error("SwordClientException : " + e.getMessage(), e);
result.setOutcome(false);
result.setMessage(T_serviceDoc_error.parameterize(e.getMessage()));
}
}
return result;