00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 package org.openmobileis.synchro.openmsp.protocol.test;
00026
00027 import org.openmobileis.common.util.codec.GeneralCoder;
00028 import org.openmobileis.common.util.log.LogManager;
00029 import org.openmobileis.synchro.openmsp.OpenMSPException;
00030 import org.openmobileis.synchro.openmsp.protocol.Command;
00031 import org.openmobileis.synchro.openmsp.protocol.ContainerMessage;
00032 import org.openmobileis.synchro.openmsp.protocol.DataItem;
00033 import org.openmobileis.synchro.openmsp.protocol.Element;
00034 import org.openmobileis.synchro.openmsp.protocol.Item;
00035 import org.openmobileis.synchro.openmsp.protocol.RequestCommand;
00036 import org.openmobileis.synchro.openmsp.protocol.Result;
00037 import org.openmobileis.synchro.openmsp.protocol.Status;
00038 import org.openmobileis.synchro.openmsp.server.synctarget.DefaultOpenMSPSynchroTargetListener;
00039 import org.openmobileis.synchro.security.auth.Credential;
00040
00048 public final class TestOpenMSPSynchroTargetListener extends DefaultOpenMSPSynchroTargetListener {
00049
00053 public TestOpenMSPSynchroTargetListener() {
00054 super();
00055 }
00056
00057 public String getTargetName() {
00058 return "testtarget";
00059 }
00060
00061
00062
00063
00064 protected ContainerMessage processMapCommand(Credential cred, ContainerMessage mapContainer) {
00065 return null;
00066 }
00067
00068
00069
00070
00071 protected void notifySyncAction(long sessionId,Credential cred, Command syncCommand) throws OpenMSPException {
00072 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener notifySyncAction META DATA :"+syncCommand.getMetaInformation());
00073 }
00074
00075
00076
00077
00078 protected void processResultCommand(Credential cred, Result resultCommande) throws OpenMSPException {
00079
00080
00081 }
00082
00083
00084
00085
00086 protected void processStatusCommand(Credential cred, Status statusCommande) throws OpenMSPException {
00087 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processStatusCommand status :"+statusCommande.getStatus()+" commandRef:"+statusCommande.getCmdRef());
00088 }
00089
00090
00091
00092
00093 protected ContainerMessage[] processGetCommand(Credential cred, ContainerMessage getContainer) throws OpenMSPException {
00094 RequestCommand getCommand = (RequestCommand)getContainer.getElement();
00095 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand META DATA :"+getCommand.getMetaInformation());
00096 DataItem item = (DataItem) getContainer.nextMessage().getElement();
00097
00098
00099 try {
00100 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00101 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00102 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM META DATA :"+meta);
00103 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM DATA :"+data);
00104 } catch (Throwable ex) {
00105 LogManager.traceError(0, ex);
00106 Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00107 ContainerMessage[] containerms = new ContainerMessage[1];
00108 containerms[0] = new ContainerMessage(status);
00109 return containerms;
00110 }
00111 Status status = new Status(getCommand.getCmdId(), Status.STATUS_OK);
00112 ContainerMessage[] containerms = new ContainerMessage[2];
00113 containerms[0] = new ContainerMessage(status);
00114 Result result = new Result(getCommand.getCmdId(), "testtarget", "testlistener");
00115 result.setMetaInformation("RESULT META INFO");
00116 ContainerMessage newContainer = new ContainerMessage(result);
00117 Item newItem = new DataItem(
00118 Element.ITEM
00119 , new String("RESULT ITEM META")
00120 , new String("RESULT ITEM CONTENT")
00121 , null
00122 , null
00123 );
00124 newContainer.add(newItem);
00125 containerms[1] = newContainer;
00126 return containerms;
00127 }
00128
00129
00130
00131
00132 protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00133 RequestCommand addCommand = (RequestCommand)addContainer.getElement();
00134 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand META DATA :"+addCommand.getMetaInformation());
00135 DataItem item = (DataItem) addContainer.nextMessage().getElement();
00136
00137
00138 try {
00139 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00140 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00141 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM META DATA :"+meta);
00142 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM DATA :"+data);
00143 } catch (Throwable ex) {
00144 LogManager.traceError(0, ex);
00145 return new Status(addCommand.getCmdId(), Status.STATUS_FAILED);
00146 }
00147 return new Status(addCommand.getCmdId(), Status.STATUS_OK);
00148 }
00149
00150
00151
00152
00153 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00154 RequestCommand deleteCommand = (RequestCommand)deleteContainer.getElement();
00155 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand META DATA :"+deleteCommand.getMetaInformation());
00156 DataItem item = (DataItem) deleteContainer.nextMessage().getElement();
00157
00158
00159 try {
00160 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00161 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand ITEM META DATA :"+meta);
00162 } catch (Throwable ex) {
00163 LogManager.traceError(0, ex);
00164 return new Status(deleteCommand.getCmdId(), Status.STATUS_FAILED);
00165 }
00166 return new Status(deleteCommand.getCmdId(), Status.STATUS_OK);
00167 }
00168
00169
00170
00171
00172 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00173 RequestCommand replaceCommand = (RequestCommand)replaceContainer.getElement();
00174 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand META DATA :"+replaceCommand.getMetaInformation());
00175 DataItem item = (DataItem) replaceContainer.nextMessage().getElement();
00176
00177
00178 try {
00179 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00180 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00181 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM META DATA :"+meta);
00182 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM DATA :"+data);
00183 } catch (Throwable ex) {
00184 LogManager.traceError(0, ex);
00185 return new Status(replaceCommand.getCmdId(), Status.STATUS_FAILED);
00186 }
00187 return new Status(replaceCommand.getCmdId(), Status.STATUS_OK);
00188 }
00189
00190
00191
00192
00193 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00194 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener beginProcessSyncContainerMessage.");
00195 }
00196
00197
00198
00199
00200 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00201 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener endProcessSyncContainerMessage.");
00202 ContainerMessage[] containerms = new ContainerMessage[1];
00203 Command getCommand = new Command(Element.GET, "testtarget", "testlistener");
00204 containerms[0] = new ContainerMessage(getCommand);
00205 return containerms;
00206 }
00207
00208 }