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 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand V2");
00095 RequestCommand getCommand = (RequestCommand)getContainer.getElement();
00096 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand META DATA :"+getCommand.getMetaInformation());
00097 DataItem item = (DataItem) getContainer.nextMessage().getElement();
00098
00099
00100 try {
00101 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00102 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00103 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM META DATA :"+meta);
00104 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processGetCommand ITEM DATA :"+data);
00105 } catch (Throwable ex) {
00106 LogManager.traceError(0, ex);
00107 Status status = new Status(getCommand.getCmdId(), Status.STATUS_FAILED);
00108 ContainerMessage[] containerms = new ContainerMessage[1];
00109 containerms[0] = new ContainerMessage(status);
00110 return containerms;
00111 }
00112 Status status = new Status(getCommand.getCmdId(), Status.STATUS_OK);
00113 ContainerMessage[] containerms = new ContainerMessage[2];
00114 containerms[0] = new ContainerMessage(status);
00115 Result result = new Result(getCommand.getCmdId(), "testtarget", "testlistener");
00116 result.setMetaInformation("RESULT META INFO");
00117 ContainerMessage newContainer = new ContainerMessage(result);
00118 Item newItem = new DataItem(
00119 Element.ITEM
00120 , new String("RESULT ITEM META")
00121 , new String("RESULT ITEM CONTENT")
00122 , null
00123 , null
00124 );
00125 newContainer.add(newItem);
00126 containerms[1] = newContainer;
00127 return containerms;
00128 }
00129
00130
00131
00132
00133 protected Status processAddCommand(Credential cred, ContainerMessage addContainer) throws OpenMSPException {
00134 RequestCommand addCommand = (RequestCommand)addContainer.getElement();
00135 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand META DATA :"+addCommand.getMetaInformation());
00136 DataItem item = (DataItem) addContainer.nextMessage().getElement();
00137
00138
00139 try {
00140 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00141 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00142 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM META DATA :"+meta);
00143 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processAddCommand ITEM DATA :"+data);
00144 } catch (Throwable ex) {
00145 LogManager.traceError(0, ex);
00146 return new Status(addCommand.getCmdId(), Status.STATUS_FAILED);
00147 }
00148 return new Status(addCommand.getCmdId(), Status.STATUS_OK);
00149 }
00150
00151
00152
00153
00154 protected Status processDeleteCommand(Credential cred, ContainerMessage deleteContainer) throws OpenMSPException {
00155 RequestCommand deleteCommand = (RequestCommand)deleteContainer.getElement();
00156 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand META DATA :"+deleteCommand.getMetaInformation());
00157 DataItem item = (DataItem) deleteContainer.nextMessage().getElement();
00158
00159
00160 try {
00161 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00162 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processDeleteCommand ITEM META DATA :"+meta);
00163 } catch (Throwable ex) {
00164 LogManager.traceError(0, ex);
00165 return new Status(deleteCommand.getCmdId(), Status.STATUS_FAILED);
00166 }
00167 return new Status(deleteCommand.getCmdId(), Status.STATUS_OK);
00168 }
00169
00170
00171
00172
00173 protected Status processReplaceCommand(Credential cred, ContainerMessage replaceContainer) throws OpenMSPException {
00174 RequestCommand replaceCommand = (RequestCommand)replaceContainer.getElement();
00175 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand META DATA :"+replaceCommand.getMetaInformation());
00176 DataItem item = (DataItem) replaceContainer.nextMessage().getElement();
00177
00178
00179 try {
00180 String meta = new String(GeneralCoder.decodeBase64(item.getMetaInformation().getBytes()));
00181 String data = new String(GeneralCoder.decodeBase64(item.getData().getBytes()));
00182 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM META DATA :"+meta);
00183 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener processReplaceCommand ITEM DATA :"+data);
00184 } catch (Throwable ex) {
00185 LogManager.traceError(0, ex);
00186 return new Status(replaceCommand.getCmdId(), Status.STATUS_FAILED);
00187 }
00188 return new Status(replaceCommand.getCmdId(), Status.STATUS_OK);
00189 }
00190
00191
00192
00193
00194 protected void beginProcessOpenMSpCommand(Credential cred) throws OpenMSPException {
00195 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener beginProcessSyncContainerMessage.");
00196 }
00197
00198
00199
00200
00201 protected ContainerMessage[] endProcessOpenMSpCommand() throws OpenMSPException {
00202 LogManager.traceInfo(0, "TestOpenMSPSynchroTargetListener endProcessSyncContainerMessage.");
00203 ContainerMessage[] containerms = new ContainerMessage[1];
00204 Command getCommand = new Command(Element.GET, "testtarget", "testlistener");
00205 containerms[0] = new ContainerMessage(getCommand);
00206 return containerms;
00207 }
00208
00209 }