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 void processSyncItem(Credential cred, Item item) throws OpenMSPException {
00154 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processSyncItem ITEM :"+item.getCmdId());
00155 }
00156
00157
00158
00159
00160 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00161 RequestCommand deleteCommand = (RequestCommand)deleteContainer.getElement();
00162 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand META DATA :"+deleteCommand.getMetaInformation());
00163 DataItem item = (DataItem) deleteContainer.nextMessage().getElement();
00164
00165
00166 try {
00167 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00168 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand ITEM META DATA :"+meta);
00169 } catch (Throwable ex) {
00170 LogManager.traceError(0, ex);
00171 return new Status(deleteCommand.getCmdId(), Status.STATUS_FAILED);
00172 }
00173 return new Status(deleteCommand.getCmdId(), Status.STATUS_OK);
00174 }
00175
00176
00177
00178
00179 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00180 RequestCommand replaceCommand = (RequestCommand)replaceContainer.getElement();
00181 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand META DATA :"+replaceCommand.getMetaInformation());
00182 DataItem item = (DataItem) replaceContainer.nextMessage().getElement();
00183
00184
00185 try {
00186 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00187 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00188 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM META DATA :"+meta);
00189 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM DATA :"+data);
00190 } catch (Throwable ex) {
00191 LogManager.traceError(0, ex);
00192 return new Status(replaceCommand.getCmdId(), Status.STATUS_FAILED);
00193 }
00194 return new Status(replaceCommand.getCmdId(), Status.STATUS_OK);
00195 }
00196
00197
00198
00199
00200 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00201 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener beginProcessSyncContainerMessage.");
00202 }
00203
00204
00205
00206
00207 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00208 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener endProcessSyncContainerMessage.");
00209 ContainerMessage[] containerms = new ContainerMessage[1];
00210 Command getCommand = new Command(Element.GET, "testtarget", "testlistener");
00211 containerms[0] = new ContainerMessage(getCommand);
00212 return null;
00213 }
00214
00215 }