Examples of HTTPChannel


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

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

      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

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

         {
            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

Examples of org.apache.tomcat.lite.http.HttpChannel

    static Tomcat main = TomcatStandaloneMain.setUp(port);

    public void testSimple() throws IOException {
        HttpConnector clientCon = HttpClient.newClient();

        HttpChannel ch = clientCon.get("localhost", port);
        ch.getRequest().setRequestURI("/index.html");
        ch.getRequest().send();

        BBuffer res = ch.readAll(null, 0);

        assertTrue(res.toString(),
                res.toString().indexOf("<title>Apache Tomcat</title>") >= 0);
    }
View Full Code Here

Examples of org.apache.tomcat.lite.http.HttpChannel

            int port = 443;
            if (hostPort.length > 1) {
                port = Integer.parseInt(hostPort[1]);
            }
            if (log.isLoggable(Level.FINE)) {
                HttpChannel server = serverHttpReq.getHttpChannel();
                log.info("NEW: " + server.getId() + " " + dstHost + " "  +
                        server.getRequest().getMethod() +
                        " " + server.getRequest().getRequestURI() + " " +
                        server.getIn());
            }

            try {
                getSelector().connect(host, port,
                        new ProxyConnectClientConnection(serverHttpReq.getHttpChannel()));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return;
        }


        CBuffer origURIx = serverHttpReq.requestURI();
//        String origURI = origURIx.toString();
//        if (origURI.startsWith("http://")) {
//            // Real proxy - extract client address, modify the uri.
//            // TODO: optimize the strings.
//            int start = origURI.indexOf('/', 7);
//            String hostPortS = (start == -1) ?
//                    origURI.subSequence(7, origURI.length()).toString() :
//                    origURI.subSequence(7, start).toString();
//            String[] hostPort = hostPortS.split(":");
//
//            dstHost = hostPort[0];
//            dstPort = (hostPort.length > 1) ? Integer.parseInt(hostPort[1]) :
//                80;
//
//            if (start >= 0) {
//                serverHttpReq.requestURI().set(origURI.substring(start));
//            } else {
//                serverHttpReq.requestURI().set("/");
//            }
//        } else {
            // Adjust the host header.
            CBuffer hostHdr =
                serverHttpReq.getMimeHeaders().getHeader("host");
            if (hostHdr != null) {
                hostHdr.recycle();
                CBuffer cb = hostHdr;
                cb.append(dstHost);
                if (dstPort != 80) {
                    cb.append(':');
                    cb.appendInt(dstPort);
                }
            }
//        }
        if (debug) {
            HttpChannel server = serverHttpReq.getHttpChannel();
            log.info("START: " + server.getId() + " " + dstHost + " "  +
                    server.getRequest().getMethod() +
                    " " + server.getRequest().getRequestURI() + " " +
                    server.getIn());
        }

        // Send the request with a non-blocking write
        HttpChannel serverHttp = serverHttpReq.getHttpChannel();

        // Client connection
        HttpChannel httpClient = getHttpConnector().get(dstHost, dstPort);

        serverHttp.getRequest().setAttribute("CLIENT", httpClient);
        httpClient.getRequest().setAttribute("SERVER", serverHttp);
        serverHttp.getRequest().setAttribute("P", httpClient);
        httpClient.getRequest().setAttribute("P", serverHttp);

        httpClient.setHttpService(clientHeadersReceived);

        // Will send the original request (TODO: small changes)
        // Response is not affected ( we use the callback )
        httpClient.getRequest().method().set(serverHttp.getRequest().method());
        httpClient.getRequest().requestURI().set(serverHttp.getRequest().requestURI());
        if (serverHttp.getRequest().queryString().length() != 0) {
            httpClient.getRequest().queryString().set(serverHttp.getRequest().queryString());
        }

        httpClient.getRequest().protocol().set(serverHttp.getRequest().protocol());

        //cstate.reqHeaders.addValue(name)
        copyHeaders(serverHttp.getRequest().getMimeHeaders(),
                httpClient.getRequest().getMimeHeaders() /*dest*/);

        // For debug
        httpClient.getRequest().getMimeHeaders().remove("Accept-Encoding");

        if (!keepOpen) {
            httpClient.getRequest().getMimeHeaders().setValue("Connection").set("Close");
        }

        // Any data
        serverHttp.setDataReceivedCallback(copy);
        copy.handleReceived(serverHttp);

        httpClient.send();


        //serverHttp.handleReceived(serverHttp.getSink());
        //httpClient.flush(); // send any data still there

        httpClient.setCompletedCallback(done);
        // Will call release()
        serverHttp.setCompletedCallback(done);

        serverHttpReq.async();
    }
