Package org.xmlBlaster.util.xbformat

Examples of org.xmlBlaster.util.xbformat.MsgInfo


               final MsgInfo[] msgInfoArr = MsgInfo.parse(glob, progressListener, iStream, getMsgInfoParserClassName(), driver.getPluginConfig());
               if (msgInfoArr.length < 1) {
                  log.warning(toString() + ": Got unexpected empty data from SOCKET, closing connection now");
                  break;
               }
               final MsgInfo msgInfo = msgInfoArr[0];

               if (this.callCoreInSeparateThread) {
                  executorService.execute(new Runnable() {
                     public void run() {
                        handleMessage(msgInfo, false);
View Full Code Here


      if (!isConnected())
         throw new XmlBlasterException(glob, ErrorCode.COMMUNICATION_NOCONNECTION, ME, "ping() invocation ignored, we are shutdown.");

      try {
         String cbSessionId = "";
         MsgInfo parser = new MsgInfo(glob, MsgInfo.INVOKE_BYTE, MethodName.PING, cbSessionId);
         parser.addMessage(qos);
         Object response = requestAndBlockForReply(parser, SocketExecutor.WAIT_ON_RESPONSE, SocketUrl.SOCKET_TCP);
         return (String)response;
      }
      catch (Throwable e) {
         if (log.isLoggable(Level.FINE)) log.fine("IO exception: " + e.toString());
View Full Code Here

            log.info("Started successfully " + getType() + " UDP driver on '" + socketUrl.getUrl() + "'");

            byte packetBuffer[] = new byte[MAX_PACKET_SIZE];
            DatagramPacket packet = new DatagramPacket(packetBuffer, packetBuffer.length);
            MsgInfo receiver = null;
            listenerReadyUDP = true;
            while (runningUDP) {
               try {
                  socketUDP.receive(packet);
               }
               catch (IOException e) {
                  if (e.toString().indexOf("closed") == -1) {
                     log.severe("Error receiving packet from '" + socketUrl.getUrl() + "' : " + e.toString());
                  }
                  else {
                     if (log.isLoggable(Level.FINE)) log.fine("UDP datagram socket shutdown '" + socketUrl.getUrl() + "' : " + e.toString());
                  }
                  return;
               }
               if (log.isLoggable(Level.FINE))
                  log.fine("UDP packet arrived, size=" + packet.getLength() + " bytes");
               if (!runningUDP) {
                  log.info("Closing server '" + socketUrl.getUrl() + "'");
                  return;
               }
               int actualSize = packet.getLength();
               if (packet.getLength() > MAX_PACKET_SIZE) {
                  log.warning("Packet has been truncated, size=" + packet.getLength() + ", MAX_PACKET_SIZE=" + MAX_PACKET_SIZE);
                  actualSize = MAX_PACKET_SIZE;
               }
               InputStream iStream = new ByteArrayInputStream(packet.getData(), 0, actualSize);
               try {
                  receiver = MsgInfo.parse(glob, null, iStream, null/*getMsgInfoParserClassName()*/, getPluginConfig())[0];
               }
               catch (Throwable e) {
                  log.severe("Error parsing data from UDP packet: " + e);
                  continue;
               }
               String sessionId = receiver.getSecretSessionId();
               HandleClient hh = getClient(sessionId);
               if (hh == null)
                  log.severe("Request from unknown client, sessionId: " + sessionId);
               else
                  hh.handleMessage(receiver, true);
View Full Code Here

      InputStream is = new ByteArrayInputStream(literal.getBytes());
      try {
         MsgInfo[] msgInfoArr = parser.parse(is);
         if (msgInfoArr != null) {
            for (int i=0; i < msgInfoArr.length; i++) {
               MsgInfo msgInfo = msgInfoArr[i];
               MethodName method = msgInfo.getMethodName();
               String sessionId = msgInfo.getSecretSessionId();
               MsgUnitRaw[] msgUnitRawArr = msgInfo.getMessageArr();
               String key = null;
               MsgUnitRaw msgUnitRaw = null;
              
               if (msgUnitRawArr != null && msgUnitRawArr.length > 0) {
                  msgUnitRaw = msgUnitRawArr[0];
                  key = msgUnitRaw.getKey();
               }
               String qos = msgInfo.getQos();
              
               if (method.isConnect()) {
                 
               }
               else if (method.isDisconnect()) {
View Full Code Here

      InputStream is = new ByteArrayInputStream(literal.getBytes());
      try {
         MsgInfo[] msgInfoArr = parser.parse(is);
         if (msgInfoArr != null) {
            for (int i=0; i < msgInfoArr.length; i++) {
               MsgInfo msgInfo = msgInfoArr[i];
               String sessionId = msgInfo.getSecretSessionId();
               String qos = msgInfo.getQos();
               MethodName method = msgInfo.getMethodName();
               if (method.isConnect()) {
                  return connect(qos);
               }
               else if (method.isDisconnect()) {
                  return disconnect(sessionId, qos);
View Full Code Here

      String requestId = null;
      try {
         // We use the RequestReplyExecutor.java for the request/reply pattern

         MsgInfo msgInfo = new MsgInfo(this.glob, MsgInfo.INVOKE_BYTE, methodName,
               getSecretSessionId(), super.getProgressListener());
         msgInfo.addMessage(msgArr);
         requestId = msgInfo.createRequestId(null);

         if (expectingResponse) { // register at the POP3 poller
            getPop3Driver().registerForEmail(getEmailSessionId(), requestId, this);
         }
View Full Code Here

            log.warning("Unexpected msgInfo with length==0, requestId=" + requestId + " data=" + emailData.toXml(true));
            Thread.dumpStack();
            return;
         }
         for (int j=0; j<msgInfos.length; j++) {
            MsgInfo msgInfo = msgInfos[j];
            msgInfo.setRequestIdGuessed(emailData.isRequestIdFromSentDate());
            msgInfo.setBounceObject(BOUNCE_MAILFROM_KEY, emailData.getFrom());
            // The messageId could be in the subject and not in the attachment
            msgInfo.setBounceObject(BOUNCE_MESSAGEID_KEY, emailData.getMessageId(messageIdFileName));
            AttachmentHolder[] attachments = emailData.getAttachments();
            for (int i=0; i<attachments.length; i++) {
               AttachmentHolder a = attachments[i];
               if (a == msgUnitAttachmentHolder)
                  continue;
               // TODO: Determine which attachments to bounce
               msgInfo.setBounceObject(a.getFileName(), a);
            }
         }

      } catch (Throwable e) {
         log.warning("Error parsing email data from "
                           + pop3Url
                           + ", check if client and server have identical compression settings: "
                           + e.toString() + ": " + emailData.toXml(true));
         return;
      }

      // Response and Exception messages should NEVER expire
      if (emailData.isExpired(messageIdFileName) && msgInfos[0].isInvoke()) {
         log.warning("Message is expired, we discard it: " + emailData.toString());
         return;
      }

      // For XmlScript && INVOKE we could have multiple message bundled
      // else length is always 1!
      for (int i=0; i<msgInfos.length; i++) {
         MsgInfo msgInfo = msgInfos[i];
         // If counterside has stripped information we add it again from the messageId attachment
         if (msgInfo.getRequestId().length() == 0)
            msgInfo.setRequestId(emailData.getRequestId(messageIdFileName));
         if (msgInfo.getSecretSessionId().length() == 0)
            msgInfo.setSecretSessionId(emailData.getSessionId(messageIdFileName));
  
         try {
            if (i==0 && msgInfo.isInvoke()) {
               if (isLoopingMail(msgInfo, emailData))
                  return;
            }
  
            /*
              Memory leak cleanup is handled by EmailDriver.java on LogoutEvent
              if (MethodName.DISCONNECT.equals(msgInfo.getMethodName())) {
                removeFromLoopProtection(emailData.getFrom());
              }
            */
           
            // This wakes up the blocking thread of sendEmail() and returns the
            // returnQos or the received invocation
            // On server side it typically invokes the core connect() or publish() etc.
            if (receiveReply(msgInfo, false) == false) {
               log.warning("Error parsing email data from "
                     + getPop3Driver().getPop3Url()
                     + ", CONNECT etc is not yet implemented");
            }
           
            if (i==0 && msgInfos.length > 1 && MethodName.CONNECT.equals(msgInfo.getMethodName())) {
               // If multiple requests where bundled pass the others the secret session id
               for (int k=1; k<msgInfos.length; k++)
                  msgInfos[k].setSecretSessionId(msgInfo.getSecretSessionId());
            }
         } catch (Throwable e) {
            if (log.isLoggable(Level.FINE))
               e.printStackTrace();
            log.warning("Can't process email data from "
View Full Code Here

      File file = new File(subDir, fileId);
      if (file.exists())
         log.warning("File '" + file.getAbsolutePath() + "' exists already. Will overwrite it");
      FileOutputStream fos = new FileOutputStream(file);
      MsgUnitRaw msgUnitRaw = new MsgUnitRaw(msgUnit.getKey(), msgUnit.getContent(), msgUnit.getQos());
      MsgInfo msgInfo = new MsgInfo(this.global, MsgInfo.INVOKE_BYTE, MethodName.UPDATE_ONEWAY, this.slaveSessionId);
      msgInfo.addMessage(msgUnitRaw);
      XmlScriptParser parser = new XmlScriptParser();
      parser.init(new Global(), null, null);
      fos.write(parser.toLiteral(msgInfo).getBytes());
      fos.close();
      log.info("MsgUnit '" + msgUnit.getQosData().getRcvTimestamp().getTimestamp() + "' has been written to file '" + file.getAbsolutePath() + "'");
View Full Code Here

         server.initialize(this.glob, getLoginName(), cba, this.cbClient);
         // NOTE: This happens only if the client has no callback configured, we create a faked one here (as the SOCKET plugin needs it)
      }

      try {
         MsgInfo parser = new MsgInfo(glob, MsgInfo.INVOKE_BYTE, MethodName.CONNECT, sessionId); // sessionId is usually null on login, on reconnect != null
         parser.setPluginConfig(this.pluginInfo);
         parser.addMessage(connectQos);
         return (String)getCbReceiver().requestAndBlockForReply(parser, SocketExecutor.WAIT_ON_RESPONSE, SocketUrl.SOCKET_TCP);
      }
      catch (XmlBlasterException e) {
         throw e;
      }
View Full Code Here

    * Send a one way response message back to the other side
    */
   protected final void executeResponse(MsgInfo receiver, Object response, boolean udp) throws XmlBlasterException, IOException {

      // Take a clone:
      MsgInfo returner = receiver.createReturner(MsgInfo.RESPONSE_BYTE);

      if (response instanceof String)
         returner.addMessage((String)response);
      else if (response instanceof String[])
         returner.addMessage((String[])response);
      else if (response instanceof MsgUnitRaw[])
         returner.addMessage((MsgUnitRaw[])response);
      else if (response instanceof MsgUnitRaw)
         returner.addMessage((MsgUnitRaw)response);
      else
         throw new XmlBlasterException(glob, ErrorCode.INTERNAL_ILLEGALARGUMENT, ME, "Invalid response data type " + response.toString());
      sendMessage(returner, receiver.getRequestId(), receiver.getMethodName(), udp);
      if (log.isLoggable(Level.FINE)) log.fine("Successfully sent response for " + receiver.getMethodName() + "(" + receiver.getRequestId() + ")");
      if (log.isLoggable(Level.FINEST)) log.finest("Successful sent response for " + receiver.getMethodName() + "() >" + returner.toLiteral() + "<");
   }
View Full Code Here

TOP

Related Classes of org.xmlBlaster.util.xbformat.MsgInfo

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.