Package org.xmlBlaster.util

Examples of org.xmlBlaster.util.XmlBlasterException


      }
      catch (XmlBlasterException e) {
         throw XmlBlasterException.tranformCallbackException(e);
      }
      catch (Throwable e) {
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,
               "Email oneway callback of message to client [" + callbackAddress.getSecretSessionId() + "] failed", e);
      }
   }
View Full Code Here


    try {
      if (actionType == null) {
        log(getInfo(req, true, true) + "Missing ActionType, ignoring request");
        String msg = getText(req, "noActionType", "Invalid access", null, null);
        cleanupSession(req);
        throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT,
            "AjaxServlet", msg);
      }
     
      if (isBlockedIP(req.getRemoteAddr())) {
        log(getInfo(req, true, true) + "Blocked IP " + req.getRemoteAddr() + ", ignoring request");
        String msg = getText(req, "isBlocked", "Access is currently not allowed", null, null);
        cleanupSession(req);
        throw new XmlBlasterException(Global.instance(), ErrorCode.USER_SECURITY_AUTHENTICATION_ACCESSDENIED,
            "AjaxServlet", msg);
      }
 
      //String host = req.getRemoteAddr();
      //String ME = "AjaxServlet.doGet(" + host + "): ";
      //log.info("ENTERING DOGET ....");
      if (forceLoad)
        log(getInfo(req) + "forceLoad=" + forceLoad);

      if (req.getSession(false) == null) {
        if (maxUserSessionsReached(req)) { // "?admin=true" will ignore this test
          log(getInfo(req, true, true) + "Max user sessions = " + getMaxUserSessions() + " reached, please try again later");
          String msg = getText(req, "maxUserSessionReached", "Max user sessions = {0} reached, please try again later",
              ""+getMaxUserSessions(), null);
          throw new XmlBlasterException(Global.instance(), ErrorCode.USER_CONFIGURATION_MAXSESSION,
              "AjaxServlet", msg);
        }
        HttpSession session = req.getSession(true);
        session.setMaxInactiveInterval(this.maxInactiveInterval);
        newBrowser = true;
        log(getInfo(req, true, false) + "New browser arrived");
      }
    /*
    }
    catch (XmlBlasterException ex) {
      res.setContentType("text/xml; charset=UTF-8");
      PrintWriter backToBrowser = res.getWriter();
      StringBuffer sb = new StringBuffer(512);
      sb.append("<xmlBlasterResponse>");
      sb.append(ex.toXml());
      sb.append("</xmlBlasterResponse>");
      backToBrowser.write(sb.toString());
      backToBrowser.close();
      return;
    }
    */

    // set header field first
    //res.setContentType("text/plain; charset=UTF-8");
    // xml header don't like empty response, so send at least "<void/>
    //res.setContentType("text/xml; charset=UTF-8");
      blasterInstance = getBlasterInstance(req);
      boolean admin = getReqProp(req, "admin", false);
      if (admin) blasterInstance.setAdmin(admin); // can be passed on connect()

      if (actionType.equals("xmlScript")) {
        String xmlScript64 = (String) req.getParameter("xmlScriptBase64");
        String xmlScriptPlain = (String) req.getParameter("xmlScriptPlain");
        byte[] raw = null;
        if (xmlScript64 != null && xmlScriptPlain != null) {
          String errTxt = "You can not set both 'xmlScriptBase64' and 'xmlScriptPlain'";
          throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT, "AjaxServlet", errTxt);
        }
        String xmlScript = xmlScriptPlain;
        if (xmlScript64 != null) {
          // the url encoder has somewhere changed my + to blanks
          // you must send this by invoking encodeURIComponent(txt) on the javascript side.
          xmlScript64 = ReplaceVariable.replaceAll(xmlScript64, " ", "+");
          raw = Base64.decode(xmlScript64);
          xmlScript = new String(raw, "UTF-8");
        } else if (xmlScriptPlain != null) {
          raw = xmlScriptPlain.getBytes();
        } else {
          String errTxt = "You must choose one of 'xmlScriptBase64' and 'xmlScriptPlain' since you choosed 'xmlScript'";
          throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT, "AjaxServlet", errTxt);
        }
        if (newBrowser && xmlScript.indexOf("<connect")==-1)
          throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT, "AjaxServlet", "The first call must contain a connect markup");
        blasterInstance.execute(raw, xmlScript, out);
        return;
      }

      // A request/reply with direct binary streaming of the MsgUnit content
      // back to the browser, can be used e.g. to access backend DB pictures
      // Todo: Add a variant with service response, e.g. &binary=false
      // "/watchee/ajax?ActionType=request&task=getRawPhoto&data=4517&timeout=5000&maxEntries=10"
      else if (actionType.equals("request")) { // request-response pattern, blocking for repsonse
        // "image/gif" "image/jpeg" "image/bmp" "image/x-png" "application/x-msdownload" "video/avi" "video/mpeg"
        long timeout = (req.getParameter("timeout") == null) ? 8000 : Long.valueOf(
            (String) req.getParameter("timeout")).longValue();
        int maxEntries = (req.getParameter("maxEntries") == null) ? 1 : Integer.valueOf(
            (String) req.getParameter("maxEntries")).intValue();
        String topicId = (req.getParameter("topicId") == null) ? "service" : (String) req
            .getParameter("topicId");
        String content = req.getParameter("content");
        String qos = (req.getParameter("qos") == null) ? "<qos/>" : (String) req
            .getParameter("qos");
        if (content == null) {
          String task = (String) req.getParameter("task"); // "getRawPhoto"
          String data = (String) req.getParameter("data"); // "locationPictureId"
          String serviceName = (String) req.getParameter("serviceName");
          if (serviceName == null)
            serviceName = "track";
          String taskType = (String) req.getParameter("taskType");
          if (taskType == null)
            taskType = "named";
          // Service markup: sc=serviceCollection, s=service, p=property
          content = "<sc>" + " <s>" + "  <p k='serviceName'>" + serviceName + "</p>"
              + "  <p k='taskType'>" + taskType + "</p>" + "  <p k='task'>" + task
              + "</p>" + "  <p k='data'>" + data + "</p>" + " </s>" + "</sc>";
        }
        MsgUnit msgUnit = new MsgUnit("<key oid='" + topicId + "'/>", content, qos);
        log(getInfo(req) + "Sending request to " + topicId + ": " + content);
        MsgUnit[] msgUnitArr = blasterInstance.getXmlBlasterAccess().request(msgUnit,
            timeout, maxEntries);
        if (msgUnitArr.length > 0) {
          String contentMime = msgUnitArr[0].getQosData().getClientProperty(
              "contentMime", "image/jpeg");
          res.setContentType(contentMime);
          log(getInfo(req) + "Returning request/reply image '" + contentMime + "' length="
              + msgUnitArr[0].getContent().length);
          out = null;
          ServletOutputStream binOut = res.getOutputStream();
          byte[] buff = msgUnitArr[0].getContent();
          binOut.write(buff, 0, buff.length);
          binOut.flush();
          binOut.close();
        }
        return;
      }

      /* see XbAccess.js/watchee.js for an example:
      In the mode "updatePoll" this script polls every 8000 millis for update
      and the servlet returns directly if nothing is available, this is suboptimal
      as we have a delay of up to 8 seconds.
      In the mode "updatePollBlocking" we don't poll but the servlet blocks our call
      and immediately returns when update messages arrive.
      To prevent from e.g. proxy timeouts the servlet returns after 15sec and we immediately
      poll again.
      */
      // "timeout" and "numEntries" is only evaluated for "updatePollBlocking"
      boolean updatePoll = actionType.equals("updatePoll");
      boolean updatePollBlocking = actionType.equals("updatePollBlocking");
      if (updatePoll || updatePollBlocking) {
       
        if (newBrowser) // The initial call should not be the AjaxPoller
          throw new XmlBlasterException(Global.instance(), ErrorCode.USER_NOT_CONNECTED, "AjaxServlet", "Connection is lost, please login again");
       
        boolean onlyContent = get(req, "onlyContent", false);
        long timeout = get(req, "timeout", (updatePoll) ? 0L : 15000L);
        int numEntries = get(req, "numEntries", -1);
        int count = blasterInstance.sendUpdates(out, onlyContent, numEntries, timeout);
        if (count == 0) { // watchee hack
          if (newBrowser || forceLoad) {
            String initGps = (String) req.getParameter("initGps");
            if (initGps != null && "true".equalsIgnoreCase(initGps.trim())) {
              String tmp = blasterInstance.getStartupPos();
              if (tmp.length() > 0) {
                out.write(tmp);
                log(getInfo(req) + tmp);
              }
            }
          }
        } else
          log(getInfo(req) + " Sending " + count + " received update messages to browser");
        return;
      }

      if (actionType.equals("plainGet")) {
        blasterInstance.plainGet(req, res, out);
      }

      // log(getInfo(req)+"Ignoring identical");
    } catch (XmlBlasterException e) {
      log("newBrowser=" + newBrowser + " forceLoad=" + forceLoad + ": "
          + e.toString());
      // if (newBrowser || forceLoad)
      // out.write(blasterInstance.getStartupPos());
      throwable = e;
    } catch (Throwable e) {
      log("newBrowser=" + newBrowser + " forceLoad=" + forceLoad + ": "
              + e.toString());
      e.printStackTrace();
      throwable = e;
    } finally {
      if (out != null) {
        //res.setContentType("text/xml");
          //res.setCharacterEncoding("UTF-8");
        res.setContentType("text/xml; charset=UTF-8");
        // For HTML: out.println("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" />");
        PrintWriter backToBrowser = res.getWriter();
        if (out.getBuffer().length() > 0)
          log("Sending now '" + out.getBuffer().toString() + "'");
        if (out.getBuffer().length() > 0)
          backToBrowser.write(out.getBuffer().toString());
        else {
          if (throwable != null) {
            StringBuffer sb = new StringBuffer(256);
            sb.append("<xmlBlasterResponse>");
            XmlBlasterException ex = (XmlBlasterException)throwable;
            if (throwable instanceof XmlBlasterException) {
              ex = (XmlBlasterException)throwable;
              if (ex.isErrorCode(ErrorCode.INTERNAL_STOP)) { // XmlScript Sax Parser stopped
                Throwable th = ex.getEmbeddedException();
                if (th != null && th instanceof XmlBlasterException) {
                  ex = (XmlBlasterException)th;
                  //ex.changeErrorCode(((XmlBlasterException)th).getErrorCode());
                }
              }
            }
            else {
              ex = new XmlBlasterException(Global.instance(), ErrorCode.INTERNAL_UNKNOWN, "AjaxServlet", "Unknown problem", throwable);
            }
            sb.append(ex.toXml());
            sb.append("</xmlBlasterResponse>");
            if (blasterInstance != null)
              blasterInstance.shutdown();
            /*
            <xmlBlasterResponse>
 
View Full Code Here

    * This sends the update to the client.
    * @exception e.id="CallbackFailed", should be caught and handled appropriate
    */
   public final String[] sendUpdate(MsgUnitRaw[] msgArr) throws XmlBlasterException {
      if (this.handler == null)
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,
                  "SOCKET sendUpdate failed, the handle is null");
      return this.handler.sendUpdate(callbackAddress.getSecretSessionId(), msgArr,
             SocketExecutor.WAIT_ON_RESPONSE, this.useUdpForOneway, getPluginInfo());
   }
View Full Code Here

    * The oneway variant, without return value.
    * @exception XmlBlasterException Is never from the client (oneway).
    */
   public void sendUpdateOneway(MsgUnitRaw[] msgArr) throws XmlBlasterException {
      if (this.handler == null)
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,
                  "SOCKET sendUpdateOneway failed");
      this.handler.sendUpdate(callbackAddress.getSecretSessionId(), msgArr,
            SocketExecutor.ONEWAY, this.useUdpForOneway, getPluginInfo());
   }
View Full Code Here

      }
      */
     
      SocketExecutor se = this.handler;
      if (se == null)
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,
                  "SOCKET callback ping failed, handler is null");
      try {
         return se.ping(qos);
      } catch (Throwable e) {
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME,
                     "CallbackSocketDriver " + getType() + " callback ping failed", e);
      }
   }
