HttpMessage.java

/*
** Module   : HttpMessage.java
** Abstract : Implementation of the builtin class.
**
** Copyright (c) 2019-2023, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------------Description----------------------------------------
** 001 CA  20190526 First version, stubs taken by converting the skeleton using FWD.
** 002 CA  20191024 Added method support levels and updated the class support level.
** 003 MP  20200603 Added missing methods as stubs taken by converting the skeleton using FWD.
** 004 ME  20201103 Set cookies array entries only when we have any.
** 005 CA  20210113 Renamed clear() to clear_(), to follow NameConverter's rules.
** 006 CA  20210221 Fixed 'qualified', 'extent' and 'returns' annotations at the legacy signature.
**     CA  20210609 Updated INPUT/INPUT-OUTPUT parameters to the new approach, where they are explicitly 
**                  initialized at the method's execution, and not at the caller's arguments.
**     VVT 20210917 Javadoc fixed, missing @Override annotations inserted.
**     CA  20210928 The instances deleted in destroy() must be deleted them only if they are valid. 
**     CA  20220120 Do not used TypeFactory.object when the OO reference must not be tracked or registered.
**                  Do not use TypeFactory.object for internal usages, use ObjectVar if the reference must 
**                  be tracked.
**                  All TypeFactory.object variable definitions must be done outside of the top-level block.
**     CA  20221020 Do not explicitly delete the 'entity' object in destructor, let it follow the reference
**                  counting lifetime.
**     OM  20221220 Replaced array container with FinalParameterContainer.
** 007 CA  20230817 Removed ObjectOps.register, as this registration is handled by runtime.
** 008 CA  20231113 The 'execute' method must be annotated with LegacySignature Type.Execute, and also can be
**                  dropped if is a no-op.
*/

/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.oo.net.http;

import static com.goldencode.p2j.report.ReportConstants.*;
import static com.goldencode.p2j.util.BlockManager.*;

import com.goldencode.p2j.oo.core.*;
import com.goldencode.p2j.oo.core.collections.*;
import com.goldencode.p2j.oo.lang.*;
import com.goldencode.p2j.oo.net.http.filter.writer.*;
import com.goldencode.p2j.security.ContextLocal;
import com.goldencode.p2j.util.*;
import com.goldencode.p2j.util.BlockManager.Action;
import com.goldencode.p2j.util.BlockManager.Condition;
import com.goldencode.p2j.util.InternalEntry.*;

/**
 * Business logic (converted to Java from the 4GL source code
 * in OpenEdge/Net/HTTP/HttpMessage.cls).
 */
