Package nexj.core.meta.integration.channel.http

Examples of nexj.core.meta.integration.channel.http.HTTPChannel


   {
      SOAPService service = getService((Named)channel);

      if (channel instanceof HTTPChannel)
      {
         HTTPChannel httpChannel = (HTTPChannel)channel;
         StringBuilder buf = new StringBuilder();

         buf.append((httpChannel.isSecure()) ? "https://" : "http://");
         buf.append(m_sHostName);
         buf.append(m_sContextRoot);
         buf.append(((httpChannel.getAuthMode() == HTTPChannel.AUTH_CERT) ? "cert/channel/" : "channel/")
            + httpChannel.getName());

         service.setEndpoint(buf.toString());
      }

      return service;
View Full Code Here


      if (!(channel instanceof HTTPChannel) || !channel.isReceivable())
      {
         throw new RPCException("err.rpc.http.notReceiver", new Object[]{sChannel});
      }
     
      HTTPChannel http = (HTTPChannel)channel;

      if (http.isSecure() && !m_request.isSecure())
      {
         throw new RequestException("err.rpc.http.insecure", new Object[]{sChannel});
      }

      // Deny anonymous access to non-anonymous channels, and vice-versa
      if (HTTPUtil.isAnonymousRequest(m_request, metadata))
      {
         if (http.getAuthMode() != HTTPChannel.AUTH_NONE)
         {
            throw new SecurityViolationException("err.rpc.anonymous");
         }
      }
      else if (http.getAuthMode() == HTTPChannel.AUTH_NONE)
      {
         throw new SecurityViolationException("err.rpc.notAnonymous", new Object[]{sChannel});
      }

      boolean bRequestUsesCertificateAuth = HTTPUtil.isUsingClientCertificateAuthentication(m_request);

      // Deny access to client certificate channels if no certificate present
      if (http.getAuthMode() == HTTPChannel.AUTH_CERT)
      {
         if (!bRequestUsesCertificateAuth)
         {
            throw new SecurityViolationException("err.rpc.http.certificateRequired", new Object[]{sChannel});
         }

         X509Certificate[] certs = (X509Certificate[])m_request.getAttribute(HTTPUtil.CLIENT_CERTIFICATE_ATTRIBUTE_NAME);

         if (certs == null)
         {
            throw new SecurityViolationException("err.integration.missingCertificate", new Object[]{sChannel});
         }

         // The certificate should now be validated against allowed certificates for this channel.
         if (!HTTPUtil.isCertificateMatched(http.getTrustedCertificate(), certs))
         {
            throw new SecurityViolationException("err.integration.unauthorized", new Object[]{sChannel});
         }
      }
      else if (bRequestUsesCertificateAuth)
      {
         // Deny access to non-certificate-auth channels through certificate authentication.
         throw new SecurityViolationException("err.integration.unauthorized", new Object[]{sChannel});
      }

      if (http.getPrivilege() != null && !m_context.getPrivilegeSet().contains(http.getPrivilege()))
      {
         throw new SecurityViolationException("err.integration.unauthorized", new Object[]{sChannel});
      }
     
      m_lMaxRequestSize = http.getMaxRequestSize();

      HTTPAdapter adapter = (HTTPAdapter)channel.getReceiver().getInstance(m_context);

      adapter.setServer(this);

      String sMethod = m_request.getMethod();
      boolean bImplemented;

      if (sMethod.equals("POST"))
      {
         bImplemented = http.isPostImplemented();
      }
      else if (sMethod.equals("GET"))
      {
         bImplemented = http.isGetImplemented();

         if (channel.getBindingCount() > 0 &&
            GENERATE_WSDL_QUERY.equalsIgnoreCase(m_request.getQueryString()))
         {
            SchemaExporter exporter = null;
            MessageTable msgTable = channel.getMessageTable();

            if (msgTable != null)
            {
               Format format = msgTable.getFormat();

               if (format != null)
               {
                  Class exporterClass = format.getExporter();

                  if (exporterClass != null)
                  {
                     Object obj = m_context.getClassInstance(exporterClass);

                     if (obj instanceof SchemaExporter)
                     {
                        exporter = (SchemaExporter)obj;
                     }
                  }
               }
            }

            if (exporter != null)
            {
               Writer writer;

               m_response.setStatus(HttpServletResponse.SC_OK);
               m_response.setContentType("text/xml; charset=UTF-8");
               writer = m_response.getWriter();
               exporter.exportSchema(channel, getRoot() + "/", writer);
               writer.close();
               return;
            }
         }
      }
      else if (sMethod.equals("HEAD"))
      {
         if (http.isHeadImplemented())
         {
            bImplemented = true;
         }
         else if (http.isGetImplemented())
         {
            sMethod = "GET";
            bImplemented = true;
         }
         else
         {
            bImplemented = false;
         }
      }
      else if (sMethod.equals("PUT"))
      {
         bImplemented = http.isPutImplemented();
      }
      else if (sMethod.equals("DELETE"))
      {
         bImplemented = http.isDeleteImplemented();
      }
      else if (sMethod.equals("TRACE"))
      {
         if (!http.isTraceImplemented())
         {
            doTrace();
            return;
         }

         bImplemented = true;
      }
      else if (sMethod.equals("OPTIONS"))
      {
         if (!http.isOptionsImplemented())
         {
            doOptions(http);
            return;
         }
        
         bImplemented = true;
      }
      else
      {
         bImplemented = false;
      }

      if (!bImplemented)
      {
         if (m_request.getProtocol().endsWith("1.1"))
         {
            m_response.setHeader("Allowed", getAllowedMethods(http));
            m_response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
         }
         else
         {
            m_response.sendError(HttpServletResponse.SC_BAD_REQUEST);
         }
      }
      else if (adapter.isBound(channel, m_context))
      {
         TransferObject tobj = new TransferObject(6);
         String sEncoding = m_request.getCharacterEncoding();

         if (sEncoding == null)
         {
            sEncoding = HTTPAdapter.getEncoding(http.getContentType(), HTTPAdapter.DEFAULT_ENCODING);
            m_request.setCharacterEncoding(sEncoding);
         }

         tobj.setValue(HTTPAdapter.CHANNEL, http.getName());
         tobj.setValue(HTTPAdapter.METHOD, sMethod);
         tobj.setValue(HTTPAdapter.PATH, sPath);

         TransferObject headers = new TransferObject();

         for (Enumeration enm = m_request.getHeaderNames(); enm.hasMoreElements();)
         {
            String sName = (String)enm.nextElement();
            String sNameLower = sName.toLowerCase(Locale.ENGLISH);
            Object value;

            switch (HTTP.getHeaderType(sNameLower))
            {
               case HTTP.TYPE_INTEGER:
                  value = Primitive.createInteger(m_request.getIntHeader(sName));
                  break;

               case HTTP.TYPE_DATE:
                  long lDate = m_request.getDateHeader(sName);
                  value = (lDate == -1) ? null : new Timestamp(lDate);
                  break;

               default:
                  value = m_request.getHeader(sName);
                  break;
            }

            headers.setValue(sNameLower, value);
         }

         tobj.setValue(HTTPAdapter.HEADERS, headers);

         Map parameterMap = getParameterMap();
         TransferObject parameters = null;

         if (parameterMap != null && parameterMap.size() > 0)
         {
            parameters = new TransferObject(parameterMap.size());

            for (Iterator itr = parameterMap.entrySet().iterator(); itr.hasNext(); )
            {
               Map.Entry entry = (Map.Entry)itr.next();
               String[] sValueArray = (String[])entry.getValue();
               Object value;

               if (sValueArray == null)
               {
                  value = null;
               }
               else if (sValueArray.length == 1)
               {
                  value = sValueArray[0];
               }
               else
               {
                  List valueList = new ArrayList(sValueArray.length);

                  for (int k = 0; k < sValueArray.length; k++)
                  {
                     valueList.add(sValueArray[k]);
                  }

                  value = valueList;
               }

               parameters.setValue((String)entry.getKey(), value);
            }
         }

         if (isMultipart())
         {
            Lookup paramMap = getMultipartParameters(null, 0);

            if (parameters == null && paramMap.size() > 0)
            {
               parameters = new TransferObject(paramMap.size());
            }

            for (Lookup.Iterator itr = paramMap.iterator(); itr.hasNext();)
            {
               itr.next();
               parameters.setValue((String)itr.getKey(), itr.getValue());
            }
         }

         if (parameters != null)
         {
            tobj.setValue(HTTPAdapter.PARAMETERS, parameters);
         }

         tobj.setValue(HTTPAdapter.BODY,
            (http.getDataType() == Primitive.BINARY ||
               http.getDataType() == null &&
               MIMEUtil.isBinaryMIMEType(m_request.getHeader(HTTP.HEADER_CONTENT_TYPE))) ?
               new StreamInput(getInputStream(), sEncoding) :
                  (Input)new ReaderInput(getReader()));

         try
View Full Code Here

         {
            Channel channel = (Channel)itr.next();

            if (channel instanceof HTTPChannel && channel.isEnabled())
            {
               HTTPChannel http = (HTTPChannel)channel;

               if (http.isSecure() && http.getTrustedCertificate() != null)
               {
                  keyStore.setCertificateEntry(SysUtil.NAMESPACE + "-channel-" +
                     http.getName().toLowerCase(Locale.ENGLISH), http.getTrustedCertificate());
               }
            }
         }

         // Add Generic RPC trusted certificate
View Full Code Here

TOP

Related Classes of nexj.core.meta.integration.channel.http.HTTPChannel

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.