Пример #1
0
  /** Flush any buffered output. */
  public synchronized void flush() {
    if (recCount <= 0) {
      if (Debug.messageEnabled()) {
        Debug.message("RemoteHandler.flush(): no records " + "in buffer to send");
      }
      return;
    }
    Vector responses = new Vector();
    if (Debug.messageEnabled()) {
      Debug.message("RemoteHandler.flush(): sending buffered records");
    }

    String thisAMException = null;
    try {
      Iterator sidIter = reqSetMap.keySet().iterator();
      while (sidIter.hasNext()) {
        String currentLoggedBySID = (String) sidIter.next();
        URL logHostURL = getLogHostURL(currentLoggedBySID);
        if (logHostURL == null) {
          Debug.error("RemoteHandler.flush(): logHostURL is null");
          this.recCount = 0;
          reqSetMap = new HashMap();
          return;
        }
        RequestSet reqSet = (RequestSet) reqSetMap.get(currentLoggedBySID);
        responses = PLLClient.send(logHostURL, reqSet);
        Iterator respIter = responses.iterator();
        while (respIter.hasNext()) {
          Response resp = (Response) respIter.next();
          String respContent = resp.getContent();
          if (!respContent.equals("OK")) {
            Debug.error("RemoteHandler.flush(): " + respContent + " on remote machine");
            if (thisAMException == null) {
              thisAMException = "RemoteHandler.flush(): " + respContent + " on remote machine";
            }
          }
        }
      }
    } catch (Exception e) {
      Debug.error("RemoteHandler.flush(): ", e);
    }
    this.recCount = 0;
    reqSetMap = new HashMap();
    if (thisAMException != null) {
      throw new AMLogException(thisAMException);
    }
  }
  protected AmFilterResult handleNotification(AmFilterRequestContext ctx) {
    AmFilterResult result = null;
    String notificationData = getNotificationDataString(ctx.getHttpServletRequest());
    if (isLogMessageEnabled()) {
      logMessage(
          "NotificationTaskHandler.handleNotification:"
              + " notification Data: "
              + NEW_LINE
              + notificationData);
    }
    NotificationSet notificationSet = NotificationSet.parseXML(notificationData);
    Vector notifications = notificationSet.getNotifications();
    if (notifications != null && notifications.size() > 0) {
      String serviceID = notificationSet.getServiceID();
      if (isLogMessageEnabled()) {
        logMessage(
            "NotificationTaskHandler.handleNotification:"
                + " received "
                + serviceID
                + " notification");
      }
      if (serviceID != null) {
        String response = STR_NOTIFICATION_PROCESSING_FAILED;
        if (isServiceNotificationEnabled(serviceID)) {
          NotificationHandler handler = PLLClient.getNotificationHandler(serviceID);
          if (handler == null) {
            logError(
                "NotificationTaskHandler.handleNotification:"
                    + " NotificationHandler for "
                    + serviceID
                    + " not found");
          } else {
            handler.process(notifications);
            response = STR_NOTIFICATION_PROCESSING_SUCCESS;
          }
        }
        result = ctx.getServeDataResult(response);
      }
    }

    return result;
  }
Пример #3
0
    public void run() {
      Vector responses = new Vector();
      if (Debug.messageEnabled()) {
        Debug.message("RemoteHandler.FlushTask.run(): " + "sending buffered records");
      }

      String thisAMException = null;
      try {
        for (String currentLoggedBySID : logReqsMap.keySet()) {
          URL logHostURL = getLogHostURL(currentLoggedBySID);
          if (logHostURL == null) {
            Debug.error("RemoteHandler.FlushTask.run(): " + "logHostURL is null");
            return;
          }
          RequestSet reqSet = (RequestSet) logReqsMap.get(currentLoggedBySID);
          responses = PLLClient.send(logHostURL, reqSet);
          Iterator respIter = responses.iterator();
          while (respIter.hasNext()) {
            Response resp = (Response) respIter.next();
            String respContent = resp.getContent();
            if (!respContent.equals("OK")) {
              Debug.error("RemoteHandler.FlushTask.run(): " + respContent + " on remote machine");
              if (thisAMException == null) {
                thisAMException =
                    "RemoteHandler.FlushTask.run(): " + respContent + " on remote machine";
              }
            }
          }
        }
      } catch (Exception e) {
        Debug.error("RemoteHandler.FlushTask.run(): ", e);
      }

      if (thisAMException != null) {
        throw new AMLogException(thisAMException);
      }
    }
