Package nexj.core.util

Examples of nexj.core.util.MIMEHeaderMap


    */
   public void testParametrize() throws Exception
   {
      Pair result;
      TransferObject params = new TransferObject(2);
      MIMEHeaderMap emptyHeaderMap = new MIMEHeaderMap();
      MIMEHeaderMap formHeaderMap = new MIMEHeaderMap();

      params.setValue("a", "x");
      params.setValue("b", "y");

      formHeaderMap.add("Content-Type", "application/x-www-form-urlencoded");

      // Parameters go in URL (with or without ? on end of input URL)
      result = HTTPAdapter.parametrize("http://www.example.com/test1", null, params, emptyHeaderMap);
      assertEquals("http://www.example.com/test1?a=x&b=y", result.getHead());
      assertNull(result.getTail());
View Full Code Here


                  return true;
               }
            });
         }

         MIMEHeaderMap headerMap = m_client.getRequestHeaders();

         headerMap.clear();
         setHeaders(headerMap, (TransferObject)tobj.findValue(HEADERS));

         if (m_channel.getAgent() != null)
         {
            headerMap.setDefault(HTTP.HEADER_USER_AGENT, m_channel.getAgent());
         }

         if (m_channel.getContentType() != null)
         {
            headerMap.setDefault(HTTP.HEADER_CONTENT_TYPE, m_channel.getContentType());
         }

         Pair req = parametrize(sURL, tobj.findValue(BODY),
            (TransferObject)tobj.findValue(PARAMETERS), headerMap);

         final Object body = req.getTail();
         String sMethod = (String)tobj.findValue(METHOD);

         if (sMethod == null)
         {
            if (body != null)
            {
               sMethod = HTTP.METHOD_POST;
            }
            else
            {
               sMethod = HTTP.METHOD_GET;
            }
         }
         else
         {
            sMethod = sMethod.toUpperCase(Locale.ENGLISH);
         }

         sURL = (String)req.getHead();
         m_sentCounter.add(1);

         return (TransferObject)m_client.invoke(URIUtil.parse(sURL), sMethod,
            new HTTPClient.RequestHandler()
            {
               public void handleRequest(HTTPClient client, OutputStream ostream) throws IOException
               {
                  writeBody(client, ostream, body);
               }
            },
            new HTTPClient.ResponseHandler()
            {
               public Object handleResponse(HTTPClient client, InputStream istream) throws IOException
               {
                  TransferObject tobj = null;

                  if (bResponse || m_channel.getErrorFunction() != null)
                  {
                     tobj = new TransferObject(5);
                     tobj.setClassName("HTTP");
                     tobj.setValue(STATUS, Primitive.createInteger(m_client.getResponseStatus()));

                     String sMessage = m_client.getResponseMessage();

                     if (sMessage != null && sMessage.length() != 0)
                     {
                        tobj.setValue(MESSAGE, sMessage);
                     }

                     MIMEHeaderMap headerMap = m_client.getResponseHeaders();
                     String sEncoding = getEncoding(headerMap.find(HTTP.HEADER_CONTENT_TYPE), null);

                     if (sEncoding == null)
                     {
                        sEncoding = getEncoding(m_channel.getContentType(), DEFAULT_ENCODING);
                     }

                     if (istream == null)
                     {
                        tobj.setValue(BODY, null);
                     }
                     else
                     {
                        MIMEHeader header;

                        if (m_channel.getDataType() == Primitive.BINARY ||
                           m_channel.getDataType() == null && MIMEUtil.isBinaryMIMEType(
                              ((header = headerMap.find(HTTP.HEADER_CONTENT_TYPE)) == null) ? null : header.getValue()))
                        {
                           tobj.setValue(BODY, new StreamInput(istream, sEncoding).getBinary());
                        }
                        else
                        {
View Full Code Here

TOP

Related Classes of nexj.core.util.MIMEHeaderMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.