/*
Set the contents of the ReplyDiscriminator field in the message header.

Javadoc description supplied by SIBusMessage interface.
965971
@Override
    public final void setReplyDiscriminator(String value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setReplyDiscriminator", value);
        if (value != null) {
            if (isValidDiscriminator(value)) {
                getApi().setField(JsApiAccess.REPLYDISCRIMINATOR_VALUE, value);
            }
            else {
                IllegalArgumentException e = new IllegalArgumentException(value);
                if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
                    SibTr.exit(this, tc, "setReplyDiscriminator", e);
                throw e;
            }
        }
        else {
            getApi().setChoiceField(JsApiAccess.REPLYDISCRIMINATOR, JsApiAccess.IS_REPLYDISCRIMINATOR_UNSET);
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setReplyDiscriminator");
    }
68790
public void setResponse(Map<String, Object> headers) {
        int size = RES_200.length;
        byte[] len = stringToBytes(String.valueOf(0));
        size += CONTENT_LENGTH.length;
        size += len.length;
        size += TextCommandConstants.RETURN.length;
        if (headers != null) {
            for (Map.Entry<String, Object> entry : headers.entrySet()) {
                size += stringToBytes(HEADER_CUSTOM_PREFIX + entry.getKey() + ": ").length;
                size += stringToBytes(entry.getValue().toString()).length;
                size += TextCommandConstants.RETURN.length;
            }
        }
        size += TextCommandConstants.RETURN.length;
        this.response = ByteBuffer.allocate(size);
        response.put(RES_200);
        response.put(CONTENT_LENGTH);
        response.put(len);
        response.put(TextCommandConstants.RETURN);
        if (headers != null) {
            for (Map.Entry<String, Object> entry : headers.entrySet()) {
                response.put(stringToBytes(HEADER_CUSTOM_PREFIX + entry.getKey() + ": "));
                response.put(stringToBytes(entry.getValue().toString()));
                response.put(TextCommandConstants.RETURN);
            }
        }
        response.put(TextCommandConstants.RETURN);
        response.flip();
    }
814385
@SuppressWarnings({"unchecked", "rawtypes"})
  public void setField(final FieldDescriptorType descriptor,
                       Object value) {
    if (descriptor.isRepeated()) {
      if (!(value instanceof List)) {
        throw new IllegalArgumentException(
          "Wrong object type used with protocol message reflection.");
      }

      // Wrap the contents in a new list so that the caller cannot change
      // the list's contents after setting it.
      final List newList = new ArrayList();
      newList.addAll((List) value);
      for (final Object element : newList) {
        verifyType(descriptor.getLiteType(), element);
      }
      value = newList;
    } else {
      verifyType(descriptor.getLiteType(), value);
    }

    if (value instanceof LazyField) {
      hasLazyField = true;
    }
    fields.put(descriptor, value);
  }
366935
public void setRawResponseContent(String rawResponseContent) {
        this.rawResponse = rawResponseContent == null ? null : rawResponseContent.getBytes
                (StringUtils.UTF8);
    }
1112014
public final void setGuaranteedTargetDestinationDefinitionUUID(SIBUuid12 value) {
    if (value != null)
      jmo.setField(ControlAccess.TARGETDESTDEFUUID, value.toByteArray());
    else
      jmo.setField(ControlAccess.TARGETDESTDEFUUID, null);
  }
1193354
protected void doResponseHeaders(final HttpServletResponse response, final String mimeType) {
        if (mimeType != null) {
            response.setContentType(mimeType);
        }
    }
608773
public void setUtf8Content(final Object content) throws MessagingException
	{
		final String type = EmailConstants.MIMETYPE_TEXT_PLAIN + EmailConstants.CHARSET_PREFIX
			+ EmailConstants.CHARSET_UTF8;
		setContent(content, type);
	}
328670
public ResponseMessageBuilder headersWithDescription(Map<String, Header> headers) {
    this.headers.putAll(nullToEmptyMap(headers));
    return this;
  }
105947
private void setResponse(int statusCode, String statusMessage, String responseBody, Map<String, List<String>> responseHeaders)
    {
        mStatusCode      = statusCode;
        mStatusMessage   = statusMessage;
        mResponseBody    = responseBody;
        mResponseHeaders = responseHeaders;
    }
251884
void setRequestedProxySubscriptionsResponded()
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "setRequestedProxySubscriptionsResponded");

    synchronized (this)
    {
      iRequestSent = false;

      if (!iAlarmCancelled)
        iAlarm.cancel();

      iAlarmCancelled = true;
    }

    String meName = JsAdminUtils.getMENameByUuidForMessage(iMEUuid.toString());

    if (meName == null)
      meName = iMEUuid.toString();

    SibTr.push(iProxyHandler.getMessageProcessor().getMessagingEngine());
    SibTr.info(tc, "NEIGHBOUR_REPLY_RECIEVED_INFO_CWSIP0382",
               new Object[]{meName});
    SibTr.pop();

    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "setRequestedProxySubscriptionsResponded");
  }
112113
public void setReplyTo(List<String> replyTos) {
        addField(ConfigureNodeFields.replyto, FormField.Type.list_multi);
        setAnswer(ConfigureNodeFields.replyto.getFieldName(), replyTos);
    }
486944
public static void setDynamicMdcFields(String spec, GelfMessageAssembler gelfMessageAssembler) {
        if (null != spec) {
            String[] fields = spec.split(MULTI_VALUE_DELIMITTER);

            for (String field : fields) {
                gelfMessageAssembler.addField(new DynamicMdcMessageField(field.trim()));
            }
        }
    }
604356
@Override
    public final void setJmsDestination(byte[] value) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "setJmsDestination", value);
        /* There is no need to take a copy because the JMS API layer will never */
        /* change the byte array passed in. */
        getHdr2().setField(JsHdr2Access.JMSDESTINATION_DATA, value);
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "setJmsDestination");
    }
