NutzCN Logo
问答 Http.setHttpProxy需要哪种类型的IP呢,为啥会报NullPointerException?
发布于 3007天前 作者 Lewe© 2585 次浏览 复制 上一个帖子 下一个帖子
标签:

host=222.79.206.28
port=81

2016-08-31 21:41:11,525 org.nutz.ctemplate.mvc.LogTimeProcessor.process(LogTimeProcessor.java:32) DEBUG - [ GET]URI=/register/sendmsg 7948ms
2016-08-31 21:41:11,526 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) WARN  - Error@/register/sendmsg :
org.nutz.http.HttpException: url=http://221.179.180.158:9008/HttpQuickProcess/submitMessageAll
	at org.nutz.http.sender.PostSender.send(PostSender.java:41)
	at org.nutz.http.Http.post2(Http.java:192)
	at org.nutz.ctemplate.util.HttpUtil.post2(HttpUtil.java:48)
	at org.nutz.ctemplate.util.GuoDuSMSClient.postURL(GuoDuSMSClient.java:136)
	at org.nutz.ctemplate.util.GuoDuSMSClient.sendMsg(GuoDuSMSClient.java:69)
	at org.nutz.ctemplate.util.MessageHandler.send(MessageHandler.java:60)
	at org.nutz.ctemplate.controller.LoginController.sendMsg(LoginController.java:118)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:483)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:25)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.integration.shiro.NutShiroProcessor.process(NutShiroProcessor.java:118)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.ctemplate.mvc.LogTimeProcessor.process(LogTimeProcessor.java:27)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:198)
	at org.nutz.ctemplate.mvc.NutzTemplateNutFilter.doFilter(NutzTemplateNutFilter.java:51)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at com.alibaba.druid.support.http.WebStatFilter.doFilter(WebStatFilter.java:123)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
	at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:106)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:617)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1527)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1484)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
	at org.nutz.http.Http$1.getProxy(Http.java:256)
	at org.nutz.http.Sender.openConnection(Sender.java:147)
	at org.nutz.http.sender.PostSender.send(PostSender.java:22)
	... 66 more
10 回复

给出调用代码, 看上去是req.getHeader()返回null导致NPE

@wendal
Properties prop = new Properties();
InputStream in = GuoDuSMSClient.class.getClassLoader().getResourceAsStream("custom/proxy.properties");
try {
prop.load(in);
} catch (IOException e) {
try {
in.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
Http.setHttpProxy(prop.getProperty("proxy.host"),Integer.parseInt(prop.getProperty("proxy.port")));
Http.setAutoSwitch(true);
//...
Http.post2(url, params, timeOut);

知道了,是bug, 先用post3, header传Header.create()

@wendal
post3 body直接把参数map传进去就行吧?
Http.post3(address, params, Header.create(), Constant.SMS_TIME_OUT);

这样写吧.

return Sender.create(Request.create(url, METHOD.POST, params, Header.create()))
                     .setTimeout(timeout)
                     .send();

@wendal setHttpProxy是一次设置任何地方调用Http.post/get ...都会经过代理吗

@wendal 那如果。。。想只在一个地方使用代理。。请求结束后,setHttpProxy(null,null)?

Http.setProxySwitcher 看看这个方法, 自定义规则都行

添加回复
请先登陆
回到顶部