Package nexj.core.integration

Examples of nexj.core.integration.IntegrationException


      {
         sURL = m_channel.getURL();

         if (sURL == null)
         {
            throw new IntegrationException("err.integration.http.noURL");
         }
      }

      try
      {
         if (m_client == null)
         {
            m_client = new HTTPClient();
         }

         m_client.setTrustedCertificate(m_channel.getTrustedCertificate());
         m_client.setReadTimeout(m_channel.getReadTimeout());
         m_client.setConnectionTimeout(m_channel.getConnectionTimeout());

         switch (m_channel.getAuthMode())
         {
            case HTTPChannel.AUTH_BASIC:
            case HTTPChannel.AUTH_NONE:
               m_client.setSPNEGOMode(HTTPClient.SPNEGO_NONE);
               break;

            case HTTPChannel.AUTH_CRED:
               m_client.setSPNEGOMode(HTTPClient.SPNEGO_CRED);
               break;

            case HTTPChannel.AUTH_SERVER:
               m_client.setSPNEGOMode(HTTPClient.SPNEGO_SILENT);
               break;

            case HTTPChannel.AUTH_CLIENT:
               // TODO: Implement credential propagation
               break;

            case HTTPChannel.AUTH_CERT:
               m_client.setClientCertificate(m_channel.getClientCertificate(), m_channel.getPassword());
               break;
         }

         if (m_channel.getAuthMode() == HTTPChannel.AUTH_BASIC ||
            m_channel.getAuthMode() == HTTPChannel.AUTH_CRED)
         {
            String sUser = (String)tobj.findValue(USER);
           
            if (sUser == null)
            {
               if (m_credentials == null && m_channel.getUser() != null)
               {
                  m_credentials = new PasswordAuthentication(m_channel.getUser(),
                     ((m_channel.getPassword() == null) ? "" : m_channel.getPassword()).toCharArray());
               }

               m_client.setPasswordProvider(this);
            }
            else
            {
               String sPassword = (String)tobj.findValue(PASSWORD);
               final PasswordAuthentication credentials = new PasswordAuthentication(sUser,
                  ((sPassword == null) ? "" : sPassword).toCharArray());

               m_client.setPasswordProvider(new PasswordAuthenticationProvider()
               {
                  public PasswordAuthentication getPasswordAuthentication()
                  {
                     return credentials;
                  }

                  public boolean isAuthenticationDeterministic()
                  {
                     return true;
                  }
               });
            }
         }
         else
         {
            m_client.setPasswordProvider(this);
         }

         final String sProxyHost = (String)tobj.findValue(PROXY_HOST);
         Proxy proxy = m_channel.getProxy();

         if (sProxyHost != null)
         {
            final Integer proxyPort = (Integer)tobj.findValue(PROXY_PORT);

            if (proxyPort != null)
            {
               proxy = new Proxy(Proxy.Type.HTTP, (InetSocketAddress)AccessController.doPrivileged(
                  new PrivilegedAction()
                  {
                     public Object run()
                     {
                        return InetSocketAddress.createUnresolved(sProxyHost, proxyPort.intValue());
                     }
                  }
               ));
            }
         }

         m_client.setProxy(proxy);

         switch (m_channel.getProxyAuthMode())
         {
            case HTTPChannel.AUTH_BASIC:
               m_client.setProxySPNEGOMode(HTTPClient.SPNEGO_NONE);
               break;

            case HTTPChannel.AUTH_CRED:
               m_client.setProxySPNEGOMode(HTTPClient.SPNEGO_CRED);
               break;

            case HTTPChannel.AUTH_SERVER:
               m_client.setProxySPNEGOMode(HTTPClient.SPNEGO_SILENT);
               break;
         }

         String sProxyUser = (String)tobj.findValue(PROXY_USER);
         String sProxyPassword;

         if (sProxyUser == null)
         {
            sProxyPassword = m_channel.getProxyPassword();
            sProxyUser = m_channel.getUser();
         }
         else
         {
            sProxyPassword = (String)tobj.findValue(PROXY_PASSWORD);
         }

         if (sProxyUser != null)
         {
            final PasswordAuthentication proxyCredentials = new PasswordAuthentication(sProxyUser,
               ((sProxyPassword == null) ? "" : sProxyPassword).toCharArray());

            m_client.setProxyPasswordProvider(new PasswordAuthenticationProvider()
            {
               public PasswordAuthentication getPasswordAuthentication()
               {
                  return proxyCredentials;
               }

               public boolean isAuthenticationDeterministic()
               {
                  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
                        {
                           istream = UTF8BOMIgnoreInputStream.wrap(istream, sEncoding);
                           tobj.setValue(BODY, new ReaderInput(new InputStreamReader(istream, sEncoding)).getString());
                        }
                     }

                     tobj.setValue(CHANNEL, m_channel.getName());
                     tobj.setValue(HEADERS, getHeaders(m_client.getResponseHeaders()));
                  }

                  if (s_logger.isDebugEnabled())
                  {
                     s_logger.debug("Received a response on channel \"" + m_channel.getName() + "\"");
                     s_logger.dump(tobj);
                  }

                  if (m_channel.getErrorFunction() != null)
                  {
                     if (Intrinsic.isTrue(m_context.getMachine().invoke(m_channel.getErrorFunction(), tobj, (Pair)null)))
                     {
                        fail(m_client);
                     }
                  }
                  else if (isError(m_client.getResponseStatus()))
                  {
                     fail(m_client);
                  }

                  return tobj;
               }
            });
      }
      catch (URISyntaxException e)
      {
         throw new IntegrationException("err.integration.uri", new Object[]{sURL}, e);
      }
      catch (IOException e)
      {
         throw new IntegrationException("err.integration.io", e);
      }
      catch (RuntimeException e)
      {
         if (m_client != null)
         {
            if (e instanceof AuthenticationException ||
               e instanceof CancellationException)
            {
               m_client.reset();
            }
         }

         throw new IntegrationException("err.integration.io", e);
      }
   }
