我想编写一个JAX-WS Web服务,使用http://www.w3.org/TR/xmldsig-core/建议来签署我的SOAP消息.
通过我在互联网上找到的东西,我写了一个JAX-WS处理程序(SOAPHandler<SOAPMessageContext>
),它设法改变SOAP请求的副本:
@Override
public boolean handleMessage(SOAPMessageContext smc) {
Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
SOAPMessage message = smc.getMessage();
if (outboundProperty) {
try {
SOAPPart soapPart = message.getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
Source source = soapPart.getContent();
Node root = null;
Document doc22 = null;
if (source instanceof DOMSource) {
root = ((DOMSource) source).getNode();
} else if (source instanceof SAXSource) {
InputSource inSource = ((SAXSource) source).getInputSource();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = null;
db = dbf.newDocumentBuilder(); …
Run Code Online (Sandbox Code Playgroud) 有人可以向我解释为什么以下代码:
public class Test {
public static void main(String... args) {
round(6.2088, 3);
round(6.2089, 3);
}
private static void round(Double num, int numDecimal) {
System.out.println("BigDecimal: " + new BigDecimal(num).toString());
// Use Locale.ENGLISH for '.' as decimal separator
NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
nf.setGroupingUsed(false);
nf.setMaximumFractionDigits(numDecimal);
nf.setRoundingMode(RoundingMode.HALF_UP);
if(Math.abs(num) - Math.abs(num.intValue()) != 0){
nf.setMinimumFractionDigits(numDecimal);
}
System.out.println("Formatted: " + nf.format(num));
}
}
Run Code Online (Sandbox Code Playgroud)
给出以下输出?
[me@localhost trunk]$ java Test
BigDecimal: 6.208800000000000096633812063373625278472900390625
Formatted: 6.209
BigDecimal: 6.208899999999999863575794734060764312744140625
Formatted: 6.208
Run Code Online (Sandbox Code Playgroud)
如果你没有看到它:"6.2089"四舍五入到3位给出输出"6.208"而"6.2088"给出"6.209"作为输出.少即是多?
使用Java 5,6或7时结果很好但是这个Java 8给了我这个奇怪的输出.Java版本:
[me@localhost trunk]$ java -version
java version …
Run Code Online (Sandbox Code Playgroud) 是否有关于Java堆栈跟踪行号的明确文档?
在打印堆栈跟踪(它背后的逻辑,而不是实现)时,它们如何"计算"?
为了告诉你为什么我感到困惑,请使用以下代码片段:
public static void main(String[] args) {
String evilString = null;
System.out.println(new StringBuilder()
.append(evilString.toLowerCase()));
evilString.toUpperCase();
}
Run Code Online (Sandbox Code Playgroud)
它提供了:线程"main"显示java.lang.NullPointerException异常在be.company.training.ocjp6.App.main(App.java:28)
而下面这段代码:
public static void main(String[] args) {
String evilString = null;
System.out.println(new StringBuilder()
.append("".toLowerCase()));
evilString.toUpperCase();
}
Run Code Online (Sandbox Code Playgroud)
给出:异常在线程"主"显示java.lang.NullPointerException在be.company.training.ocjp6.App.main(App.java:30)
所以我理解运行StringBuilder
方法链使它被视为1行(StringBuilder代码从我的编辑器中的第28行开始).但是如果在evilString.toUpperCase()片段中发生错误,我们就会回到第30行.
我想知道,当我看到一个堆栈跟踪时,我可以确定错误发生在哪一行(链接方法(在多行上)在我正在查看的代码中非常常见).
这是一个有效的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<filter>
<filter-name>rememberMeCookieFilter</filter-name>
<filter-class>be.example.fun.jsp.filters.RememberMeCookieFilter</filter-class>
</filter>
<filter>
<filter-name>mustBeSignedInFilter</filter-name>
<filter-class>be.example.fun.jsp.filters.MustBeSignedInFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>rememberMeCookieFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>mustBeSignedInFilter</filter-name>
<url-pattern>/private/*</url-pattern>
</filter-mapping>
</web-app>
Run Code Online (Sandbox Code Playgroud)
当我删除<filter>
元素并使用以下注释时:
@WebFilter(filterName="rememberMeCookieFilter")
public class RememberMeCookieFilter implements Filter
@WebFilter(filterName="mustBeSignedInFilter")
public class MustBeSignedInFilter implements Filter
Run Code Online (Sandbox Code Playgroud)
然后Tomcat 7.0.14给我以下错误:
java.lang.IllegalArgumentException: Filter mapping must specify either a <url-pattern> or a <servlet-name>
at org.apache.catalina.core.StandardContext.validateFilterMap(StandardContext.java:2956)
at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2915)
at org.apache.catalina.deploy.WebXml.configureContext(WebXml.java:1180)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1270)
...
Run Code Online (Sandbox Code Playgroud)
我按照这个问题的答案,但这对我不起作用.
以下是我的Web应用程序的依赖项:
<dependencies>
<!-- SLF4J (+ LOGBack) for logging -->
<dependency> …
Run Code Online (Sandbox Code Playgroud) Channel.id()已在Netty 4.0.0.CR9中删除.
这些天我如何获得频道的ID?
我曾经在我的所有处理程序中使用id()进行日志记录(例如System.out.println(ctx.channel().id()+" - readableBytes():"+ in.readableBytes())).
我不能依赖Channel的toString方法,因为它可能被覆盖.
情况:我有一个使用Netty 4.0.17.Final的代理应用程序(仅供参考:我已经有版本4.0.13.Final和4.0.9.Final的问题),这是基于Netty示例的代理.
我的代码与示例之间的主要区别在于,当通道处于活动状态时,我的代码不会连接到后端服务器,但仅在第一次读取时,因为此读取必须首先对输入进行一些检查,然后再连接并转发该消息到后端服务器.
我已经进行了单元测试并对我的应用程序进行了几个小时的加载测试
问题:
由于收到的第一个消息需要执行一些阻塞操作,我试图EventExecutorGroup
为那个执行该操作的一个处理程序使用单独的(以便IO线程不会被阻塞):
private static final EventExecutorGroup handlersExecutor = new DefaultEventExecutorGroup(10);
...
pipeline.addLast(handlersExecutor, "authenticationHandler", new FrontendHandler(outboundAddress));
Run Code Online (Sandbox Code Playgroud)
这(=我做的唯一更改!)在负载测试期间中断了应用程序.什么打破?3500个客户端连接中的XXX报告我,这些客户端的500条消息中的YY没有从代理获得回复(每个请求应该得到一个响应).来自客户端日志的摘录:
2014-02-14 00:39:56.146 [id:0x34cb2c60]错误(com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接(/127.0.0.1:7201).PDU收到:13
2014-02-14 00:39:56.146 [id:0xf0955993]错误(com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接(/127.0.0.1:7201).PDU收到:13
2014-02-14 00:39:56.147 [id:0x9a911fa3] ERROR(com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接(/127.0.0.1:7201).PDU收到:13
2014-02-14 00:39:56.149 [id:0x811bbadf] ERROR(com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接(/127.0.0.1:7201).PDU收到:13
2014-02-14 00:39:56.150 [id:0x0c4d4c5a]错误(com.nsn.ucpsimulator.common.UcpDecoder) - 空闲连接(/127.0.0.1:7201).PDU收到:13
代理应用程序告诉我收到了500条消息并被转发,但只收到了13条回复并转发回客户端:
2014-02-14 00:39:57.683 [id:0x39af563b]错误(be.demmel.fun.UcpDecoder) - 空闲连接(/127.0.0.1:49359).收到的PDU:500
2014-02-14 00:39:57.683 [id:0x82056d39]错误(be.demmel.fun.FrontendHandler) - 空闲连接(/127.0.0.1:52004),关闭它.转发的PDU:500.成功:500
2014-02-14 00:40:00.717 [id:0xcdca8f66] ERROR(be.demmel.fun.UcpDecoder) - 空闲连接(/127.0.0.1:7900).PDU收到:13
2014-02-14 00:40:00.718 [id:0xcdca8f66]错误(be.demmel.fun.BackendHandler) - 空闲连接(/127.0.0.1:7900).转发的PDU:13.成功:13
服务器告诉我一切都很好:
2014-02-14 00:40:02.855 [id:0x4980be2c] …
我有一个执行一些 IO 的方法,我想限制对这个方法的调用(每秒),以避免后端获得它无法处理的并发请求的爆发。
如果要求没有“每秒”,我可以只使用一个堆栈(基本上只是一个计数器)并offer()
在开始请求时和poll()
完成时使用。对于“每秒”要求,我需要以某种方式清除堆栈上比给定时间流逝更旧的插槽。
我该如何正确地做到这一点?显然,该结构应该是线程安全的。
感谢您的时间!
有人报告我,我给他使用log4j的程序没有正确打印字符.他告诉我"é"在文件中打印为"Ã"(例如:"Vidéo"变成"VidÃ"o").
这可能是一些编码问题,但我喜欢重现问题以证明它是固定的.我无法找到有关该主题的优秀(和简短)文档,因此:
感谢您的帮助!
我想知道在调用HttpServletRequest.getSession(false)时何时期望"null"
另外:HttpSession有很好的教程吗?我想得到如下细节:何时无效()?有什么后果?我需要检查返回的HttpSession是否有效?... <==请在评论中回答.
我的项目有一些JUnit
我很少想要运行的测试.为此,我把它们放进去@Category
,然后我做了这个:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<!-- Run all but the inject tests -->
<configuration>
<groups>!be.test.InjectTests</groups>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我想在命令行中覆盖配置以运行Inject测试,如下所示:
mvn clean install -Dgroups=be.test.InjectTests
Run Code Online (Sandbox Code Playgroud)
但这不起作用,-Dgroups被Maven忽略了.
如果我不把命令工作正常.