View Full Code Here

      this.ME = "JdbcDriver" + this.glob.getLogPrefixDashed();


      org.xmlBlaster.engine.ServerScope engineGlob = (org.xmlBlaster.engine.ServerScope)glob.getObjectEntry(Constants.OBJECT_ENTRY_ServerScope);
      if (engineGlob == null)
         throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "could not retreive the ServerNodeScope. Am I really on the server side ?");
      try {
         this.authenticate = engineGlob.getAuthenticate();
         if (this.authenticate == null) {
            throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "authenticate object is null");
         }
         I_XmlBlaster xmlBlasterImpl = this.authenticate.getXmlBlaster();
         if (xmlBlasterImpl == null) {
            throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "xmlBlasterImpl object is null");
         }

         init(glob, new AddressServer(glob, getType(), glob.getId(), pluginInfo.getParameters()), this.authenticate, xmlBlasterImpl);
        
         activate();
      }
      catch (XmlBlasterException ex) {
         throw ex;
      }
      catch (Throwable ex) {
         throw new XmlBlasterException(this.glob, ErrorCode.INTERNAL_UNKNOWN, ME + ".init", "init. Could'nt initialize the driver.", ex);
      }
   }
View Full Code Here

      loginName = glob.getProperty().get("JdbcDriver.loginName", "__sys__jdbc");
      passwd = glob.getProperty().get("JdbcDriver.password", "secret");

      if (loginName==null || passwd==null) {
         log.severe("login failed: please use no null arguments for connect()");
         throw new XmlBlasterException("LoginFailed.InvalidArguments", "login failed: please use no null arguments for connect()");
      }

      // "JDBC" below is the 'callback protocol type', which results in instantiation of the given class:
      CallbackAddress cbAddress = new CallbackAddress(glob, "JDBC");
      cbAddress.setRawAddress("native-NameService:org.xmlBlaster.protocol.jdbc.CallbackJdbcDriver");
