예제 #1
0
 // Default implementation
 public void setBlock(Player player, World level, Position pos, int mode, int type) {
   logger.debug("Setting block mode {} type {}", mode, type);
   if (mode == 1 && false && !player.isAuthorized(Permission.BUILD)) {
     logger.info("Not permitted to build.");
     try {
       //	player.getSession().getActionSender().sendBlock(pos,
       // level.getBlock(pos),level.getBlockMeta(pos));
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } else if (mode == 0 && false && !player.isAuthorized(Permission.DESTROY)) {
     logger.info("Not permitted to destroy.");
     try {
       //	player.getSession().getActionSender().sendBlock(pos, level.getBlock(pos),
       // level.getBlockMeta(pos));
     } catch (Exception e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } else {
     logger.debug("Building is OK!");
     level.setBlock(pos, (byte) (mode == 1 ? type : 0));
   }
 }
예제 #2
0
  public void processResponse(ResponseEvent responseReceivedEvent) {

    // Log.info("Registering response...." + sipCallId);

    Response response = (Response) responseReceivedEvent.getResponse();
    int statusCode = response.getStatusCode();
    String method = ((CSeqHeader) response.getHeader(CSeqHeader.NAME)).getMethod();

    Log.debug("Got response " + response);

    if (statusCode == Response.OK) {
      isRegistered = true;

      Log.info(
          "Voice bridge successfully registered with "
              + registrar
              + " for "
              + proxyCredentials.getXmppUserName());
      PluginImpl.sipRegisterStatus = "Registered ok with " + proxyCredentials.getHost();

      sipServerCallback.removeSipListener(sipCallId);

    } else if (statusCode == Response.UNAUTHORIZED
        || statusCode == Response.PROXY_AUTHENTICATION_REQUIRED) {

      if (method.equals(Request.REGISTER)) {
        CSeqHeader cseq = (CSeqHeader) response.getHeader(CSeqHeader.NAME);

        if (cseq.getSequenceNumber() < 2) {

          ClientTransaction regTrans =
              SipService.handleChallenge(
                  response, responseReceivedEvent.getClientTransaction(), proxyCredentials);

          if (regTrans != null) {
            try {
              regTrans.sendRequest();

            } catch (Exception e) {

              Log.info("Registration failed, cannot send transaction " + e);
              PluginImpl.sipRegisterStatus = "Registration error " + e.toString();
            }

          } else {
            Log.info("Registration failed, cannot create transaction");
            PluginImpl.sipRegisterStatus = "Registration cannot create transaction";
          }

        } else {
          Log.info("Registration failed " + responseReceivedEvent);
          PluginImpl.sipRegisterStatus = "Registration failed";
        }
      }

    } else {
      Log.info("Unrecognized response:  " + response);
    }
  }
 @Transactional(readOnly = true)
 public SorPerson findByPersonIdAndSorIdentifier(
     final Long personId, final String sorSourceIdentifier) {
   try {
     return this.personRepository.findByPersonIdAndSorIdentifier(personId, sorSourceIdentifier);
   } catch (final Exception e) {
     logger.debug(e.getMessage(), e);
     return null;
   }
 }
예제 #4
0
 private void handleException(Exception e) {
   if (INTERRUPTED_EXCEPTION_TYPES.contains(e.getClass())) {
     LOG.info("Changes feed was interrupted");
   } else {
     LOG.error("Caught exception while listening to changes feed:", e);
   }
 }
예제 #5
0
 public void executeCommand(String cmd, String LogName1, String dir) throws Exception {
   Runtime run = Runtime.getRuntime();
   Process pr = null;
   log.info("Executing the command and getting the log file...");
   StringBuffer sb = new StringBuffer(30000);
   try {
     pr = run.exec(cmd);
     log.info(cmd + " executed successfully!!!");
   } catch (Exception e) {
     log.info(cmd + " couldn't be executed with error message: " + e.getMessage());
   }
   InputStream is = null;
   is = pr.getInputStream();
   int c = 0;
   try {
     while ((c = is.read()) != -1) {
       sb.append((char) c);
     }
   } catch (Exception e) {
     log.info("There is an exception: While appending in the file " + e.getMessage());
     e.printStackTrace();
   } finally {
     if (is != null) {
       try {
         is.close();
       } catch (Exception localException) {
         log.info("There is an exception: " + localException.getMessage());
         localException.printStackTrace();
       }
     }
   }
   try {
     File filename = new File(dir, LogName1);
     FileUtil.writeToTextFile(sb.toString(), filename);
     log.info("process comp.." + pr.waitFor());
   } catch (Exception e) {
     log.info("Problem while writing log to a log file with error stack " + e.getMessage());
   }
   pr = null;
 }
예제 #6
0
파일: Parser.java 프로젝트: nagyistge/jnats
  protected void parse(byte[] buf, int len) throws ParseException {
    int i;
    byte b;
    boolean error = false;

    //		if (len > buf.length) {
    //			throw new ParseException(String.format("Parse length(%d) > actual buffer length(%d)\n",
    // len, buf.length),0);
    //		}
    //		String tmpStr = new String(buf, 0, len);
    //		System.err.printf("#####     Parsing buf=[%s], ps.argBuf=[%s]\n", tmpStr.trim(), ps.argBuf);

    for (i = 0; i < len; i++) {
      b = buf[i];

      //          printStatus(buf, i);

      switch (ps.state) {
        case OP_START:
          switch (b) {
            case 'M':
            case 'm':
              ps.state = NatsOp.OP_M;
              break;
            case 'P':
            case 'p':
              ps.state = NatsOp.OP_P;
              break;
            case '+':
              ps.state = NatsOp.OP_PLUS;
              break;
            case '-':
              ps.state = NatsOp.OP_MINUS;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_M:
          switch (b) {
            case 'S':
            case 's':
              ps.state = NatsOp.OP_MS;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MS:
          switch (b) {
            case 'G':
            case 'g':
              ps.state = NatsOp.OP_MSG;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MSG:
          switch (b) {
            case ' ':
            case '\t':
              ps.state = NatsOp.OP_MSG_SPC;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MSG_SPC:
          switch (b) {
            case ' ':
            case '\t':
              continue;
            default:
              ps.state = NatsOp.MSG_ARG;
              ps.as = i;
              break;
          }
          break;
        case MSG_ARG:
          switch (b) {
            case '\r':
              ps.drop = 1;
              break;
            case '\n':
              ByteBuffer arg = null;
              if (ps.argBuf != null) {
                // End of args
                arg = ps.argBuf;
                arg.flip();
                processMsgArgs(arg.array(), arg.arrayOffset(), arg.limit());
              } else {
                //                        	arg = ByteBuffer.wrap(buf, ps.as,
                // i-ps.drop-ps.as).slice();
                processMsgArgs(buf, ps.as, i - ps.drop - ps.as);
              }
              //                		System.err.printf("arrayOffset=%d, length=%d\n",
              // arg.arrayOffset(), arg.limit());
              //						processMsgArgs(arg.array(), arg.arrayOffset(), arg.limit());

              ps.drop = 0;
              ps.as = i + 1;
              ps.state = NatsOp.MSG_PAYLOAD;

              // jump ahead with the index. If this overruns
              // what is left we fall out and process split
              // buffer.
              i = ps.as + ps.ma.size - 1;
              break;
            default:
              // We have a leftover argBuf we'll continuing filling
              if (ps.argBuf != null) {
                try {
                  ps.argBuf.put(b);
                } catch (Exception e) {
                  System.err.printf("i=%d, b=%c, ps.argBuf=%s\n", i, (char) b, ps.argBuf);
                  e.printStackTrace();
                }
              }
              break;
          }
          break;
        case MSG_PAYLOAD:
          boolean done = false;
          //                	System.err.printf("MSG_PAYLOAD: ps.ma.size = %d\n", ps.ma.size);
          //            		System.err.printf("ps.msgBuf.position=%d, i=%d, ps.as=%d,
          // ps.ma.size=%d\n",
          //            				ps.msgBuf.position(), i, ps.as, ps.ma.size);
          if (ps.msgBuf != null) {
            //                		System.err.printf("ps.msgBuf.position=%d, i=%d, ps.as=%d,
            // ps.ma.size=%d\n",
            //                				ps.msgBuf.position(), i, ps.as, ps.ma.size);
            // Already have bytes in the buffer
            if (ps.msgBuf.position() >= ps.ma.size) {
              ps.msgBuf.flip();
              nc.processMsg(ps.msgBuf.array(), 0, ps.msgBuf.limit());
              done = true;
            } else {
              // copy as much as we can to the buffer and skip ahead.
              int toCopy = ps.ma.size - ps.msgBuf.limit();
              int avail = len - i;

              if (avail < toCopy) {
                toCopy = avail;
              }

              //            				System.err.printf("msgBuf=%s(remaining=%d), i=%d, len=%d,
              // ps.ma.size=%d, avail = %d, toCopy=%d,"
              //            						+ " buf.length=%d\n",
              //            						ps.msgBuf, ps.msgBuf.remaining(), i, len, ps.ma.size, avail,
              // toCopy, buf.length);
              if (toCopy > 0) {
                //                				System.err.printf("msgBuf=%s(remaining=%d), i=%d, len=%d,
                // ps.ma.size=%d, avail = %d, toCopy=%d,"
                //                						+ " buf.length=%d\n",
                //                						ps.msgBuf, ps.msgBuf.remaining(), i, len, ps.ma.size, avail,
                // toCopy, buf.length);
                ps.msgBuf.put(buf, i, toCopy);
                // Update our index
                i += toCopy - 1;
              } else {
                ps.msgBuf.put(b);
              }
            }
          } else if (i - ps.as >= ps.ma.size) {
            //                		System.err.printf("i=%d, ps.as=%d, ps.ma.size=%d\n", i, ps.as,
            // ps.ma.size);
            // If we are at or past the end of the payload, go ahead and process it, no
            // buffering needed.
            nc.processMsg(buf, ps.as, i - ps.as); // pass offset and length
            done = true;
          }

          if (done) {
            ps.argBuf = null;
            //                		ps.argBuf.clear();
            ps.msgBuf = null;
            //                		ps.msgBuf.clear();
            ps.state = NatsOp.MSG_END;
          }

          break;
        case MSG_END:
          switch (b) {
            case '\n':
              ps.drop = 0;
              ps.as = i + 1;
              ps.state = NatsOp.OP_START;
              break;
            default:
              continue;
          }
          break;
        case OP_PLUS:
          switch (b) {
            case 'O':
            case 'o':
              ps.state = NatsOp.OP_PLUS_O;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PLUS_O:
          switch (b) {
            case 'K':
            case 'k':
              ps.state = NatsOp.OP_PLUS_OK;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PLUS_OK:
          switch (b) {
            case '\n':
              nc.processOK();
              ps.drop = 0;
              ps.state = NatsOp.OP_START;
              break;
          }
          break;
        case OP_MINUS:
          switch (b) {
            case 'E':
            case 'e':
              ps.state = NatsOp.OP_MINUS_E;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MINUS_E:
          switch (b) {
            case 'R':
            case 'r':
              ps.state = NatsOp.OP_MINUS_ER;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MINUS_ER:
          switch (b) {
            case 'R':
            case 'r':
              ps.state = NatsOp.OP_MINUS_ERR;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MINUS_ERR:
          switch (b) {
            case ' ':
            case '\t':
              ps.state = NatsOp.OP_MINUS_ERR_SPC;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_MINUS_ERR_SPC:
          switch (b) {
            case ' ':
            case '\t':
              continue;
            default:
              ps.state = NatsOp.MINUS_ERR_ARG;
              ps.as = i;
              break;
          }
          break;
        case MINUS_ERR_ARG:
          switch (b) {
            case '\r':
              ps.drop = 1;
              break;
            case '\n':
              ByteBuffer arg = null;
              if (ps.argBuf != null) {
                arg = ps.argBuf;
                ps.argBuf = null;
              } else {
                arg = ByteBuffer.wrap(buf, ps.as, i - ps.as);
              }
              nc.processErr(arg);
              ps.drop = 0;
              ps.as = i + 1;
              ps.state = NatsOp.OP_START;
              break;
            default:
              if (ps.argBuf != null) {
                ps.argBuf.put(b);
              }
              break;
          }
          break;
        case OP_P:
          switch (b) {
            case 'I':
            case 'i':
              ps.state = NatsOp.OP_PI;
              break;
            case 'O':
            case 'o':
              ps.state = NatsOp.OP_PO;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PO:
          switch (b) {
            case 'N':
            case 'n':
              ps.state = NatsOp.OP_PON;
              break;
            default:
              //                            parseError(buf, i);
              error = true;
              break;
          }
          break;
        case OP_PON:
          switch (b) {
            case 'G':
            case 'g':
              ps.state = NatsOp.OP_PONG;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PONG:
          switch (b) {
            case '\n':
              nc.processPong();
              ps.drop = 0;
              ps.state = NatsOp.OP_START;
              break;
            default:
              break;
          }
          break;
        case OP_PI:
          switch (b) {
            case 'N':
            case 'n':
              ps.state = NatsOp.OP_PIN;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PIN:
          switch (b) {
            case 'G':
            case 'g':
              ps.state = NatsOp.OP_PING;
              break;
            default:
              error = true;
              break;
          }
          break;
        case OP_PING:
          switch (b) {
            case '\n':
              nc.processPing();
              ps.drop = 0;
              ps.state = NatsOp.OP_START;
              break;
          }
          break;
        default:
          error = true;
          break;
      } // switch(ps.state)

      if (error) {
        error = false;
        throw new ParseException(
            String.format("nats: parse error [%s]: '%s'", ps.state, new String(buf, i, len - i)),
            i);
      }
      //            System.err.printf("After processing index %d, ps.state=%s\n", i, ps.state );
    } // for

    // We have processed the entire buffer
    // Check for split buffer scenarios
    if ((ps.state == NatsOp.MSG_ARG || ps.state == NatsOp.MINUS_ERR_ARG) && (ps.argBuf == null)) {
      ps.argBuf = ByteBuffer.wrap(ps.argBufStore);
      ps.argBuf.put(buf, ps.as, i - ps.drop - ps.as);
      //    		System.err.printf("split msg, no clone, ps.argBuf=%s\n", ps.argBuf);
      // FIXME, check max len
    }
    // Check for split msg
    if (ps.state == NatsOp.MSG_PAYLOAD && ps.msgBuf == null) {
      // We need to clone the msgArg if it is still referencing the
      // read buffer and we are not able to process the msg.
      if (ps.argBuf == null) {
        cloneMsgArg();
        //        		System.err.printf("split msg, after clone, ps.argBuf=%s\n", ps.argBuf);
      }

      // If we will overflow the scratch buffer, just create a
      // new buffer to hold the split message.
      int lrem = len - ps.as; // portion of msg remaining in buffer
      if (ps.ma.size > ps.msgBufStore.length) {
        ps.msgBufStore = new byte[ps.ma.size];
      }
      ps.msgBuf = ByteBuffer.wrap(ps.msgBufStore);
      // copy what's left in the buffer
      ps.msgBuf.put(buf, ps.as, lrem);
    }
  }
예제 #7
0
  private void register() throws IOException {
    Log.info("Registering with " + registrar);
    FromHeader fromHeader = getFromHeader();
    Address fromAddress = fromHeader.getAddress();

    // Request URI
    SipURI requestURI = null;
    try {
      requestURI = addressFactory.createSipURI(null, registrar);

    } catch (ParseException e) {
      throw new IOException("Bad registrar address:" + registrar + " " + e.getMessage());
    }
    // requestURI.setPort(registrarPort);

    try {
      requestURI.setTransportParam(sipProvider.getListeningPoint().getTransport());

    } catch (ParseException e) {
      throw new IOException(
          sipProvider.getListeningPoint().getTransport()
              + " is not a valid transport! "
              + e.getMessage());
    }

    CallIdHeader callIdHeader = sipProvider.getNewCallId();
    CSeqHeader cSeqHeader = null;

    try {
      cSeqHeader = headerFactory.createCSeqHeader(1, Request.REGISTER);
    } catch (ParseException e) {
      // Should never happen
      throw new IOException("Corrupt Sip Stack " + e.getMessage());
    } catch (InvalidArgumentException e) {
      // Should never happen
      throw new IOException("The application is corrupt ");
    }

    ToHeader toHeader = null;
    try {
      String proxyWorkAround = System.getProperty("com.sun.mc.softphone.REGISTRAR_WORKAROUND");

      if (proxyWorkAround != null && proxyWorkAround.toUpperCase().equals("TRUE")) {

        SipURI toURI = (SipURI) (requestURI.clone());
        toURI.setUser(System.getProperty("user.name"));

        toHeader = headerFactory.createToHeader(addressFactory.createAddress(toURI), null);
      } else {
        toHeader = headerFactory.createToHeader(fromAddress, null);
      }
    } catch (ParseException e) {
      throw new IOException(
          "Could not create a To header for address:"
              + fromHeader.getAddress()
              + " "
              + e.getMessage());
    }

    ArrayList viaHeaders = getLocalViaHeaders();
    MaxForwardsHeader maxForwardsHeader = getMaxForwardsHeader();
    Request request = null;

    try {
      request =
          messageFactory.createRequest(
              requestURI,
              Request.REGISTER,
              callIdHeader,
              cSeqHeader,
              fromHeader,
              toHeader,
              viaHeaders,
              maxForwardsHeader);
    } catch (ParseException e) {
      throw new IOException("Could not create the register request! " + e.getMessage());
    }

    ExpiresHeader expHeader = null;

    for (int retry = 0; retry < 2; retry++) {
      try {
        expHeader = headerFactory.createExpiresHeader(expires);
      } catch (InvalidArgumentException e) {
        if (retry == 0) {
          continue;
        }
        throw new IOException(
            "Invalid registrations expiration parameter - " + expires + " " + e.getMessage());
      }
    }

    request.addHeader(expHeader);
    ContactHeader contactHeader = getRegistrationContactHeader();
    request.addHeader(contactHeader);

    try {
      SipURI routeURI =
          (SipURI) addressFactory.createURI("sip:" + proxyCredentials.getProxy() + ";lr");
      RouteHeader routeHeader =
          headerFactory.createRouteHeader(addressFactory.createAddress(routeURI));
      request.addHeader(routeHeader);

    } catch (Exception e) {

      Log.error("Creating registration route error ", e);
    }

    ClientTransaction regTrans = null;
    try {
      regTrans = sipProvider.getNewClientTransaction(request);
    } catch (TransactionUnavailableException e) {
      throw new IOException(
          "Could not create a register transaction!\n"
              + "Check that the Registrar address is correct! "
              + e.getMessage());
    }

    try {
      sipCallId = callIdHeader.getCallId();
      sipServerCallback.addSipListener(sipCallId, this);
      registerRequest = request;
      regTrans.sendRequest();

      Log.debug("Sent register request " + registerRequest);

      if (expires > 0) {
        scheduleReRegistration();
      }
    } catch (Exception e) {
      throw new IOException("Could not send out the register request! " + e.getMessage());
    }

    this.registerRequest = request;
  }
예제 #8
0
  public void declareJshell(
      String dir,
      String filename,
      String[] srv,
      String[] username,
      String[] password,
      String host,
      String owner,
      String servergrp)
      throws SQLException, ClassNotFoundException, UnknownHostException {

    int count = srv.length;

    DBConnection conn = new DBConnection();
    // conn.callConnection("192.168.8.81", "d2he");
    log.info("Connecting....");
    try {
      conn.callConnection(ip, sid);
      log.info("Congrats!!! Connected!!!");
    } catch (Exception e) {
      log.info("Connection error with stack " + e.getMessage());
    }
    RunDemo[] t = new RunDemo[count];
    String filename1 = "";
    filename1 = dir + filename;
    for (int i = 0; i < count; i++) {
      t[i] = new RunDemo();
      String[] serverList = srv[i].split(",");
      String logName = filename + "_" + serverList[0] + "_log";
      String sql =
          "INSERT INTO patcheventlog(SERVERNAME,hostname,FILENAME,LOGFILE,startime,owner,servergrp,hosting) VALUES ('"
              + serverList[1]
              + "','"
              + host
              + "','"
              + filename1
              + "','"
              + dir
              + logName
              + "',SYSDATE,'"
              + owner
              + "','"
              + servergrp
              + "','"
              + serverList[0]
              + "')";
      t[i].setStr(
          "sqlplus -L "
              + username[i]
              + "/"
              + password[i]
              + "@"
              + serverList[1]
              + ":"
              + serverList[2]
              + "/"
              + serverList[3]
              + " @"
              + filename1);
      t[i].setLogName(logName);
      t[i].setDirectory(dir);
      t[i].setPatchtype("manualpatch");
      try {
        conn.UpdateQuery(sql);
        log.info("Inserted into the table data with query " + sql);
      } catch (Exception e) {
        log.info(
            "The data can't be inserted into table with " + e.getMessage() + " sql query " + sql);
      }
      new Thread(t[i]).start();
    }
  }