发送 序列化message 到endpoint

RegressionTestRecord record = new RegressionTestRecord();
    record.setRecordId(Long.valueOf(currentRegressionSeq));
    record.setTestScope(testScope);

String message = marshal( record);

private static String marshal(Object object) {
    OutputStream os = new ByteArrayOutputStream();
    String xmlStr = null;
    try {
      JAXBContext.newInstance(new Class[] { object.getClass() }).createMarshaller().marshal(object, os);      xmlStr = os.toString();
    } catch (JAXBException e) {
      String errorMsg = "Failed to parse the object to xml string with error: " + e.getMessage();
      LOGGER.error(errorMsg);
      throw new RuntimeException(errorMsg);
    } finally {
      if (os != null) {
        os = null;
      }
    }
    return xmlStr;
  }

猜你喜欢

转载自dannyhz.iteye.com/blog/2244223