コード例 #1
1
 private void assertXMLFilesMatch(String label, IFile testFile, String expectedFileLocation)
     throws Exception {
   Reader testReader = null;
   Reader expectedReader = null;
   try {
     testReader = new InputStreamReader(testFile.getContents());
     expectedReader =
         new InputStreamReader(
             CreateSwitchYardProjectTest.class
                 .getClassLoader()
                 .getResourceAsStream(expectedFileLocation));
     Diff diff = XMLUnit.compareXML(testReader, expectedReader);
     assertTrue(label + ": " + diff.toString(), diff.identical());
   } finally {
     if (testReader != null) {
       try {
         testReader.close();
       } catch (Exception e) {
         // for codestyle check
         e.fillInStackTrace();
       }
       testReader = null;
     }
     if (expectedReader != null) {
       try {
         expectedReader.close();
       } catch (Exception e) {
         // for codestyle check
         e.fillInStackTrace();
       }
       expectedReader = null;
     }
   }
 }
コード例 #2
0
  /** 以字符为单位读取文件,常用于读文本,数字等类型的文件 */
  public static void readFileByChars(String fileName) {
    File file = new File(fileName);
    Reader reader = null;
    try {
      log.debug("以字符为单位读取文件内容,一次读一个字节:");
      // 一次读一个字符
      reader = new InputStreamReader(new FileInputStream(file));
      int tempchar;
      while ((tempchar = reader.read()) != -1) {
        // 对于windows下,\r\n这两个字符在一起时,表示一个换行。
        // 但如果这两个字符分开显示时,会换两次行。
        // 因此,屏蔽掉\r,或者屏蔽\n。否则,将会多出很多空行。
        if (((char) tempchar) != '\r') {
          System.out.print((char) tempchar);
        }
      }
      reader.close();
    } catch (Exception e) {
      log.error("", e.fillInStackTrace());
    }
    try {
      log.debug("以字符为单位读取文件内容,一次读多个字节:");
      // 一次读多个字符
      char[] tempchars = new char[30];
      int charread = 0;
      reader = new InputStreamReader(new FileInputStream(fileName));
      // 读入多个字符到字符数组中,charread为一次读取字符数
      while ((charread = reader.read(tempchars)) != -1) {
        // 同样屏蔽掉\r不显示
        if ((charread == tempchars.length) && (tempchars[tempchars.length - 1] != '\r')) {
          System.out.print(tempchars);
        } else {
          for (int i = 0; i < charread; i++) {
            if (tempchars[i] == '\r') {
              continue;
            } else {
              System.out.print(tempchars[i]);
            }
          }
        }
      }

    } catch (Exception e) {
      log.error("", e.fillInStackTrace());
    } finally {
      if (reader != null) {
        try {
          reader.close();
        } catch (IOException e) {
          log.error("", e.fillInStackTrace());
        }
      }
    }
  }
コード例 #3
0
ファイル: UpdateManager2.java プロジェクト: ljshj/myjavashop
  // 升级成功后更新版本号
  private void updateVersion(String version) {

    if (logger.isDebugEnabled()) {
      logger.debug("更新eop.properties中的版本信息...");
    }

    try {
      String path = StringUtil.getRootPath("eop.properties");
      File file = new File(path);

      // 更新eop.properties
      EopSetting.VERSION = version;
      InputStream in = new FileInputStream(file); // FileUtil.getResourceAsStream("eop.properties");
      Properties props = new Properties();
      props.load(in);
      props.setProperty("version", version);
      props.store(new FileOutputStream(file), "eop.properties");
      if (logger.isDebugEnabled()) {
        logger.debug("更新eop.properties中的版本成功.");
      }
    } catch (Exception e) {
      logger.error("更新eop.properties出错", e.fillInStackTrace());
      e.printStackTrace();
    }
  }
