提交 21679ed3 编写于 作者: F Frankie Wu

add logview page

上级 883de335
......@@ -44,23 +44,26 @@ public class DefaultMessageStorage implements MessageStorage, LogEnabled {
public String store(MessageTree tree) {
String path = m_builder.getLogViewPath(tree);
File file = new File(m_builder.getLogViewBaseDir(), path);
ChannelBuffer buf = ChannelBuffers.dynamicBuffer(8192);
FileOutputStream fos = null;
file.getParentFile().mkdirs();
if (!file.exists()) {
ChannelBuffer buf = ChannelBuffers.dynamicBuffer(8192);
FileOutputStream fos = null;
try {
m_codec.encode(tree, buf);
fos = new FileOutputStream(file);
buf.getBytes(buf.readerIndex(), fos, buf.readableBytes());
} catch (IOException e) {
m_logger.error(String.format("Error when writing to file(%s)!", file), e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// ignore it
file.getParentFile().mkdirs();
try {
m_codec.encode(tree, buf);
fos = new FileOutputStream(file);
buf.getBytes(buf.readerIndex(), fos, buf.readableBytes());
} catch (IOException e) {
m_logger.error(String.format("Error when writing to file(%s)!", file), e);
} finally {
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
// ignore it
}
}
}
}
......
......@@ -11,7 +11,9 @@ com.dianping.cat.report.page.home.Handler.class,
com.dianping.cat.report.page.transaction.Handler.class,
com.dianping.cat.report.page.failure.Handler.class
com.dianping.cat.report.page.failure.Handler.class,
com.dianping.cat.report.page.logview.Handler.class,
})
public class ReportModule extends AbstractModule {
......
......@@ -11,6 +11,8 @@ public enum ReportPage implements Page {
FAILURE("f", "Failure", true),
LOGVIEW("m", "Logview", true),
;
private String m_name;
......
package com.dianping.cat.report.page.logview;
public enum Action implements com.site.web.mvc.Action {
VIEW("view");
private String m_name;
private Action(String name) {
m_name = name;
}
public static Action getByName(String name, Action defaultAction) {
for (Action action : Action.values()) {
if (action.getName().equals(name)) {
return action;
}
}
return defaultAction;
}
@Override
public String getName() {
return m_name;
}
}
package com.dianping.cat.report.page.logview;
import com.dianping.cat.report.ReportContext;
public class Context extends ReportContext<Payload> {
}
package com.dianping.cat.report.page.logview;
import java.io.IOException;
import java.util.Arrays;
import javax.servlet.ServletException;
import com.dianping.cat.report.ReportPage;
import com.site.lookup.annotation.Inject;
import com.site.web.mvc.PageHandler;
import com.site.web.mvc.annotation.InboundActionMeta;
import com.site.web.mvc.annotation.OutboundActionMeta;
import com.site.web.mvc.annotation.PayloadMeta;
public class Handler implements PageHandler<Context> {
@Inject
private JspViewer m_jspViewer;
@Override
@PayloadMeta(Payload.class)
@InboundActionMeta(name = "m")
public void handleInbound(Context ctx) throws ServletException, IOException {
// display only, no action here
}
@Override
@OutboundActionMeta(name = "m")
public void handleOutbound(Context ctx) throws ServletException, IOException {
Model model = new Model(ctx);
model.setAction(Action.VIEW);
model.setPage(ReportPage.LOGVIEW);
Payload payload = ctx.getPayload();
System.out.println(payload.getIdentifier());
System.out.println(Arrays.asList(payload.getPath()));
m_jspViewer.view(ctx, model);
}
}
package com.dianping.cat.report.page.logview;
public enum JspFile {
VIEW("/jsp/report/logview.jsp"),
;
private String m_path;
private JspFile(String path) {
m_path = path;
}
public String getPath() {
return m_path;
}
}
package com.dianping.cat.report.page.logview;
import com.dianping.cat.report.ReportPage;
import com.site.web.mvc.view.BaseJspViewer;
public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model> {
@Override
protected String getJspFilePath(Context ctx, Model model) {
Action action = model.getAction();
switch (action) {
case VIEW:
return JspFile.VIEW.getPath();
}
throw new RuntimeException("Unknown action: " + action);
}
}
package com.dianping.cat.report.page.logview;
import com.dianping.cat.report.ReportPage;
import com.site.web.mvc.ViewModel;
public class Model extends ViewModel<ReportPage, Action, Context> {
public Model(Context ctx) {
super(ctx);
}
@Override
public Action getDefaultAction() {
return Action.VIEW;
}
}
package com.dianping.cat.report.page.logview;
import com.dianping.cat.report.ReportPage;
import com.site.web.mvc.ActionContext;
import com.site.web.mvc.ActionPayload;
import com.site.web.mvc.payload.annotation.FieldMeta;
import com.site.web.mvc.payload.annotation.PathMeta;
public class Payload implements ActionPayload<ReportPage, Action> {
private ReportPage m_page;
@FieldMeta("op")
private Action m_action;
@FieldMeta("id")
private int m_identifier;
@PathMeta("path")
private String[] m_path;
public void setAction(Action action) {
m_action = action;
}
public int getIdentifier() {
return m_identifier;
}
public void setIdentifier(int identifier) {
m_identifier = identifier;
}
@Override
public Action getAction() {
return m_action;
}
public String[] getPath() {
return m_path;
}
public void setPath(String[] path) {
m_path = path;
}
@Override
public ReportPage getPage() {
return m_page;
}
@Override
public void setPage(String page) {
m_page = ReportPage.getByName(page, ReportPage.LOGVIEW);
}
@Override
public void validate(ActionContext<?> ctx) {
}
}
......@@ -11,7 +11,9 @@ public class NavigationBar {
ReportPage.FAILURE,
ReportPage.TRANSACTION
ReportPage.TRANSACTION,
ReportPage.LOGVIEW
};
}
......
......@@ -99,5 +99,18 @@
<role>com.dianping.cat.report.page.failure.JspViewer</role>
<implementation>com.dianping.cat.report.page.failure.JspViewer</implementation>
</component>
<component>
<role>com.dianping.cat.report.page.logview.Handler</role>
<implementation>com.dianping.cat.report.page.logview.Handler</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.report.page.logview.JspViewer</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.page.logview.JspViewer</role>
<implementation>com.dianping.cat.report.page.logview.JspViewer</implementation>
</component>
</components>
</plexus>
......@@ -4,6 +4,7 @@
<page name="home" description="Home" default="true" />
<page name="transaction" description="Transaction" />
<page name="failure" description="Failure" />
<page name="logview" description="Logview" />
</module>
</wizard>
<%@ page contentType="text/html; charset=utf-8" %>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.logview.Context" scope="request"/>
<jsp:useBean id="payload" type="com.dianping.cat.report.page.logview.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.report.page.logview.Model" scope="request"/>
View of logview page under report
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册