1 package com.indexdata.mkjsf.pazpar2.commands.sp;
\r
3 import org.apache.log4j.Logger;
\r
5 import com.indexdata.mkjsf.pazpar2.ClientCommandResponse;
\r
6 import com.indexdata.mkjsf.pazpar2.Pz2Service;
\r
7 import com.indexdata.mkjsf.pazpar2.commands.CommandParameter;
\r
8 import com.indexdata.mkjsf.pazpar2.commands.Pazpar2Command;
\r
9 import com.indexdata.mkjsf.pazpar2.data.ResponseParser;
\r
10 import com.indexdata.mkjsf.pazpar2.data.sp.SpResponseDataObject;
\r
12 public class AuthCommand extends Pazpar2Command implements ServiceProxyCommand {
\r
14 private static final long serialVersionUID = 5487611235664162578L;
\r
15 private static Logger logger = Logger.getLogger(AuthCommand.class);
\r
17 public AuthCommand() {
\r
21 public SpResponseDataObject run() {
\r
22 Pz2Service.get().resetSearchAndRecordCommands();
\r
23 Pz2Service.get().getPzresp().getSp().resetAuthAndBeyond(true);
\r
24 ClientCommandResponse response = (ClientCommandResponse) Pz2Service.get().getSearchClient().executeCommand(this);
\r
25 String renamedResponse = renameResponseElement(response.getResponseString(), "auth");
\r
26 response.setResponseToParse(renamedResponse);
\r
27 SpResponseDataObject responseObject = (SpResponseDataObject) ResponseParser.getParser().getDataObject(response);
\r
28 if (ResponseParser.docTypes.contains(responseObject.getType())) {
\r
29 Pz2Service.get().getPzresp().put(getCommandName(), responseObject);
\r
31 if (responseObject.unsupportedCommand()) {
\r
32 logger.error("auth command does not seem to be supported by this Service Proxy");
\r
34 return responseObject;
\r
37 private String renameResponseElement(String responseString, String newName) {
\r
38 responseString = responseString.replace("<response>", "<" + newName + ">");
\r
39 responseString = responseString.replace("</response>", "</" + newName + ">");
\r
40 return responseString;
\r
44 public void setAction (String action) {
\r
45 setParameterInState(new CommandParameter("action","=",action));
\r
48 public String getAction () {
\r
49 return getParameterValue("action");
\r
52 public void setUsername(String username) {
\r
53 setParameterInState(new CommandParameter("username","=",username));
\r
56 public String getUsername () {
\r
57 return getParameterValue("username");
\r
60 public void setPassword (String password) {
\r
61 setParameterInState(new CommandParameter("password","=",password));
\r
64 public String getPassword () {
\r
65 return getParameterValue("password");
\r
68 public AuthCommand copy () {
\r
69 AuthCommand newCommand = new AuthCommand();
\r
70 for (String parameterName : parameters.keySet()) {
\r
71 newCommand.setParameterInState(parameters.get(parameterName).copy());
\r
77 public ServiceProxyCommand getSp() {
\r
82 public boolean spOnly() {
\r