コード例 #4
0
ファイル: Validation.java プロジェクト: ctsscott/GVM
  public static List<Validator> getValidators(Class<?> clazz, String property, String name) {
    try {
      List<Validator> validators = new ArrayList<Validator>();
      while (!clazz.equals(Object.class)) {
        try {
          Field field = clazz.getDeclaredField(property);
          for (Annotation annotation : field.getDeclaredAnnotations()) {

            if (annotation.annotationType().getName().startsWith("annotations.validation")) {
              // play.Logger.info("Annotation " + annotation.toString(), annotation);

              Validator validator = new Validator(annotation);
              validators.add(validator);
              if (annotation.annotationType().equals(Equals.class)) {
                validator.params.put("equalsTo", name + "." + ((Equals) annotation).value());
              }
              if (annotation.annotationType().equals(InFuture.class)) {
                validator.params.put("reference", ((InFuture) annotation).value());
              }
              if (annotation.annotationType().equals(InPast.class)) {
                validator.params.put("reference", ((InPast) annotation).value());
              }
            }
          }
          break;
        } catch (NoSuchFieldException e) {
          clazz = clazz.getSuperclass();
        }
      }
      return validators;
    } catch (Exception e) {
      play.Logger.error(e.fillInStackTrace().getMessage(), e);
      return new ArrayList<Validator>();
    }
  }
コード例 #5
0
  public void unrelateAcrossR1013From(MessageArgument_c target, boolean notifyChanges) {
    if (target == null) return;

    if (IsSupertypeMessageArgument == null) return; // already unrelated

    if (target != IsSupertypeMessageArgument) {
      Exception e = new Exception();
      e.fillInStackTrace();
      CorePlugin.logError("Tried to unrelate from non-related instance across R1013", e);
      return;
    }

    if (target != null) {
      target.clearBackPointerR1013To(this);
    }

    if (IsSupertypeMessageArgument != null) {

      m_arg_id = IsSupertypeMessageArgument.getArg_id();
      IsSupertypeMessageArgument = null;
      target.removeRef();
      if (notifyChanges) {
        RelationshipChangeModelDelta change =
            new RelationshipChangeModelDelta(
                Modeleventnotification_c.DELTA_ELEMENT_UNRELATED, this, target, "1013", "");
        Ooaofooa.getDefaultInstance().fireModelElementRelationChanged(change);
      }
    }
  }
