1 17 package org.apache.servicemix.common; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import java.io.PrintWriter ; 23 import java.io.StringWriter ; 24 25 28 public class ManagementSupport { 29 30 private static final Log logger = LogFactory.getLog(ManagementSupport.class); 31 32 public static class Message { 33 private String task; 34 private String component; 35 private String result; 36 private Throwable exception; 37 private String type; 38 private String message; 39 40 public String getComponent() { 41 return component; 42 } 43 public void setComponent(String component) { 44 this.component = component; 45 } 46 public Throwable getException() { 47 return exception; 48 } 49 public void setException(Throwable exception) { 50 this.exception = exception; 51 } 52 public String getResult() { 53 return result; 54 } 55 public void setResult(String result) { 56 this.result = result; 57 } 58 public String getTask() { 59 return task; 60 } 61 public void setTask(String task) { 62 this.task = task; 63 } 64 public String getType() { 65 return type; 66 } 67 public void setType(String type) { 68 this.type = type; 69 } 70 public String getMessage() { 71 return message; 72 } 73 public void setMessage(String message) { 74 this.message = message; 75 } 76 } 77 78 public static String createComponentMessage(Message msg) { 79 try { 80 StringBuffer sw = new StringBuffer (); 81 sw.append("<component-task-result "); 83 sw.append("xmlns=\"http://java.sun.com/xml/ns/jbi/management-message\">"); 84 sw.append("\n\t"); 85 sw.append("<component-name>"); 87 sw.append(msg.getComponent()); 88 sw.append("</component-name>"); 89 sw.append("\n\t"); 91 sw.append("<component-task-result-details>"); 92 sw.append("\n\t\t"); 94 sw.append("<task-result-details>"); 95 sw.append("\n\t\t\t"); 97 sw.append("<task-id>"); 98 sw.append(msg.getTask()); 99 sw.append("</task-id>"); 100 sw.append("\n\t\t\t"); 102 sw.append("<task-result>"); 103 sw.append(msg.getResult()); 104 sw.append("</task-result>"); 105 if (msg.getType() != null) { 107 sw.append("\n\t\t\t"); 108 sw.append("<message-type>"); 109 sw.append(msg.getType()); 110 sw.append("</message-type>"); 111 } 112 if (msg.getMessage() != null) { 114 sw.append("\n\t\t\t"); 115 sw.append("<task-status-msg>"); 116 sw.append("<msg-loc-info>"); 117 sw.append("<loc-token/>"); 118 sw.append("<loc-message>"); 119 sw.append(msg.getMessage()); 120 sw.append("</loc-message>"); 121 sw.append("</msg-loc-info>"); 122 sw.append("</task-status-msg>"); 123 } 124 if (msg.getException() != null) { 126 sw.append("\n\t\t\t"); 127 sw.append("<exception-info>"); 128 sw.append("\n\t\t\t\t"); 129 sw.append("<nesting-level>1</nesting-level>"); 130 sw.append("\n\t\t\t\t"); 131 sw.append("<msg-loc-info>"); 132 sw.append("\n\t\t\t\t\t"); 133 sw.append("<loc-token />"); 134 sw.append("\n\t\t\t\t\t"); 135 sw.append("<loc-message>"); 136 sw.append(msg.getException().getMessage()); 137 sw.append("</loc-message>"); 138 sw.append("\n\t\t\t\t\t"); 139 sw.append("<stack-trace>"); 140 StringWriter sw2 = new StringWriter (); 141 PrintWriter pw = new PrintWriter (sw2); 142 msg.getException().printStackTrace(pw); 143 pw.close(); 144 sw.append("<![CDATA["); 145 sw.append(sw2.toString()); 146 sw.append("]]>"); 147 sw.append("</stack-trace>"); 148 sw.append("\n\t\t\t\t"); 149 sw.append("</msg-loc-info>"); 150 sw.append("\n\t\t\t"); 151 sw.append("</exception-info>"); 152 } 153 sw.append("\n\t\t"); 155 sw.append("</task-result-details>"); 156 sw.append("\n\t"); 158 sw.append("</component-task-result-details>"); 159 sw.append("\n"); 161 sw.append("</component-task-result>"); 162 return sw.toString(); 164 } catch (Exception e) { 165 logger.warn("Error generating component management message", e); 166 return null; 167 } 168 } 169 170 } 171 | Popular Tags |