703042
public void setContentLength(int len) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.entering(CLASS_NAME,"setContentLength", "length --> " + String.valueOf(len) + " ["+this+"]");
        }

        // d151464 - check the include flag
        WebAppDispatcherContext dispatchContext = (WebAppDispatcherContext) getRequest().getWebAppDispatcherContext();
        if (dispatchContext.isInclude() == true) {
            if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"setContentLength", nls.getString("Illegal.from.included.servlet", "Illegal from included servlet"), "setContentLength length --> " + String.valueOf(len));  //311717
            }
        }
        else
        {
            if (_response!=null) {
                if (!_response.isCommitted()) {
                    _response.setContentLength(len);
                }
            }
            _contentLength = len;
            // LIBERTY _bufferedOut.setLimit(_contentLength = len);
            _bufferedWriter.setLimitLong(_contentLength);
            //still want to try to set the header even if the response is committed to throw the warning
            setIntHeader(HEADER_CONTENT_LENGTH, len);
        }
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled()&&logger.isLoggable (Level.FINE)) {  //306998.15
            logger.exiting(CLASS_NAME,"setContentLength");
        }
    }
1244259
private void checkResponseCode(String message) throws ResponseException {

        if (this.responseCode != 200 && this.responseCode != 204) {

            HashMap<Integer, String> responseCodes = new HashMap<Integer, String>() {{
                put(206, "PartialContent");
                put(400, "Bad request");
                put(401, "Unauthorized");
                put(403, "Prohibition to use the method");
                put(404, "Not found");
                put(405, "Method not allowed");
                put(413, "Request entity too large");
                put(422, "Unprocessable entity");
                put(500, "Internal server error");
                put(501, "Not implemented");
            }};

            ResponseException responseException = new ResponseException(message);
            responseException.setResponseHttpCode(this.responseCode);

            if (responseCodes.containsKey(this.responseCode)) {
                responseException.setResponseHttpDescription(responseCodes.get(this.responseCode));
            } else {
                responseException.setResponseHttpDescription("Unknown response error");
            }

            if (message != null) {
                JsonObject error = new JsonParser().parse(message).getAsJsonObject();
                for (Entry<String, JsonElement> entry : error.entrySet()) {

                    switch (entry.getKey().toLowerCase()) {
                        case "message":
                            responseException.setApiMessage(entry.getValue().getAsString());
                            break;
                        case "type":
                            responseException.setType(entry.getValue().getAsString());
                            break;
                        case "id":
                            responseException.setId(entry.getValue().getAsString());
                            break;
                        case "date":
                            responseException.setDate((int) entry.getValue().getAsDouble());
                            break;
                        case "errors":
                            if (entry.getValue() == null) break;

                            if (entry.getValue().isJsonNull()) break;

                            for (Entry<String, JsonElement> errorEntry : entry.getValue().getAsJsonObject().entrySet()) {
                                if (!responseException.getErrors().containsKey(errorEntry.getKey()))
                                    responseException.getErrors().put(errorEntry.getKey(), errorEntry.getValue().getAsString());
                                else {
                                    String description = responseException.getErrors().get(errorEntry.getKey());
                                    description = " | " + errorEntry.getValue().getAsString();

                                    responseException.getErrors().put(errorEntry.getKey(), description);
                                }
                            }
                            break;
                    }
                }
            }

            throw responseException;
        }
    }
196748
public void setContent(Object content, String contentType)
			throws UnsupportedEncodingException {
		// https://code.google.com/p/sipservlets/issues/detail?id=202
		if(getSipSession().getProxy() == null) {
			checkMessageState();
		}
		checkContentType(contentType);
		checkCommitted();

		if(contentType != null && contentType.length() > 0) {
			this.addHeader(ContentTypeHeader.NAME, contentType);
			ContentTypeHeader contentTypeHeader = (ContentTypeHeader)this.message.getHeader(ContentTypeHeader.NAME);
			String charset = this.getCharacterEncoding();
			try {
			    // https://code.google.com/p/sipservlets/issues/detail?id=169
				if(contentType.contains(CONTENT_TYPE_MULTIPART) && content instanceof Multipart) {
					// Fix for Issue 2667 : Correct Handling of MimeMultipart
					Multipart multipart = (Multipart) content;
					OutputStream os = new ByteArrayOutputStream();
					multipart.writeTo(os);
					this.message.setContent(os.toString(), contentTypeHeader);
				} else {
					Object tmpContent = content;
					if(tmpContent instanceof String  && charset != null) {
						//test for unsupportedencoding exception
						new String("testEncoding".getBytes(charset));
						tmpContent = new String(((String)tmpContent).getBytes());
					}
					this.message.setContent(content, contentTypeHeader);
				}
			} catch (UnsupportedEncodingException uee) {
				throw uee;
			} catch (Exception e) {
				throw new IllegalArgumentException("Parse error reading content " + content + " with content type " + contentType, e);
			}
		}
	}
676544
public void setStatusText(String strStatus, int iWarningLevel)
    {
        if (strStatus == null)
            strStatus = Constants.BLANK;
        m_strCurrentStatus = strStatus;
        m_iCurrentWarningLevel = iWarningLevel;
    }