KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > server > engine > RespURISynclet


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19
20 package sync4j.server.engine;
21
22 import java.util.logging.Logger JavaDoc;
23 import java.util.logging.Level JavaDoc;
24
25 import sync4j.framework.core.SyncML;
26 import sync4j.framework.core.Sync4jException;
27 import sync4j.framework.config.Configuration;
28 import sync4j.framework.config.ConfigurationConstants;
29 import sync4j.framework.logging.Sync4jLogger;
30 import sync4j.framework.logging.Sync4jLoggerName;
31
32 import sync4j.framework.engine.pipeline.OutputMessageProcessor;
33 import sync4j.framework.engine.pipeline.MessageProcessingContext;
34
35 /**
36  * This class implements a synclet that adds the RespURI tag to the message.
37  *
38  * @author Stefano Fornari @ Funambol.com
39  */

40 public class RespURISynclet
41 implements OutputMessageProcessor {
42     // --------------------------------------------------------------- Constants
43

44     public static final String JavaDoc PARAM_SESSION_ID = "sid";
45
46     // ------------------------------------------------------------ Private data
47

48     private static final Logger JavaDoc log = Sync4jLogger.getLogger(Sync4jLoggerName.ENGINE);
49
50     // ------------------------------------------------------------ Constructors
51

52
53     // -------------------------------------------------- OutputMessageProcessor
54

55     public void postProcessMessage(MessageProcessingContext processingContext,
56                                    SyncML message )
57     throws Sync4jException {
58         Configuration config = Configuration.getConfiguration();
59
60         String JavaDoc sessionId =
61             (String JavaDoc)processingContext.getProperty(processingContext.PROPERTY_SESSIONID);
62
63         if (sessionId == null) {
64             if (log.isLoggable(Level.INFO)) {
65                 log.info(processingContext.PROPERTY_SESSIONID + " is null! Synclet ignored");
66             }
67             return;
68         }
69
70         String JavaDoc serverUri =
71             config.getStringValue(ConfigurationConstants.CFG_SERVER_URI);
72
73         message.getSyncHdr().setRespURI(
74             serverUri +
75             '?' +
76             PARAM_SESSION_ID +
77             '=' +
78             sessionId
79         );
80     }
81 }
Popular Tags