Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
blob: afc7a3f3e0f7f9d5a934ff3eb04561e44beadef7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.log.impl;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Iterator;

import org.eclipse.wst.wsi.internal.core.WSIConstants;
import org.eclipse.wst.wsi.internal.core.log.MessageEntry;
import org.eclipse.wst.wsi.internal.core.log.MimePart;
import org.eclipse.wst.wsi.internal.core.log.MimeParts;
import org.eclipse.wst.wsi.internal.core.xml.XMLUtils;
import org.eclipse.wst.wsi.internal.core.xml.dom.ElementLocation;

/**
 * Message entry implementation.
 * 
 * @version 1.0.1
 * @author Peter Brittenham (peterbr@us.ibm.com)
 */
public class MessageEntryImpl implements MessageEntry
{
  /**
   * Log entry id.
   */
  protected String id;

  protected String conversationId;
  protected String type;
  protected String timestamp;
  protected String senderHostAndPort;
  protected String receiverHostAndPort;
  protected String message = "";
  protected String httpHeaders = "";
  protected int bom;
  protected String encoding = "";
  protected boolean isMimeContent = false;
  protected MimeParts mimeParts = new MimePartsImpl();

  protected ElementLocation elementLocation = null;

  /**
   * Empty constructor.
   */
  public MessageEntryImpl()
  {
  }
  
  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getId()
   */
  public String getId()
  {
    return this.id;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setId(String)
   */
  public void setId(String id)
  {
    this.id = id;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getConversationId()
   */
  public String getConversationId()
  {
    return this.conversationId;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setConversationId(String)
   */
  public void setConversationId(String conversationId)
  {
    this.conversationId = conversationId;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getTimestamp()
   */
  public String getTimestamp()
  {
    return this.timestamp;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setTimestamp(String)
   */
  public void setTimestamp(String timestamp)
  {
    this.timestamp = timestamp;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getType()
   */
  public String getType()
  {
    return this.type;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setType(String)
   */
  public void setType(String type)
  {
    this.type = type;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getSenderHostAndPort()
   */
  public String getSenderHostAndPort()
  {
    return this.senderHostAndPort;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setSenderHostAndPort(String)
   */
  public void setSenderHostAndPort(String senderHostAndPort)
  {
    this.senderHostAndPort = senderHostAndPort;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getReceiverHostAndPort()
   */
  public String getReceiverHostAndPort()
  {
    return this.receiverHostAndPort;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setReceiverHostAndPort(String)
   */
  public void setReceiverHostAndPort(String receiverHostAndPort)
  {
    this.receiverHostAndPort = receiverHostAndPort;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getMessage()
   */
  public String getMessage()
  {
  	if (!this.isMimeContent)
       return this.message;
  	else
  	{
  	   if (this.mimeParts.getRootPart() == null) return "";
  	   else return this.mimeParts.getRootPart().getContent();
  	}
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setMessage(String)
   */
  public void setMessage(String message)
  {
    this.message = message;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setEncoding(String)
   */
  public void setEncoding(String encoding)
  {
    this.encoding = encoding;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#getBOM()
   */
  public int getBOM()
  {
    return bom;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#setBOM(int)
   */
  public void setBOM(int bom)
  {
    this.bom = bom;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#getHTTPHeaders()
   */
  public String getHTTPHeaders()
  {
    return this.httpHeaders;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.LogEntry#setHTTPHeaders(String)
   */
  public void setHTTPHeaders(String httpHeaders)
  {
    this.httpHeaders = httpHeaders;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#getElementLocation()
   */
  public ElementLocation getElementLocation()
  {
    return this.elementLocation;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#setElementLocation(org.wsi.xml.dom.ElementLocation)
   */
  public void setElementLocation(ElementLocation elementLocation)
  {
    this.elementLocation = elementLocation;
  }

  /**
   * Get string representation of this object.
   */
  public String toString()
  {
    return toXMLString(WSIConstants.NS_NAME_WSI_LOG);
  }

  /* (non-Javadoc)
   * @see org.wsi.test.document.DocumentElement#toXMLString(String)
   */
  public String toXMLString(String namespaceName)
  {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);

    String nsName = namespaceName;
    if ((!nsName.equals("") && (!nsName.endsWith(":"))))
      nsName += ":";

    // ADD: Need to add way to indicate XML schema type for logEntry
    // Add log entry
    pw.print("<" + nsName + ELEM_NAME + " ");
    pw.print(
      "xsi:type=\"httpMessageEntry\" ");
    pw.print(WSIConstants.ATTR_ID_UC + "=\"" + id + "\" ");
    pw.print(
      WSIConstants.ATTR_CONVERSATION_ID + "=\"" + conversationId + "\" ");
    pw.print(WSIConstants.ATTR_TYPE + "=\"" + type + "\" ");
    pw.println(WSIConstants.ATTR_TIMESTAMP + "=\"" + timestamp + "\">");

    if (isMimeContent())
    {
        // Add message content with attachments element
        pw.print("<" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS);
        if (bom != 0)
          pw.print(" " + WSIConstants.ATTR_BOM + "=\"" + bom + "\"");
        pw.print(">");

        Collection partList = mimeParts.getParts();
        if (!partList.isEmpty())
        {
         	Iterator iMimeParts = partList.iterator();
        	while (iMimeParts.hasNext())
            {
        	  MimePart mimePart = (MimePart)iMimeParts.next();
         	  pw.print(mimePart.toXMLString(namespaceName));
            }
        }

        // Add end message element
        pw.println("</" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT_WITH_ATTACHMENTS + ">");
    }
    else
    {
      // Add message content element
      pw.print("<" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT);
      if (bom != 0)
        pw.print(" " + WSIConstants.ATTR_BOM + "=\"" + bom + "\"");
      pw.print(">");

      // Add encoded message
      pw.print(XMLUtils.xmlEscapedString(message));
      
      // Add end message element
      pw.println("</" + nsName + WSIConstants.ELEM_MESSAGE_CONTENT + ">");
    }

    // Add senderIPPort element
    pw.println(
      "<"
        + nsName
        + WSIConstants.ELEM_SENDER_HOST_AND_PORT
        + ">"
        + senderHostAndPort
        + "</"
        + nsName
        + WSIConstants.ELEM_SENDER_HOST_AND_PORT
        + ">");

    // Add receiverIP element
    pw.println(
      "<"
        + nsName
        + WSIConstants.ELEM_RECEIVER_HOST_AND_PORT
        + ">"
        + receiverHostAndPort
        + "</"
        + nsName
        + WSIConstants.ELEM_RECEIVER_HOST_AND_PORT
        + ">");

    // Add HTTPHeaders element
    pw.print("<" + nsName + WSIConstants.ELEM_HTTP_HEADERS + ">");

    // ADD: Does this string need to be XML encoded?
    // Add HTTP headers
    pw.print(XMLUtils.xmlEscapedString(httpHeaders));

    // End HTTPHeaders element
    pw.println("</" + nsName + WSIConstants.ELEM_HTTP_HEADERS + ">");

    // End log entry
    pw.println("</" + nsName + ELEM_NAME + ">");

    // Return string
    return sw.toString();
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#isMimeContent()
   */
  public boolean isMimeContent()
  {
    return isMimeContent;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#setMimeContent()
   */
  public void setMimeContent(boolean isMimeContent)
  {
    this.isMimeContent = isMimeContent;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#getMIMEParts()
   */
  public MimeParts getMimeParts()
  {
    return mimeParts;
  }

  /* (non-Javadoc)
   * @see org.wsi.test.log.MessageEntry#setMimeParts()
   */
  public void setMimeParts(MimeParts mimeParts)
  {
    this.mimeParts = mimeParts;
  }

}

Back to the top