第一步:
目录:
配置文件: application-context.xml
src/main/resources application.properties
log4j2.xml
application-context.xml:
application.properties :
#kafka broker
brokerList=node7-1:9092,node7-2:9092,node7-3:9092,node7-4:9092
#上报日志 topic
apperrorspark=apperrorspark
apperrorhive=apperrorhive
appstartupspark=appstartupspark
#strom数据文件
filepath=E://file/c.txt
#zk地址
zkaddress=node7-1:2181,node7-2:2181,node7-3:2181
groupid=appinfo
offsetreset=latest
autocommit=false
#上报日志 topic
topicerror=apperrorspark
#recievenums=1
#mongo 地址
mongoaddr=node7-2
mongoport=12345
#hive 参数
appId=moxaioxin
table=hiveapperror
log4j2.xml:
/app-project/src/main/webapp/WEB-INF
spring-servlet.xml:
web.xml:
contextConfigLocation
classpath:application-context.xml
characterEncodingFilter
org.springframework.web.filter.CharacterEncodingFilter
encoding
UTF-8
characterEncodingFilter
/*
org.springframework.web.context.ContextLoaderListener
org.springframework.web.util.IntrospectorCleanupListener
spring
org.springframework.web.servlet.DispatcherServlet
1
spring
/*
Archetype Created Web Application
/app-project/src/main/webapp/index.jsp
Hello World!
pom.xml
4.0.0
com.jinghang
app-project
0.0.1-SNAPSHOT
war
app-project
app-project
org.springframework
spring-webmvc
3.1.0.RELEASE
javax.servlet
servlet-api
2.4
jdk.tools
jdk.tools
1.8
system
C:\Program Files\Java\jdk1.8.0_192\lib\tools.jar
org.apache.logging.log4j
log4j-core
2.3
org.apache.logging.log4j
log4j-web
2.3
org.apache.logging.log4j
log4j-slf4j-impl
2.3
net.sf.json-lib
json-lib
2.4
jdk15
javax.servlet
jstl
1.2
org.apache.kafka
kafka_2.11
0.10.0.0
org.apache.kafka
kafka-clients
0.10.0.0
org.apache.storm
storm-core
1.0.3
provided
org.apache.spark
spark-core_2.11
2.2.1
org.apache.spark
spark-streaming_2.11
2.2.1
org.apache.spark
spark-streaming-kafka-0-10_2.11
2.2.1
org.mongodb
mongodb-driver
3.4.1
org.apache.hive
hive-exec
2.1.1
org.apache.hadoop
hadoop-hdfs
2.7.2
org.apache.hive
hive-jdbc
1.2.0
org.apache.hbase
hbase-client
1.1.2
org.apache.hbase
hbase-server
1.1.2
org.apache.hbase
hbase-common
1.1.2
com.google.code.gson
gson
2.8.5
org.codehaus.jackson
jackson-mapper-asl
1.4.2
com.typesafe
config
1.2.1
junit
junit
4.7
test
org.apache.bval
bval-jsr303
0.5
app-project
maven-compiler-plugin
3.3
1.8
1.8
utf8
org.apache.maven.plugins
maven-resources-plugin
2.5
UTF-8
maven-assembly-plugin
jar-with-dependencies
make-assembly
package
single
org.codehaus.mojo
exec-maven-plugin
1.2.1
exec
java
true
false
compile
代码:
com.jinghang.client:
package com.jinghang.client;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
import com.jinghang.entry.AppErrorLog;
import net.sf.json.JSONObject;
public class AppClient {
private static String url = "http://localhost:8080/app-project/appinfoservice/applogService";
private static Random random = new Random();
private static String appId = "moxaioxin";
private static String[] deviceIds = initDeviceId();
private static String appVersion = "3.2.1";
private static String appChannel = "baidu";
private static String appPlatform = "android";
private static String[] deviceStyles = {"iPhone 11","iPhone 12","小米9","huawei P40"}; //机型
private static String[] osTypes = {"8.3","7.1.1"}; //操作系统
private static String[] errorBriefs = {"at cn.xxx.appto55.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)"
,"at cn.xxx.appto55.control.CommandUtil.getInfo(CommandUtil.java:67)"
}; //错误摘要
private static String[] errorDetails = {"java.lang.NullPointerException "
+ "at cn.sbz.appto55.web.AbstractBaseController.validInbound(AbstractBaseController.java:72) "+
"at cn.xxx.appto.web.AbstractBaseController.validInbound",
"at cn.xxx.appto.control.CommandUtil.getInfo(CommandUtil.java:67) "+
"at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)" +
" at java.lang.reflect.Method.invoke(Method.java:606)"}; //错误详情
private static AppErrorLog[] appErrorLogs = initAppErrorLogs(); //错误相关信息的数组
private static String[] initDeviceId(){
String base = "device22";
String [] result = new String[100];
for(int i=0;i<100;i++){
result[i] = base+i+"";
}
return result;
}
//错误相关信息的数组
private static AppErrorLog[] initAppErrorLogs(){
AppErrorLog[] result = new AppErrorLog[20];
for(int i=0;i
com.jinghang.entry:
package com.jinghang.client;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Random;
import com.jinghang.entry.AppErrorLog;
import net.sf.json.JSONObject;
public class AppClient {
private static String url = "http://localhost:8080/app-project/appinfoservice/applogService";
private static Random random = new Random();
private static String appId = "moxaioxin";
private static String[] deviceIds = initDeviceId();
private static String appVersion = "3.2.1";
private static String appChannel = "baidu";
private static String appPlatform = "android";
private static String[] deviceStyles = {"iPhone 11","iPhone 12","小米9","huawei P40"}; //机型
private static String[] osTypes = {"8.3","7.1.1"}; //操作系统
private static String[] errorBriefs = {"at cn.xxx.appto55.web.AbstractBaseController.validInbound(AbstractBaseController.java:72)"
,"at cn.xxx.appto55.control.CommandUtil.getInfo(CommandUtil.java:67)"
}; //错误摘要
private static String[] errorDetails = {"java.lang.NullPointerException "
+ "at cn.sbz.appto55.web.AbstractBaseController.validInbound(AbstractBaseController.java:72) "+
"at cn.xxx.appto.web.AbstractBaseController.validInbound",
"at cn.xxx.appto.control.CommandUtil.getInfo(CommandUtil.java:67) "+
"at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)" +
" at java.lang.reflect.Method.invoke(Method.java:606)"}; //错误详情
private static AppErrorLog[] appErrorLogs = initAppErrorLogs(); //错误相关信息的数组
private static String[] initDeviceId(){
String base = "device22";
String [] result = new String[100];
for(int i=0;i<100;i++){
result[i] = base+i+"";
}
return result;
}
//错误相关信息的数组
private static AppErrorLog[] initAppErrorLogs(){
AppErrorLog[] result = new AppErrorLog[20];
for(int i=0;i
com.jinghang.service:
package com.jinghang.service;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.jinghang.entry.AppErrorLog;
import net.sf.json.JSONObject;
@Controller
@RequestMapping("/appinfoservice")
public class AppInfoService {
Logger logger = LogManager.getLogger();//添加日志
//http://localhost:8080/app-project/appinfoservice/hello
@RequestMapping("/hello")
public void sayhello(HttpServletRequest req,HttpServletResponse resp){
logger.debug("进来了哦 !!!!!");
PrintWriter printWriter = getJsonWriter(resp);
resp.setStatus(HttpStatus.OK.value());
printWriter.println("hello "+req.getRemoteAddr());
closePringWriter(printWriter);
}
private PrintWriter getJsonWriter(HttpServletResponse resp) {
resp.setCharacterEncoding("utf-8");
resp.setContentType("application/json");
PrintWriter printWriter = null;
try {
printWriter = resp.getWriter();
} catch (IOException e) {
logger.error("出错啦!!"+e.getMessage());
}
return printWriter;
}
private void closePringWriter(PrintWriter printWriter) {
if(printWriter != null){
printWriter.flush();
printWriter.close();
}
}
//开始接收client 发送的数据 做转发
@RequestMapping(value="/applogService",method=RequestMethod.POST)
public void appInfoService(@RequestBody String jsonstr,HttpServletResponse reqs){
logger.debug("进入日志上报服务了,哈哈!!");
//将字符串 转换成JSONObject
JSONObject jsonObject = JSONObject.fromObject(jsonstr);
String hivemessage = transerformtohive(jsonObject);//hive的转换后的数据格式
String sparkstreamingmessage = jsonstr; //spark的数据格式 kafka测试
// String sparkstreamingmessage = "com.logentity.AppErrorLog:"+jsonstr;//sparkStreaming的数据格式
logger.debug("hive errorLog message: "+hivemessage);
// kafkaMessageProducer.sendMessage(apperrorhive, hivemessage);
logger.debug("spark errorLog message: "+sparkstreamingmessage);
// kafkaMessageProducer.sendMessage(apperrorspark, sparkstreamingmessage);
PrintWriter printWriter = getJsonWriter(reqs);
reqs.setStatus(HttpStatus.OK.value());
printWriter.println("success");
closePringWriter(printWriter);
}
private String transerformtohive(JSONObject jsonObject) {
//将jsonObject 对象 转换成 AppErrorLog对象
AppErrorLog appEorrLog = (AppErrorLog) jsonObject.toBean(jsonObject, AppErrorLog.class);
Long createdAtMs = appEorrLog.getCreatedAtMs();
String appId = appEorrLog.getAppId();
String deviceId = appEorrLog.getDeviceId();
String appVersion=appEorrLog.getAppVersion();
String appChannel=appEorrLog.getAppChannel();
String appPlatform=appEorrLog.getAppPlatform();
String osType=appEorrLog.getOsType();
String deviceStyle=appEorrLog.getDeviceStyle();
String errorBrief=appEorrLog.getErrorBrief();
String errorDetail=appEorrLog.getErrorDetail();
String timesecond = transfertime(createdAtMs);
String result = createdAtMs + "\t"+appId+"\t"+deviceId+"\t"+appVersion+"\t"+appChannel
+"\t"+appPlatform+"\t"+osType+"\t"+deviceStyle+"\t"+errorBrief+"\t"+errorDetail
+"\t"+timesecond;
return result;
}
private static String transfertime(Long time) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddhhmmss");
return simpleDateFormat.format(time);
}
}
改的位置:
run:
报了个错:Server Tomcat v8.5 Server at localhost was unable to start within 150 seconds. If the server requires more time, try increasing the timeout in the server editor.
本地主机上的服务器Tomcat v8.5服务器无法在150秒内启动。如果服务器需要更多时间,请尝试在服务器编辑器中增加超时