Пример #4
0
  /* process the request */
  private Response processRequest(
      Request req, HttpServletRequest servletReq, HttpServletResponse servletRes) {

    // this call is to create a http session so that the JSESSIONID cookie
    // is created. The appserver(8.1) load balancer plugin relies on the
    // JSESSIONID cookie to set its JROUTE sticky cookie.
    debug.message("=======================Entering processRequest");
    servletReq.getSession(true);

    String content = req.getContent();
    AuthXMLResponse authResponse = null;

    // Check for mis-routed requests
    String cookieURL = null;
    int index = content.indexOf(AuthXMLTags.AUTH_ID_HANDLE);
    if (index != -1) {
      // Check for mis-routed requests, get server URL for
      // AuthIdentifier
      int beginIndex = content.indexOf('"', index);
      int endIndex = content.indexOf('"', beginIndex + 1);
      String authIdentifier = content.substring(beginIndex + 1, endIndex);
      if (debug.messageEnabled()) {
        debug.message(
            "authIdentifier = "
                + authIdentifier
                + "beginIndex = "
                + beginIndex
                + "endIndex ="
                + endIndex);
      }
      if (!authIdentifier.equals("0")) {
        try {
          SessionID sessionID = new SessionID(authIdentifier);
          URL sessionServerURL = SESSION_SERVICE_URL_SERVICE.getSessionServiceURL(sessionID);
          StringBuilder srtBuff = new StringBuilder(100);
          srtBuff
              .append(sessionServerURL.getProtocol())
              .append("://")
              .append(sessionServerURL.getHost())
              .append(":")
              .append(Integer.toString(sessionServerURL.getPort()))
              .append(serviceURI);
          cookieURL = srtBuff.toString();
        } catch (Exception exp) {
          debug.error("Error in getting URL from session", exp);
          cookieURL = null;
        }
      }
    }

    if ((cookieURL != null)
        && (cookieURL.trim().length() != 0)
        && !(AuthUtils.isLocalServer(cookieURL, serviceURI))) {
      // Routing to the correct server, the looks like a mis-routed
      // requested.
      HashMap cookieTable = new HashMap();
      Map headers = new HashMap();
      Enumeration headerNames = servletReq.getHeaderNames();
      while (headerNames.hasMoreElements()) {
        String headerName = (String) headerNames.nextElement();
        List headerValues = new ArrayList();
        Enumeration enum1 = servletReq.getHeaders(headerName);
        while (enum1.hasMoreElements()) {
          headerValues.add(enum1.nextElement());
        }
        headers.put(headerName, headerValues);
      }
      if (debug.messageEnabled()) {
        debug.message("Headers: " + headers);
      }
      PLLClient.parseCookies(headers, cookieTable);
      if (debug.messageEnabled()) {
        debug.message("Cookies: " + cookieTable);
      }
      RequestSet set = new RequestSet(AuthXMLTags.AUTH_SERVICE);
      set.addRequest(req);
      try {
        Vector responses = PLLClient.send(new URL(cookieURL), set, cookieTable);
        if (!responses.isEmpty()) {
          debug.message("=====================Returning redirected");
          return ((Response) responses.elementAt(0));
        }
      } catch (Exception e) {
        debug.error("Error in misrouted ", e);
        // Attempt to contact server failed
        authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
        setErrorCode(authResponse, e);
        return new Response(authResponse.toXMLString());
      }
    }

    // Either local request or new request, handle it locally
    try {
      AuthXMLRequest sreq = AuthXMLRequest.parseXML(content, servletReq);
      sreq.setHttpServletRequest(servletReq);
      authResponse = processAuthXMLRequest(content, sreq, servletReq, servletRes);
    } catch (AuthException e) {
      debug.error("Got Auth Exception", e);
      authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
      authResponse.setErrorCode(e.getErrorCode());
    } catch (Exception ex) {
      debug.error("Error while processing xml request", ex);
      authResponse = new AuthXMLResponse(AuthXMLRequest.NewAuthContext);
      setErrorCode(authResponse, ex);
    }
    debug.message("=======================Returning");
    return new Response(authResponse.toXMLString());
  }