@LegacyResource(resource = "OpenEdge.Net.HTTP.HttpMessage")
@LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_STUB)
public class HttpMessage
extends BaseObject
implements IhttpMessage,
           ISupportInitialize,
           IAdaptable
{
   private static ContextLocal<longchar> _versions = new ContextLocal<longchar>()
   {
      @Override
      protected longchar initialValue()
      {
         return TypeFactory.longchar("HTTP/1.1,HTTP/1.0");
      }
   };
   
   /** An MD5 hash of the message's content. */
   @LegacySignature(type = Type.PROPERTY, name = "ContentMD5")
   private raw contentMd5 = TypeFactory.raw();
   
   /** The message's Transfer-Encoding. */
   @LegacySignature(type = Type.PROPERTY, name = "TransferEncoding")
   private character transferEncoding = TypeFactory.character();
   
   /** The HTTP version supported. Typically HTTP/1.1 */
   @LegacySignature(type = Type.PROPERTY, name = "Version")
   private character version = TypeFactory.character();
   
   /** Holds headers for this message */
   @LegacySignature(type = Type.PROPERTY, name = "Headers")
   private object<? extends HttpHeaderCollection> headers = TypeFactory.object(HttpHeaderCollection.class);
   
   /** Object containing the response body/entity. */
   @LegacySignature(type = Type.PROPERTY, name = "Entity")
   private object<? extends _BaseObject_> entity = TypeFactory.object(BaseObject.class);
   
   /** Only cookies relevant to only this message (request or response) */
   @LegacySignature(type = Type.PROPERTY, name = "Cookies")
   private object<? extends IStringKeyedMap> cookies = TypeFactory.object(IStringKeyedMap.class);

   /**
    * Execute method.
    */
   @LegacySignature(type = Type.EXECUTE)
   public void __net_http_HttpMessage_execute__()
   {
      onBlockLevel(Condition.ERROR, Action.THROW);
   }

   /**
    * Constructor.
    */
   @LegacySignature(type = Type.CONSTRUCTOR)
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   protected void __net_http_HttpMessage_constructor__()
   {
      internalProcedure(this, "__net_http_HttpMessage_constructor__", new Block((Body) () -> 
      {
         __lang_BaseObject_constructor__();
      }));
   }
   
   /**
    * Destructor.
    */
   @LegacySignature(type = Type.DESTRUCTOR)
   public void __net_http_HttpMessage_destructor__()
   {
      internalProcedure(HttpMessage.class, this, "__net_http_HttpMessage_destructor__", new Block((Body) () -> 
      {
         this.destroy();
      }));
   }

   /**
    * Get the message's content encoding.
    * @return the message's content encoding.
    */
   @Override
   @LegacySignature(returns = "CHARACTER", type = Type.GETTER, name = "CharacterEncoding")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public character getCharacterEncoding()
   {
      return function(this, "CharacterEncoding", character.class, new Block((Body) () -> 
      {
         character headerName = new character("Content-Type");
         
         returnNormal(
               hasHeader(headerName).booleanValue() ?
                     getHeader(headerName).ref().
                        getParameterValue(new character("charset")) :
                     new character("")
         );
      }));
   }

   /**
    * Set the message's content encoding.
    * @param _encoding the message's content encoding.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "CharacterEncoding", parameters = 
   {
      @LegacyParameter(name = "encoding", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setCharacterEncoding(final character _encoding)
   {
      character encoding = TypeFactory.initInput(_encoding);
      object<? extends HttpHeader> hdr = TypeFactory.object(HttpHeader.class);
      
      internalProcedure(this, "CharacterEncoding", new Block((Body) () -> 
      {
         Assert.notNull(encoding, new character("Character Encoding"));
         character contentType = new character("Content-Type");
         if (hasHeader(contentType).booleanValue())
         {
            hdr.assign(getHeader(contentType));
         }
         else 
         {
            hdr.assign(HttpHeaderBuilder.build(contentType).ref().getHeader());
            setHeader(hdr);
         }
         hdr.ref().setParameterValue(new character("charset"), encoding);
      }));
   }

   /**
    * Get the message content length.
    * 
    * @return the message content length.
    */
   @Override
   @LegacySignature(returns = "INTEGER", type = Type.GETTER, name = "ContentLength")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public integer getContentLength()
   {
      return function(this, "ContentLength", integer.class, new Block((Body) () -> 
      {
         character contentLength = new character("Content-Length");
         if (hasHeader(contentLength).booleanValue())
         {
            character clen = getHeader(contentLength).ref().getValue();
            Assert.isInteger(clen, contentLength);
            integer ilen = new integer(clen);
            Assert.isZeroOrPositive(ilen, contentLength);
            returnNormal(ilen);
         }
         returnNormal(new integer(0));
      }));
   }

   /**
    * Set the message content length.
    * @param _len the message content length.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "ContentLength", parameters = 
   {
      @LegacyParameter(name = "len", type = "INTEGER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setContentLength(final integer _len)
   {
      integer len = TypeFactory.initInput(_len);
      object<? extends HttpHeader> hdr = TypeFactory.object(HttpHeader.class);
      
      internalProcedure(this, "ContentLength", new Block((Body) () -> 
      {
         character contentLength = new character("Content Length");
         
         Assert.notNull(len, contentLength);
         Assert.isZeroOrPositive(len, contentLength);
         
         contentLength.assign("Content-Length");
         
         if (hasHeader(contentLength).booleanValue())
         {
            hdr.assign(getHeader(contentLength));
         }
         else 
         {
            hdr.assign(HttpHeaderBuilder.build(contentLength).ref().getHeader());
            setHeader(hdr);
         }
         hdr.ref().setValue(new character(len));
      }));
   }

   /**
    * Get an MD5 hash of the message's content.
    * @return an MD5 hash of the message's content.
    */
   @Override
   @LegacySignature(returns = "RAW", type = Type.GETTER, name = "ContentMD5")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public raw getContentMd5()
   {
      return function(this, "ContentMD5", raw.class, new Block((Body) () -> 
      {
         returnNormal(contentMd5);
      }));
   }

   /**
    * Set an MD5 hash of the message's content.
    * @param _var an MD5 hash of the message's content.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "ContentMD5", parameters = 
   {
      @LegacyParameter(name = "var", type = "RAW", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setContentMd5(final raw _var)
   {
      raw var = TypeFactory.initInput(_var);
      
      internalProcedure(this, "ContentMD5", new Block((Body) () -> 
      {
         contentMd5.assign(var);
      }));
   }

   /**
    * Get message content type.
    * 
    * @return message content type.
    */
   @Override
   @LegacySignature(returns = "CHARACTER", type = Type.GETTER, name = "ContentType")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public character getContentType()
   {
      return function(this, "ContentType", character.class, new Block((Body) () -> 
      {
         character contentType = new character("Content-Type");
         if (hasHeader(contentType).booleanValue())
         {
            returnNormal(getHeader(contentType).ref().getBaseValue());
         }
         returnNormal(new character(""));
      }));
   }

   /**
    * Set message content type.
    * 
    * @param _ctype message content type.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "ContentType", parameters = 
   {
      @LegacyParameter(name = "ctype", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setContentType(final character _ctype)
   {
      character ctype = TypeFactory.initInput(_ctype);
      object<? extends HttpHeader> hdr = TypeFactory.object(HttpHeader.class);
      
      internalProcedure(this, "ContentType", new Block((Body) () -> 
      {
         Assert.notNull(ctype, new character("Content Type"));
         
         character contentType = new character("Content-Type");
         
         if (hasHeader(contentType).booleanValue())
         {
            hdr.assign(getHeader(contentType));
         }
         else 
         {
            hdr.assign(HttpHeaderBuilder.build(contentType).ref().getHeader());
            setHeader(hdr);
         }
         hdr.ref().setValue(ctype);
      }));
   }

   /**
    * Get cookies relevant to only this message (request or response).
    *  
    * @return cookies relevant to only this message (request or response).
    */
   @LegacySignature(returns = "OBJECT", qualified = "OpenEdge.Core.Collections.IStringKeyedMap", type = Type.GETTER, name = "Cookies")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   protected object<? extends IStringKeyedMap> getCookies()
   {
      return function(this, "Cookies", object.class, new Block((Body) () -> 
      {
         returnNormal(cookies);
      }));
   }


   /**
    * Get  an object containing the message body/entity. 
    * 
    * @return an object containing the message body/entity.
    */
   @Override
   @LegacySignature(returns = "OBJECT", qualified = "Progress.Lang.Object", type = Type.GETTER, name = "Entity")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public object<? extends com.goldencode.p2j.oo.lang._BaseObject_> getEntity()
   {
      return function(this, "Entity", object.class, new Block((Body) () -> 
      {
         returnNormal(entity);
      }));
   }

   /**
    * Set an object containing the message body/entity.
    * 
    * @param _var an object containing the message body/entity.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "Entity", parameters = 
   {
      @LegacyParameter(qualified = "Progress.Lang.Object", name = "var", type = "OBJECT", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setEntity(final object<? extends _BaseObject_> _var)
   {
      object<? extends _BaseObject_> var = TypeFactory.initInput(_var);
      
      internalProcedure(this, "Entity", new Block((Body) () -> 
      {
         entity.assign(var);
      }));
   }

   /**
    * Get the headers of this message.
    * 
    * @return the headers of this message.
    */
   @LegacySignature(returns = "OBJECT", qualified = "OpenEdge.Net.HTTP.HttpHeaderCollection", type = Type.GETTER, name = "Headers")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   protected object<? extends HttpHeaderCollection> getHeaders()
   {
      return function(this, "Headers", object.class, new Block((Body) () -> 
      {
         returnNormal(headers);
      }));
   }

   
   @Override
   @LegacySignature(type = Type.METHOD, name = "SetHeaders", parameters = 
   {
      @LegacyParameter(name = "poHeaders", type = "OBJECT", extent = -1, qualified = "openedge.net.http.httpheader", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setHeaders(final object<? extends com.goldencode.p2j.oo.net.http.HttpHeader>[] poHeaders)
   {
      internalProcedure(HttpMessage.class, this, "SetHeaders", new Block((Body) () -> 
      {
         for (object<? extends com.goldencode.p2j.oo.net.http.HttpHeader> h : poHeaders) {
            if (h._isValid())
               setHeader(h);
         }
      }));
   }

   /**
    * Get the message's Transfer-Encoding. 
    * 
    * @return the message's Transfer-Encoding.
    */
   @Override
   @LegacySignature(returns = "CHARACTER", type = Type.GETTER, name = "TransferEncoding")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public character getTransferEncoding()
   {
      return function(this, "TransferEncoding", character.class, new Block((Body) () -> 
      {
         returnNormal(transferEncoding);
      }));
   }

   /**
    * Set the message's Transfer-Encoding.
    * @param _var the message's Transfer-Encoding.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "TransferEncoding", parameters = 
   {
      @LegacyParameter(name = "var", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setTransferEncoding(final character _var)
   {
      character var = TypeFactory.initInput(_var);
      
      internalProcedure(this, "TransferEncoding", new Block((Body) () -> 
      {
         Assert.notNull(var, new character("Transfer encoding"));
         transferEncoding.assign(var);
      }));
   }

   /**
    * Get the HTTP version supported.
    * 
    * @return the HTTP version supported.
    */
   @Override
   @LegacySignature(returns = "CHARACTER", type = Type.GETTER, name = "Version")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public character getVersion()
   {
      return function(this, "Version", character.class, new Block((Body) () -> 
      {
         returnNormal(version);
      }));
   }

   /**
    * Set the HTTP version supported.
    * 
    * @param _var the HTTP version supported.
    */
   @Override
   @LegacySignature(type = Type.SETTER, name = "Version", parameters = 
   {
      @LegacyParameter(name = "var", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setVersion(final character _var)
   {
      character var = TypeFactory.initInput(_var);
      
      internalProcedure(this, "Version", new Block((Body) () -> 
      {
         Assert.isIn(var, _versions.get(), new character("HTTP Version"));
         version.assign(var);
      }));
   }

   /**
    * Removes all cookies from this message.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "ClearCookies")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void clearCookies()
   {
      internalProcedure(this, "ClearCookies", new Block((Body) () -> 
      {
         this.cookies.ref().clear_();
      }));
   }

   /**
    * Removes all headers from this message.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "ClearHeaders")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void clearHeaders()
   {
      internalProcedure(this, "ClearHeaders", new Block((Body) () -> 
      {
         this.headers.ref().clear_();
      }));
   }

   /**
    * Destroy.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "Destroy")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void destroy()
   {
      internalProcedure(this, "Destroy", new Block((Body) () -> 
      {
         clearCookies();
         clearHeaders();
         
         // entity can't be explicitly deleted here - a getter will return the exact instance, and this can
         // survive after the response has been destroyed.
         
         if (cookies._isValid())
         {
            ObjectOps.delete(cookies);
         }
         if (headers._isValid())
         {
            ObjectOps.delete(headers);
         }
      }));
   }

   /**
    *  Returns an adapter for this message
    *  
    *  @param _p1 The type we want to adapt this message to.
    *  
    *  @return The adapter. Will typically be of the type specified by the input argument.
    */
   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "GetAdapter", 
         qualified = "progress.lang.object", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", 
            qualified = "progress.lang.class", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   @Override
   public object<? extends _BaseObject_> getAdapter(final object<? extends LegacyClass> _p1)
   {
      object<? extends LegacyClass> cls = TypeFactory.initInput(_p1);
      
      return function(this, "GetAdapter", object.class, new Block((Body) () -> 
      {
         Assert.notNull(cls, new character("Adapter"));
         
         if (getLegacyClass().ref()._isA(cls))
         {
            returnNormal(new object(this));
         }
         returnNormal(new object(BaseObject.class));
      }));
   }

   /**
    * Returns a cookie by name from this message.
    * 
    * @param _p1 The cookie's name to check.
    * 
    * @return The (first) cookie found by name.
    */
   @Override
   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "GetCookie", 
         qualified = "openedge.net.http.cookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public object<? extends Cookie> getCookie(final character _p1)
   {
      character name = TypeFactory.initInput(_p1);
      
      return function(this, "GetCookie", object.class, new Block((Body) () -> 
      {
         Assert.notNullOrEmpty(name, new character("Cookie name"));
         returnNormal(ObjectOps.cast(this.cookies.ref().get(name), Cookie.class));
      }));
   }

   /**
    * Returns all the cookies for this message.
    * 
    * @param _extpoCookies
    *        An array of cookies.
    * 
    * @return The number of cookies returned.
    */
   @Override
   @LegacySignature(returns = "INTEGER", type = Type.METHOD, name = "GetCookies", parameters = {
            @LegacyParameter(name = "p1", type = "OBJECT", extent = -1, qualified = "openedge.net.http.cookie", mode = "OUTPUT") })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL | RT_LVL_STUB)
   public integer getCookies(final OutputExtentParameter<object<? extends Cookie>> _extpoCookies)
   {
      int sz = this.cookies.ref().getSize().intValue();
      object[] extpoCookies = TypeFactory.initOutput(_extpoCookies, sz);
      
      return function(this, "GetCookies", integer.class, new Block((Body) () -> {
         if (extpoCookies.length > 0)
         {
            object<? extends Icollection> valueCollection = this.cookies.ref().getValues();

            object<? extends _BaseObject_>[] cookieArray = valueCollection.ref().toArray();

            for (int i = 0; i < cookieArray.length; i++)
            {
               extpoCookies[i] = ObjectOps.cast(cookieArray[i], Cookie.class);
            }
         }

         returnNormal(new integer(extpoCookies.length));
      }));
   }

   /**
    * Returns a named header. 
    * 
    * @param _p1 The name of the header to retrieve.
    * 
    * @return The header object. Null if not exists.
    */
   @Override
   @LegacySignature(returns = "OBJECT", type = Type.METHOD, name = "GetHeader", 
         qualified = "openedge.net.http.httpheader", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public object<? extends HttpHeader> getHeader(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);
      
      return function(this, "GetHeader", object.class, new Block((Body) () -> 
      {
         returnNormal(this.headers.ref().get(p1));
      }));
   }

   /**
    * Returns all the headers.
    * 
    * @param _extp1
    *         An array of headers.
    * 
    * @return The number of headers returned.
    */
   @Override
   @LegacySignature(returns = "INTEGER", type = Type.METHOD, name = "GetHeaders", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", extent = -1, 
            qualified = "openedge.net.http.httpheader", mode = "OUTPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public integer getHeaders(final OutputExtentParameter<object<? extends HttpHeader>> _extp1)
   {
      FinalParameterContainer<object<? extends HttpHeader>[]> extp1 = 
            new FinalParameterContainer<>(TypeFactory.initOutput(_extp1));
      
      return function(this, "GetHeaders", integer.class, new Block((Body) () -> 
      {
         returnNormal(headers.ref().getAll(
                  new OutputExtentParameter<object<? extends HttpHeader>>()
                  {
                     @Override
                     public object<? extends HttpHeader>[] getVariable()
                     {
                        return extp1.getValue();
                     }
                     
                     @Override
                     public void setVariable(object<? extends HttpHeader>[] reference)
                     {
                        extp1.setValue(reference);
                     }
                  }));
      }));
   }
   
   /**
    * Indicates whether a cookie exists for this message.
    * 
    * @param _p1 The cookie's name to check.
    * 
    * @return <code>true</code> if this message contains the cookie.
    */
   @Override
   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "HasCookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public logical hasCookie(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);
      
      return function(this, "HasCookie", logical.class, new Block((Body) () -> 
      {
         Assert.notNullOrEmpty(p1, new character("Cookie name"));
         returnNormal(new logical(this.cookies.ref().containsKey(p1)));
      }));
   }

   /**
    * Indicates whether a cookie exists for this message.
    * 
    * @param _p1 The cookie to check.
    * 
    * @return <code>true</code> if this message contains the cookie.
    */
   @Override
   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "HasCookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", 
            qualified = "openedge.net.http.cookie", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public logical hasCookie(final object<? extends Cookie> _p1)
   {
      object<? extends Cookie> p1 = TypeFactory.initInput(_p1);
      
      return function(this, "HasCookie", logical.class, new Block((Body) () -> 
      {
         Assert.notNull(p1, new character("Cookie"));
         
         returnNormal(hasCookie(p1.ref().getName()));
      }));
   }

   /**
    * Indicates whether a header exists for this message or not.
    * 
    * @param _p1 The name of a header to check.
    * 
    * @return <code>true</code>  if this message contains the header.
    */
   @Override
   @LegacySignature(returns = "LOGICAL", type = Type.METHOD, name = "HasHeader", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public logical hasHeader(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);
      
      return function(this, "HasHeader", logical.class, new Block((Body) () -> 
      {
         returnNormal(this.headers.ref().has(p1));
      }));
   }

   /**
    * Initialize 
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "Initialize")
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void initialize()
   {
      internalProcedure(this, "Initialize", new Block((Body) () -> 
      {
         transferEncoding.assign("None");
         cookies.assign(ObjectOps.newInstance(StringKeyedMap.class));
         headers.assign(ObjectOps.newInstance(HttpHeaderCollection.class));
      }));
   }

   /**
    * Removes coolies from this message for a given name.
    * @param _p1 The name of the cookie(s) to remove.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "RemoveCookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void removeCookie(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);
      
      internalProcedure(this, "RemoveCookie", new Block((Body) () -> 
      {
         Assert.notNullOrEmpty(p1, new character("Cookie name"));
         cookies.ref().remove(p1);
      }));
   }

   /**
    * Removes a cookie from this message.
    * 
    * @param _p1 The cookie to remove.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "RemoveCookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", 
            qualified = "openedge.net.http.cookie", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void removeCookie(final object<? extends Cookie> _p1)
   {
      object<? extends Cookie> p1 = TypeFactory.initInput(_p1);
      
      internalProcedure(this, "RemoveCookie", new Block((Body) () -> 
      {
         Assert.notNull(p1, new character("Cookie"));
         removeCookie(p1.ref().getName());
      }));
   }

   /**
    * Removes all headers with a given name from the set of message headers. No-op if none exists.
    * 
    * @param _p1 The name of the header to remove.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "RemoveHeader", parameters = 
   {
      @LegacyParameter(name = "p1", type = "CHARACTER", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void removeHeader(final character _p1)
   {
      character p1 = TypeFactory.initInput(_p1);
      
      internalProcedure(this, "RemoveHeader", new Block((Body) () -> 
      {
         Assert.notNull(p1, new character("Header name"));
         this.headers.ref().remove(p1);
      }));
   }

   /**
    * Adds a cookie to this message
    * 
    * @param _p1 The cookie to add.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "SetCookie", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", 
            qualified = "openedge.net.http.cookie", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setCookie(final object<? extends Cookie> _p1)
   {
      object<? extends Cookie> p1 = TypeFactory.initInput(_p1);
      
      internalProcedure(this, "SetCookie", new Block((Body) () -> 
      {
         Assert.notNull(p1, new character("Cookie"));
         this.cookies.ref().put_2(p1.ref().getName(), p1);
      }));
   }
   
   @Override
   @LegacySignature(type = Type.METHOD, name = "SetCookies", parameters = 
   {
      @LegacyParameter(name = "poCookies", type = "OBJECT", extent = -1, qualified = "openedge.net.http.cookie", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setCookies(final object<? extends com.goldencode.p2j.oo.net.http.Cookie>[] poCookies)
   {
      internalProcedure(HttpMessage.class, this, "SetCookies", new Block((Body) () -> 
      {
         for (object<? extends com.goldencode.p2j.oo.net.http.Cookie> c : poCookies) {
            if (c._isValid())
               setCookie(c);
         }
      }));
   }

   /**
    * Adds header info to this message's collection of headers.
    * 
    * @param _p1 The header.
    */
   @Override
   @LegacySignature(type = Type.METHOD, name = "SetHeader", parameters = 
   {
      @LegacyParameter(name = "p1", type = "OBJECT", 
            qualified = "openedge.net.http.httpheader", mode = "INPUT")
   })
   @LegacyResourceSupport(supportLvl = CVT_LVL_FULL|RT_LVL_FULL)
   public void setHeader(final object<? extends HttpHeader> _p1)
   {
      object<? extends HttpHeader> hdr = TypeFactory.initInput(_p1);
      object<? extends IHttpMessageWriter> writer = TypeFactory.object(IHttpMessageWriter.class);
      
      internalProcedure(this, "SetHeader", new Block((Body) () -> 
      {
         Assert.notNull(hdr, new character("Http Header"));
         writer.assign(SetHeaderMessageWriterBuilder.build(new object<>(this), hdr));
         if (writer.isValid().booleanValue())
         {
            writer.ref().open();
            writer.ref().write(hdr);
            writer.ref().close();
         }
         else 
         {
            this.headers.ref().put(hdr);
         }
      }));
   }
}