View Full Code Here


      {
         return new BufferedReader(new InputStreamReader(m_istream, m_sEncoding));
      }
      catch (UnsupportedEncodingException e)
      {
         throw new IntegrationException("err.integration.io", e);
      }
   }
View Full Code Here

      {
         IOUtil.copy(ostream, m_istream);
      }
      catch (IOException e)
      {
         throw new IntegrationException("err.integration.io", e);
      }

      return new Binary(ostream.toByteArray());
   }
View Full Code Here

      {
         IOUtil.copy(writer, new InputStreamReader(m_istream, m_sEncoding));
      }
      catch (IOException e)
      {
         throw new IntegrationException("err.integration.io", e);
      }

      return writer.toString();
   }
View Full Code Here

   {
      if (m_ostream == null)
      {
         if (m_writer != null)
         {
            throw new IntegrationException("err.integration.outputStream");
         }
        
         m_ostream = new ByteArrayOutputStream(256);
      }
View Full Code Here

            {
               m_writer = new OutputStreamWriter(m_ostream, m_sEncoding);
            }
            catch (UnsupportedEncodingException e)
            {
               throw new IntegrationException("err.integration.io", e);
            }
         }
         else
         {
            m_writer = new StringWriter(256);
View Full Code Here

   /**
    * @see nexj.core.integration.Output#getOutputStream()
    */
   public OutputStream getOutputStream() throws IntegrationException
   {
      throw new IntegrationException("err.integration.outputStream");
   }
View Full Code Here

   /**
    * @see nexj.core.integration.Output#setBinary(nexj.core.util.Binary)
    */
   public void setBinary(Binary msg) throws IntegrationException
   {
      throw new IntegrationException("err.integration.outputBinary");
   }
View Full Code Here

      {
         m_writer.write(sMsg);
      }
      catch (IOException e)
      {
         throw new IntegrationException("err.integration.io", e);
      }
   }
View Full Code Here

   /**
    * @see nexj.core.integration.Output#setObject(java.lang.Object)
    */
   public void setObject(Object obj) throws IntegrationException
   {
      throw new IntegrationException("err.integration.outputObject");
   }
View Full Code Here

TOP

Related Classes of nexj.core.integration.IntegrationException

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.