コード例 #6
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Instance State Machine.dispose call: ";
    ModelClass_c testR518Inst = ModelClass_c.getOneO_OBJOnR518(this, false);

    if (testR518Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "518 ";
    }
    StateMachine_c testR517Inst1 = StateMachine_c.getOneSM_SMOnR517(this, false);

    if (testR517Inst1 != null) {
      delete_error = true;
      errorMsg = errorMsg + "517 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Instance State Machine", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #7
0
  public void unrelateAcrossR518From(ModelClass_c target, boolean notifyChanges) {
    if (target == null) return;

    if (ModelClass == null) return; // already unrelated

    if (target != ModelClass) {
      Exception e = new Exception();
      e.fillInStackTrace();
      CorePlugin.logError("Tried to unrelate from non-related instance across R518", e);
      return;
    }

    if (target != null) {
      target.clearBackPointerR518To(this);
    }

    if (ModelClass != null) {

      m_obj_id = ModelClass.getObj_id();
      if (IdAssigner.NULL_UUID.equals(m_obj_id)) {
        m_obj_id = ModelClass.getObj_idCachedValue();
      }
      ModelClass = null;
      target.removeRef();
      UmlProblem.removeXtUMLProblem(this, target);
      if (notifyChanges) {
        RelationshipChangeModelDelta change =
            new RelationshipChangeModelDelta(
                Modeleventnotification_c.DELTA_ELEMENT_UNRELATED, this, target, "518", "");
        Ooaofooa.getDefaultInstance().fireModelElementRelationChanged(change);
      }
    }
  }
コード例 #8
0
  @Override
  public Map<String, FudgeMsg> doSnapshot(Collection<String> uniqueIds) {
    ArgumentChecker.notNull(uniqueIds, "Unique IDs");
    if (uniqueIds.isEmpty()) {
      return Collections.emptyMap();
    }

    Set<String> buids = Sets.newHashSetWithExpectedSize(uniqueIds.size());
    for (String uniqueId : uniqueIds) {
      String buid = "/buid/" + uniqueId;
      buids.add(buid);
    }

    // caching ref data provider must not be used here
    Map<String, FudgeMsg> snapshotValues =
        getReferenceDataProvider()
            .getReferenceDataIgnoreCache(buids, BloombergDataUtils.STANDARD_FIELDS_SET);
    Map<String, FudgeMsg> returnValue = Maps.newHashMap();
    for (String buid : buids) {
      FudgeMsg fieldData = snapshotValues.get(buid);
      if (fieldData == null) {
        Exception e = new Exception("Stack Trace");
        e.fillInStackTrace();
        s_logger.error("Could not find result for {} in data snapshot, skipping", buid, e);
        // throw new OpenGammaRuntimeException("Result for " + buid + " was not found");
      } else {
        String securityUniqueId = buid.substring("/buid/".length());
        returnValue.put(securityUniqueId, fieldData);
      }
    }
    return returnValue;
  }
  @RequestMapping(
      value = "/dashboard/updateuser",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public @ResponseBody String updateUserProfile(
      @RequestBody String contactObjectJSON, ModelMap model, HttpServletRequest request) {

    logger.info("Updating User Profile for JSON" + contactObjectJSON);

    if (filter.isUserSessionExpired(request, encoder)) {
      return "You session has expired. Please login again to proceed!!";
    }

    Contact contact = null;
    try {
      contact = Utils.getContactObjectFromJSON(contactObjectJSON);

      logger.info("Updating User Profile for username = "******"Error in updating user details in database.";
    }
    model.addAttribute("command", contact);
    return "true";
  }
コード例 #10
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Assign to Member.dispose call: ";
    Value_c testR609Inst = Value_c.getOneV_VALOnR609(this, false);

    if (testR609Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "609 ";
    }
    Value_c testR689Inst = Value_c.getOneV_VALOnR689(this, false);

    if (testR689Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "689 ";
    }
    Statement_c testR603Inst11 = Statement_c.getOneACT_SMTOnR603(this, false);

    if (testR603Inst11 != null) {
      delete_error = true;
      errorMsg = errorMsg + "603 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Assign to Member", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #11
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the GraphNode.dispose call: ";
    Graphelement_c testR301Inst1 = Graphelement_c.getOneDIM_GEOnR301(this, false);

    if (testR301Inst1 != null) {
      delete_error = true;
      errorMsg = errorMsg + "301 ";
    }
    Shape_c testR19Inst1 = Shape_c.getOneGD_SHPOnR19(this, false);

    if (testR19Inst1 != null) {
      delete_error = true;
      errorMsg = errorMsg + "19 ";
    }
    FloatingText_c testR19Inst2 = FloatingText_c.getOneGD_CTXTOnR19(this, false);

    if (testR19Inst2 != null) {
      delete_error = true;
      errorMsg = errorMsg + "19 ";
    }
    if (delete_error == true) {

      if (CanvasPlugin.getDefault().isDebugging()) {
        Ooaofgraphics.log.println(ILogger.DELETE, "GraphNode", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CanvasPlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #12
0
  public void unrelateAcrossR39From(DataType_c target, boolean notifyChanges) {
    if (target == null) return;

    if (ContainsDataType == null) return; // already unrelated

    if (target != ContainsDataType) {
      Exception e = new Exception();
      e.fillInStackTrace();
      CorePlugin.logError("Tried to unrelate from non-related instance across R39", e);
      return;
    }

    if (target != null) {
      target.clearBackPointerR39To(this);
    }

    if (ContainsDataType != null) {

      m_dt_id = ContainsDataType.getDt_id();
      if (IdAssigner.NULL_UUID.equals(m_dt_id)) {
        m_dt_id = ContainsDataType.getDt_idCachedValue();
      }
      ContainsDataType = null;
      target.removeRef();
      if (notifyChanges) {
        RelationshipChangeModelDelta change =
            new RelationshipChangeModelDelta(
                Modeleventnotification_c.DELTA_ELEMENT_UNRELATED, this, target, "39", "");
        Ooaofooa.getDefaultInstance().fireModelElementRelationChanged(change);
      }
    }
  }
コード例 #13
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Data Type in Package.dispose call: ";
    DataType_c testR39Inst = DataType_c.getOneS_DTOnR39(this, false);

    if (testR39Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "39 ";
    }

    DataTypePackage_c testR39InstOth = DataTypePackage_c.getOneS_DPKOnR39(this, false);

    if (testR39InstOth != null) {
      delete_error = true;
      errorMsg = errorMsg + "39 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Data Type in Package", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #14
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Component in Component.dispose call: ";
    Component_c testR4202Inst = Component_c.getOneC_COnR4202(this, false);

    if (testR4202Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "4202 ";
    }
    Component_c testR4203Inst = Component_c.getOneC_COnR4203(this, false);

    if (testR4203Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "4203 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Component in Component", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #15
0
  /**
   * 获取CPU序列号
   *
   * @return
   */
  public static String getCPUSerial() {
    if (!"".equals(result)) return result;
    try {
      File file = File.createTempFile("tmp", ".vbs");
      file.deleteOnExit();
      FileWriter fw = new java.io.FileWriter(file);
      String vbs =
          "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
              + "Set colItems = objWMIService.ExecQuery _ \n"
              + "   (\"Select * from Win32_Processor\") \n"
              + "For Each objItem in colItems \n"
              + "    Wscript.Echo objItem.ProcessorId \n"
              + "    exit for  ' do the first cpu only! \n"
              + "Next \n";

      // + "    exit for  \r\n" + "Next";
      fw.write(vbs);
      fw.close();
      Process p = Runtime.getRuntime().exec("cscript //NoLogo " + file.getPath());
      BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
      String line;
      while ((line = input.readLine()) != null) {
        result += line;
      }
      input.close();
      file.delete();
    } catch (Exception e) {
      e.fillInStackTrace();
    }
    if (result.trim().length() < 1 || result == null) {
      result = "无CPU_ID被读取";
    }

    return result.trim();
  }
コード例 #16
0
 /**
  * Import remote calendar into Silverpeas calendar (update event if necessary)
  *
  * @param urlCalendar
  * @param localCalendar
  * @param loginICalendar
  * @param pwdIcalendar
  * @return ReturnCode
  */
 public String synchroIcalAgenda(
     URL urlCalendar, File localCalendar, String loginICalendar, String pwdIcalendar) {
   String returnCodeSynchro = AgendaSessionController.SYNCHRO_FAILED;
   try {
     // Private iCal URL
     // Use the SyncEngine.listCalendars() method to get URLs
     URL remoteCalendar = urlCalendar;
     // Creates a synchronizer engine
     SyncEngine engine = new SyncEngine();
     // Do the synchronization :
     // Remote SilverpeasCalendar -> localfile SilverpeasCalendar
     String remoteConnect =
         engine.synchronize(localCalendar, remoteCalendar, loginICalendar, pwdIcalendar);
     if (SyncEngine.REMOTE_CONNECT_SUCCEEDED.equals(remoteConnect)) {
       // localfile -> Silverpeas Agenda
       ImportIcalManager impIcalManager = new ImportIcalManager(agendaSessionController);
       String returnImport = impIcalManager.importIcalAgenda(localCalendar);
       if (returnImport.equals(AgendaSessionController.IMPORT_FAILED)) {
         returnCodeSynchro = AgendaSessionController.SYNCHRO_FAILED;
       } else {
         returnCodeSynchro = AgendaSessionController.SYNCHRO_SUCCEEDED;
       }
     } else {
       returnCodeSynchro = remoteConnect;
     }
   } catch (Exception e) {
     SilverTrace.error(
         "agenda", "SynchroIcalManager.synchroIcalAgenda()", "", e.fillInStackTrace());
   }
   return returnCodeSynchro;
 }
コード例 #17
0
  protected void storeImage(MasterImageMetaData mimd, MultipartFile mpFile) {
    try {
      InputStream imageStream = mpFile.getInputStream();
      log.debug("storeImage: uploaded a multipart file -- filename: " + FILE_UPLOAD_FIELD);

      ImageData imageData = imageResizeMgr.generateImage(imageStream, null, null);
      log.debug("storeImage: file name is: " + mpFile.getOriginalFilename());
      imageData.setFilename(mpFile.getOriginalFilename());

      // Store the image in the cache
      String imageKey = imageCacheManager.addImage(imageData);

      // Uploading a new image
      if (imageKey != mimd.getImageKey()) {
        // Then clear out the previous sized images and their data
        mimd.clearSizedImages();
      }

      // Add the image key and data to the Master Image
      mimd.setImageKey(imageKey);
      mimd.setMetaData(imageData);
    } catch (Exception e) {
      log.debug(
          "storeImage: An exception was caught in storeImage: No inputStream found because no file was uploaded.",
          e.fillInStackTrace());
    }
  }
コード例 #18
0
ファイル: SignupController.java プロジェクト: hotmob/passport
 @RequestMapping(
     method = RequestMethod.POST,
     params = {"bind", "step!=1"})
 public String onBindSubmit(
     UserForm userForm,
     BindingResult errors,
     WebRequest webRequest,
     HttpServletRequest request,
     HttpServletResponse response)
     throws Exception {
   try {
     if (StringUtils.hasText(userForm.getConfirmPassword())) { // New User, Signup !
       onSubmit(userForm, errors, request, response);
     } else {
       SecurityContext.addCasSignin(
           centralAuthenticationService,
           ticketGrantingTicketCookieGenerator,
           userForm.getUsername(),
           userForm.getPassword(),
           false,
           false,
           response);
     }
     ProviderSignInUtils.handlePostSignUp(userForm.getUsername(), webRequest);
     return "redirect:/";
   } catch (Exception e) {
     e.fillInStackTrace();
     log.warn(e.getMessage());
     saveError(request, getText("bind.error.signup", request.getLocale()));
     return "signup";
   }
 }
コード例 #19
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Element In Move.dispose call: ";
    GraphicalElement_c testR25Inst = GraphicalElement_c.getOneGD_GEOnR25(this, false);

    if (testR25Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "25 ";
    }

    Model_c testR25InstOth = Model_c.getOneGD_MDOnR25(this, false);

    if (testR25InstOth != null) {
      delete_error = true;
      errorMsg = errorMsg + "25 ";
    }
    if (delete_error == true) {

      if (CanvasPlugin.getDefault().isDebugging()) {
        Ooaofgraphics.log.println(ILogger.DELETE, "Element In Move", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CanvasPlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #20
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Bridge Invocation.dispose call: ";
    ActualParameter_c testR628Inst = ActualParameter_c.getOneV_PAROnR628(this, false);

    if (testR628Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "628 ";
    }
    Statement_c testR603Inst7 = Statement_c.getOneACT_SMTOnR603(this, false);

    if (testR603Inst7 != null) {
      delete_error = true;
      errorMsg = errorMsg + "603 ";
    }
    Bridge_c testR674Inst = Bridge_c.getOneS_BRGOnR674(this, false);

    if (testR674Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "674 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Bridge Invocation", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #21
0
  public boolean delete() {
    boolean result = super.delete();
    boolean delete_error = false;
    String errorMsg =
        "The following relationships were not torn down by the Transient Value Reference.dispose call: ";
    Variable_c testR805Inst = Variable_c.getOneV_VAROnR805(this, false);

    if (testR805Inst != null) {
      delete_error = true;
      errorMsg = errorMsg + "805 ";
    }
    Value_c testR801Inst13 = Value_c.getOneV_VALOnR801(this, false);

    if (testR801Inst13 != null) {
      delete_error = true;
      errorMsg = errorMsg + "801 ";
    }
    if (delete_error == true) {

      if (CorePlugin.getDefault().isDebugging()) {
        Ooaofooa.log.println(ILogger.DELETE, "Transient Value Reference", errorMsg);
      } else {
        Exception e = new Exception();
        e.fillInStackTrace();
        CorePlugin.logError(errorMsg, e);
      }
    }
    return result;
  }
コード例 #22
0
  public void unrelateAcrossR301From(Graphelement_c target, boolean notifyChanges) {
    if (target == null) return;

    if (IsSupertypeGraphelement == null) return; // already unrelated

    if (target != IsSupertypeGraphelement) {
      Exception e = new Exception();
      e.fillInStackTrace();
      CanvasPlugin.logError("Tried to unrelate from non-related instance across R301", e);
      return;
    }

    if (target != null) {
      target.clearBackPointerR301To(this);
    }

    if (IsSupertypeGraphelement != null) {

      m_elementid = IsSupertypeGraphelement.getElementid();
      if (IdAssigner.NULL_UUID.equals(m_elementid)) {
        m_elementid = IsSupertypeGraphelement.getElementidCachedValue();
      }
      IsSupertypeGraphelement = null;
      target.removeRef();
      if (notifyChanges) {
        RelationshipChangeModelDelta change =
            new RelationshipChangeModelDelta(
                Modeleventnotification_c.DELTA_ELEMENT_UNRELATED, this, target, "301", "");
        Ooaofgraphics.getDefaultInstance().fireModelElementRelationChanged(change);
      }
    }
  }
コード例 #23
0
 public void testSysExceptionWithNestedSysException() {
   Exception exception = new SysException("test");
   exception.fillInStackTrace();
   SysException se = new SysException(null, exception);
   StackTraceElement[] st = se.getStackTrace();
   assertNotNull(st);
   assertFalse(st.length == 0);
 }
  /**
   * This calls the unsecured web service for this method.
   *
   * @param body The message to be sent to the web service.
   * @param assertion The assertion information to go with the message.
   * @return The response from the web service.
   * @throws PatientDiscoveryException
   */
  @AdapterDelegationEvent(
      beforeBuilder = PRPAIN201305UV02EventDescriptionBuilder.class,
      afterReturningBuilder = PRPAIN201306UV02EventDescriptionBuilder.class,
      serviceType = "Patient Discovery",
      version = "1.0")
  public PRPAIN201306UV02 respondingGatewayPRPAIN201305UV02(
      PRPAIN201305UV02 body, AssertionType assertion) throws PatientDiscoveryException {
    String url = null;
    PRPAIN201306UV02 response = new PRPAIN201306UV02();
    String sServiceName = NhincConstants.PATIENT_DISCOVERY_ADAPTER_SERVICE_NAME;

    try {
      if (body != null) {
        LOG.debug("Before target system URL look up.");
        url = oProxyHelper.getAdapterEndPointFromConnectionManager(sServiceName);
        LOG.debug(
            "After target system URL look up. URL for service: " + sServiceName + " is: " + url);

        if (NullChecker.isNotNullish(url)) {
          RespondingGatewayPRPAIN201305UV02RequestType request =
              new RespondingGatewayPRPAIN201305UV02RequestType();
          request.setAssertion(assertion);
          request.setPRPAIN201305UV02(body);
          request.setNhinTargetCommunities(null);

          ServicePortDescriptor<AdapterPatientDiscoveryPortType> portDescriptor =
              new AdapterPatientDiscoveryServicePortDescriptor();
          CONNECTClient<AdapterPatientDiscoveryPortType> client =
              CONNECTClientFactory.getInstance()
                  .getCONNECTClientUnsecured(portDescriptor, url, assertion);

          response =
              (PRPAIN201306UV02)
                  client.invokePort(
                      AdapterPatientDiscoveryPortType.class,
                      "respondingGatewayPRPAIN201305UV02",
                      request);
        } else {
          throw new PatientDiscoveryException(
              "Failed to call the adapter web service (" + sServiceName + ").  The URL is null.");
        }
      } else {
        throw new PatientDiscoveryException(
            "Failed to call the web service (" + sServiceName + ").  The input parameter is null.");
      }
    } catch (Exception e) {
      LOG.error(
          "Failed to call the web service ("
              + sServiceName
              + ").  An unexpected exception occurred.  "
              + "Exception: "
              + e.getMessage(),
          e);
      throw new PatientDiscoveryException(e.fillInStackTrace());
    }

    return response;
  }
コード例 #25
0
  private ChannelManager.TARTT_ERROR downloadFile(ChannelFile file) {
    InputStream input = null;
    OutputStream output = null;
    HttpURLConnection connection = null;
    try {
      URL url = new URL(file.getUrl());
      connection = (HttpURLConnection) url.openConnection();
      connection.setConnectTimeout(10000);
      connection.setReadTimeout(10000);
      connection.connect();

      if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        Log.e(TAG, "Connection error " + connection.getResponseCode());
        return ChannelManager.TARTT_ERROR.DOWNLOAD_ABORTED;
      }

      input = connection.getInputStream();
      File outputFolder = new File(mTargetFolder, file.getDirname());
      outputFolder.mkdirs();
      File outputFile = new File(outputFolder, file.getFilename());
      output = new FileOutputStream(outputFile, false);

      byte data[] = new byte[4096];
      int count;
      while ((count = input.read(data)) != -1) {
        // allow canceling
        if (isCancelled()) {
          try {
            if (output != null) output.close();
            if (input != null) input.close();
          } catch (IOException ignored) {
          }
          return ChannelManager.TARTT_ERROR.DOWNLOAD_ABORTED;
        }
        mBytesLoaded += count;
        publishProgress(mBytesLoaded);
        output.write(data, 0, count);
      }

      if (!MD5.checkMD5(file.getMd5(), outputFile)) {
        Log.e(TAG, "File was corrupt, downloading again");
        mBytesLoaded = -file.getFilesize();
        return downloadFile(file);
      }
    } catch (Exception e) {
      Log.e(TAG, "Exception downloading " + e.fillInStackTrace());
      return ChannelManager.TARTT_ERROR.DOWNLOAD_ABORTED;
    } finally {
      try {
        if (output != null) output.close();
        if (input != null) input.close();
      } catch (IOException ignored) {
      }

      if (connection != null) connection.disconnect();
    }
    return null;
  }
コード例 #26
0
ファイル: MultiThreadWikify.java プロジェクト: yao8839836/COT
  @SuppressWarnings("deprecation")
  @Override
  public void run() {
    // TODO Auto-generated method stub
    org.jsoup.nodes.Document doc = null;

    Elements links = null;

    File result = null;
    OutputStream out = null;
    BufferedWriter bw = null;
    int i = 0;
    try {
      for (i = start; i < end; i++) {

        String option = "&sourceMode=AUTO&repeatMode=FIRST_IN_REGION&minProbability=0";

        result = new File("file//boc//wikified(NYT)//" + (i + 1) + ".txt");
        out = new FileOutputStream(result, false);
        bw = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));
        String[] passage = null;
        if (texts[i].contains("\n")) passage = texts[i].split("\n");
        for (int j = 0; j < passage.length; j++) {
          // Thread.sleep(2000);
          if (passage[j].equals("")) continue;

          doc =
              Jsoup.connect(
                      "http://wikipedia-miner.cms.waikato.ac.nz/services/wikify?source="
                          + URLEncoder.encode(passage[j]).replaceAll("\\+", "%20")
                          + option)
                  .timeout(500000)
                  .get();
          links = doc.getElementsByTag("detectedtopic");
          for (Element e : links) {
            String title = e.attr("title");
            String weight = e.attr("weight");
            System.out.println(title + " " + weight);
            bw.write(title + " " + weight);
            bw.newLine();
          }
          // Connection conn =
          // Jsoup.connect("http://wikipedia-miner.cms.waikato.ac.nz/services/wikify?source="+URLEncoder.encode(passage[j]).replaceAll("\\+",
          // "%20")+option);
          System.out.println(j);
        }

        bw.close();
        out.close();
      }

    } catch (Exception e) {
      System.out.println("Error:" + i + " " + e.toString() + "\n" + e.fillInStackTrace());
    } finally {

    }
  }
コード例 #27
0
ファイル: Rethrowing.java プロジェクト: Eegger/ThinkingInJava
 public static void h() throws Exception {
   try {
     f();
   } catch (Exception e) {
     System.out.println("Inside h(),e.printStackTrace()");
     e.printStackTrace(System.out);
     throw (Exception) e.fillInStackTrace();
   }
 }
コード例 #28
0
 public int getCount() {
   int result = 0;
   try {
     result = ThesysTrackingDAO.getInstance().count(getSiteId(), getMemberId());
   } catch (Exception ex) {
     LOG.error(ex, ex.fillInStackTrace());
   }
   return result;
 }
コード例 #29
0
 public boolean deleteAll() {
   try {
     ThesysTrackingDAO.getInstance().deleteAll(getSiteId(), getMemberId());
   } catch (Exception ex) {
     LOG.error(ex, ex.fillInStackTrace());
     return false;
   }
   return true;
 }
コード例 #30
0
  private static Test error(Class testClass, String testMethod, Exception exception) {
    final Throwable e2 = exception.fillInStackTrace();
    return new TestCase(testMethod + "(" + testClass.getName() + ")") { // $NON-NLS-1$ //$NON-NLS-2$

      @Override
      protected void runTest() throws Throwable {
        throw e2;
      }
    };
  }