View Full Code Here

Examples of org.apache.tomcat.lite.http.HttpChannel

         * Headers received from the client (content http server).
         * TODO: deal with version missmatches.
         */
        @Override
        public void service(HttpRequest clientHttpReq, HttpResponse clientHttpRes) throws IOException {
            HttpChannel serverHttp = (HttpChannel) clientHttpReq.getAttribute("SERVER");

            try {
                serverHttp.getResponse().setStatus(clientHttpRes.getStatus());
                serverHttp.getResponse().getMessageBuffer().set(clientHttpRes.getMessageBuffer());
                copyHeaders(clientHttpRes.getMimeHeaders(),
                        serverHttp.getResponse().getMimeHeaders());

                serverHttp.getResponse().getMimeHeaders().addValue("TomcatProxy").set("True");

                clientHttpReq.getHttpChannel().setDataReceivedCallback(copy);
                copy.handleReceived(clientHttpReq.getHttpChannel());

                serverHttp.startSending();


                //clientHttpReq.flush(); // send any data still there

                //  if (clientHttpReq.getHttpChannel().getIn().isClosedAndEmpty()) {
View Full Code Here

Examples of org.apache.tomcat.lite.http.HttpChannel

        public HttpDoneCallback() {
        }

        @Override
        public void handle(HttpChannel doneCh, Object extraData) throws IOException {
            HttpChannel serverCh =
                (HttpChannel) doneCh.getRequest().getAttribute("SERVER");
            HttpChannel clientCh = doneCh;
            String tgt = "C";
            if (serverCh == null) {
                 serverCh = doneCh;
                 clientCh =
                    (HttpChannel) doneCh.getRequest().getAttribute("CLIENT");
                 tgt = "S";
            }
            if (serverCh == null || clientCh == null) {
                return;
            }
            if (doneCh.getError()) {
                serverCh.abort("Proxy error");
                clientCh.abort("Proxy error");
                return;
            }

            if (log.isLoggable(Level.FINE)) {
                HttpChannel peerCh =
                    (HttpChannel) doneCh.getRequest().getAttribute("SERVER");
                if (peerCh == null) {
                    peerCh =
                        (HttpChannel) doneCh.getRequest().getAttribute("CLIENT");
                } else {

                }
                log.info(tgt + " " + peerCh.getId() + " " +
                        doneCh.getTarget() + " " +
                        doneCh.getRequest().getMethod() +
                        " " + doneCh.getRequest().getRequestURI() + " " +
                        doneCh.getResponse().getStatus() + " IN:" + doneCh.getIn()
                        + " OUT:" + doneCh.getOut() +
                        " SIN:" + peerCh.getIn() +
                        " SOUT:" + peerCh.getOut() );
            }
            // stop forwarding. After this call the client object will be
            // recycled
            //clientCB.outBuffer = null;
View Full Code Here

Examples of org.apache.tomcat.lite.http.HttpChannel

    public EchoCallback() {
    }

    @Override
    public void service(HttpRequest req, HttpResponse res) throws IOException {
        HttpChannel sproc = req.getHttpChannel();
        res.setStatus(200);
        res.setContentType(contentType);

        IOBuffer tmp = new IOBuffer(null);
        Http11Connection.serialize(req, tmp);

        sproc.getOut().append("REQ HEAD:\n");
        sproc.getOut().append(tmp.readAll(null));
        IOBuffer reqBuf = sproc.getOut();

        reqBuf.append("\nCONTENT_LENGTH:")
            .append(Long.toString(req.getContentLength()))
            .append("\n");
//
View Full Code Here

Examples of org.eclipse.jetty.client.HttpChannel

    @Override
    protected void send(HttpExchange exchange)
    {
        normalizeRequest(exchange.getRequest());
        // One connection maps to N channels, so for each exchange we create a new channel
        HttpChannel channel = new HttpChannelOverSPDY(getHttpDestination(), this, session);
        channels.add(channel);
        channel.associate(exchange);
        channel.send();
    }
View Full Code Here

Examples of org.eclipse.jetty.server.HttpChannel

                @Override
                public void sessionCreated(HttpSessionEvent se)
                {                   
                    //if current request is authenticated, then as we have just created the session, mark it as secure, as it has not yet been returned to a user
                    HttpChannel channel = HttpChannel.getCurrentHttpChannel();             
                   
                    if (channel == null)
                        return;
                    Request request = channel.getRequest();
                    if (request == null)
                        return;
                   
                    if (request.isSecure())
                    {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.