View Full Code Here

         }
        
        
      }
      catch (IOException ex) {
         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "An exception occured when parsing the string " + literal);
      }
     
      return null;
   }
View Full Code Here

            MsgUnitRaw[] msgUnitArr = ProtoConverter.objMatrix2MsgUnitRawArray(msgUnitArrWrap);
            String[] strArr = blasterNative.publishArr(this.addressServer, sessionId, msgUnitArr);
            return ProtoConverter.stringArray2Vector(strArr);
         }
         else
            throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT, ME, "Empty array to be published");
      }
      catch (ClassCastException e) {
         log.severe("not a valid MsgUnitRaw: " + e.toString());
         throw new XmlBlasterException(Global.instance(), ErrorCode.USER_ILLEGALARGUMENT, ME, "Not a valid Message Unit: Class Cast Exception", e);
      }
   }
View Full Code Here

      // check in the own sessionId pipe if there is some data available, if not wait some time and then
      // return
      // if there are some messages available send them to the client and await an acknowledge or an
      // exception from him.
      if (sessionId == null)
         throw new XmlBlasterException(Global.instance(), ErrorCode.COMMUNICATION_NOCONNECTION_CALLBACKSERVER_NOTAVAILABLE, ME, "no sessionId defined");

      CallbackXmlRpcDriverSingleChannel cb = null;
      synchronized(cbMap) {
         WeakReference<CallbackXmlRpcDriverSingleChannel> tmp = null;
         tmp = cbMap.get(sessionId);
         if (tmp == null) {
            throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION_CALLBACKSERVER_NOTAVAILABLE, ME, "The callback is null (shutdown?)");
            // return null;
         }
         cb = tmp.get();
      }
     
      Object[] ret = new Object[3];
      // 0: methodName
      // 1: refId
      // 2: Vector containing data
      long tmpWaitTime = Long.parseLong(waitTimeTxt);
      long pingInterval = cb.getPingInterval();
      long halfTime = pingInterval/2;
      if (pingInterval > 0 && tmpWaitTime > halfTime)
         waitTime = halfTime;
      else
         waitTime = tmpWaitTime;
        
      boolean contentAsString = asString != null && "true".equals(asString);
     
      if (cb != null) {
         try {
            cb.setCurrentThread(Thread.currentThread());
            cb.respan("XmlBlasterImpl.updateRequest-before.blocking");
            try {
               while (true) {
                  LinkedQueue updQueue = cb.getUpdateQueue();
                  if (updQueue == null)
                     throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION_CALLBACKSERVER_NOTAVAILABLE, ME, "The callback is shutdown");
                  UpdateEvent ue = (UpdateEvent)updQueue.poll(this.waitTime);
                  if (ue != null) {
                     String methodName = ue.getMethod();
                     long refId = ue.getUniqueId();
                     ret[0] = methodName;
                     ret[1] = "" + refId;
                     if ("update".equals(methodName))  {
                        ret[2] = ProtoConverter.messageUnitArray2Vector(contentAsString, ue.getMsgUnit());
                        cb.respan("XmlBlasterImpl.updateRequest-after-update");
                        return ret;
                     }
                     else if ("updateOneway".equals(methodName)) {
                        ret[2] = ProtoConverter.messageUnitArray2Vector(contentAsString, ue.getMsgUnit());
                        cb.respan("XmlBlasterImpl.updateRequest-after-updateOneway");
                        return ret;
                     }
                     else {
                        log.severe("The method '" + methodName + "' is unkown in this context and should not occur, will ignore it");
                     }
                  }
                  else {
                     cb.respan("XmlBlasterImpl.updateRequest-no-event");
                     return null; // better chance next time
                  }
               }
            }
            catch (InterruptedException ex) {
               // removeCallback(sessionId);
               // throw new XmlBlasterException(glob, ErrorCode.INTERNAL_INTERRUPTED, ME, "The update has been interrupted");
               return null;
            }
         }
         finally {
            cb.setCurrentThread(null);
         }
      }
      else {
         removeCallback(sessionId, "callback was null, i.e. garbage collector has removed it when it still was in map");
         throw new XmlBlasterException(Global.instance(), ErrorCode.INTERNAL_ILLEGALSTATE, ME, "No callback found for session " + sessionId);
      }
   }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.XmlBlasterException

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.