我们有一个相当复杂的签名小程序,自从我们几年前开发它以来一直很好用.在我们关心的所有操作系统/浏览器配置中,它可以在Java 1.5和1.6上运行良好.
它在Windows 7或Vista上的任何浏览器中都不适用于Java 1.7.我们已经看到它适用于Windows XP.此applet在Apache使用mod_proxy连接到Tomcat 6的站点中运行.
这些都是背景信息,因为我将问题简化为一个非常简单的未签名小程序:
package myapplet;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
public class MyApplet extends Applet {
private static final long serialVersionUID = 1L;
public void paint(Graphics g) {
g.drawRect(0, 0, 250, 100);
g.setColor(Color.blue);
g.drawString("Look at me, I'm a Java Applet!", 10, 50);
}
}
Run Code Online (Sandbox Code Playgroud)
如果将这个applet类放入一个jar文件中,另一个文件将jar文件的总(压缩)大小超过大约18KB,那么当由本地运行的Tomcat 6(或Apache 2.2)提供服务时,applet不会加载.
我通过向jar文件添加文本文件并更改文本文件的大小来玩.我通过在文本文件中添加一个字符来实现它从工作到不工作的程度.
查看带有跟踪的控制台日志,它正在尝试下载jar文件.这是我认为悬挂的主题:
"thread applet-com.bright.assetbank.clientsideedit.myapplet.MyApplet-1" prio=4 tid=0x048d8c00 nid=0x19b8 runnable [0x0700d000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at java.io.BufferedInputStream.read1(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
- …Run Code Online (Sandbox Code Playgroud) 我正在使用带有Gradle插件的STS开发Spring Boot应用程序.我有一个不同的测试配置,以防止我们的Selenium测试必须登录.
所以src/test/java/etc我有这样的事情:
@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public static class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests().anyRequest().permitAll();
}
}
Run Code Online (Sandbox Code Playgroud)
而在src/main/java我有一个等效的类配置登录等,需要登录所有页面.
如果我通过Gradle插件(bootRun)运行应用程序,一切正常.
但是,如果我直接通过Eclipse运行或调试它(例如右键单击项目,Run As-> Spring Boot App或单击Spring或Java视图中的run/debug按钮),则应用测试配置,因此访问被授予所有页面而无需登录.
我猜测当我以这种方式启动应用程序时,测试类被包含在类路径中.有没有一种简单的方法可以防止这种情况发生?
给定矩形形状S,纵横比为sx/sy,以及另外两个矩形形状A(纵横比为ax/ay)和B(纵横比为bx/by),如何找出形状A或B中的哪一个具有与S最近的宽高比?形状的大小并不重要.
是(sx/sy)/(ax/ay)和(sx/sy)/(bx/by)中哪一个最接近1?
我实际上要做的是找出PPTX幻灯片上哪个形状最适合将调整大小然后裁剪以适合该形状的图像.我想另一种方法是找出哪种形状导致丢失最少的像素,尽管在我的代码中,如果我可以通过比较宽高比来做到这一点会更容易.
最后我使用下面的算法,实现如下(感谢Matt Ball的反馈):
ShapeInPPTXLocation closest;
double imageAR = a_imageDim.getWidth()/a_imageDim.getHeight();
double aspectRatioCandidateA = a_candidateA.getWidth()/a_candidateA.getHeight();
double aspectRatioCandidateB = a_candidateB.getWidth()/a_candidateB.getHeight();
double closenessScoreA=1-(imageAR/aspectRatioCandidateA);
double closenessScoreB=1-(imageAR/aspectRatioCandidateB);
if (Math.abs(closenessScoreA) <= Math.abs(closenessScoreB))
{
closest=a_candidateA;
}
else
{
closest=a_candidateB;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 Spring Boot 1.3、Spring 4.2 和 Spring Security 4.0。我正在使用 MockMvc 运行集成测试,例如:
mockMvc = webAppContextSetup(webApplicationContext).build();
MvcResult result = mockMvc.perform(get("/"))
.andExpect(status().isOk())
.etc;
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我模拟用户登录,如下所示:
CurrentUser principal = new CurrentUser(user);
Authentication auth =
new UsernamePasswordAuthenticationToken(principal, "dummypassword",
principal.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(auth);
Run Code Online (Sandbox Code Playgroud)
这对于我用 注释的方法效果很好@PreAuthorize,例如从测试中调用这样的方法时:
@PreAuthorize("@permissionsService.canDoThisThing(principal)")
public void mySecuredMethod()
Run Code Online (Sandbox Code Playgroud)
原理是,我的 CurrentUser 对象在PermissionsService#canDoThisThing.
我有一个用 @ControllerAdvice 注释的类,它将当前登录的用户添加到模型中,以便可以在每个视图中访问它:
@ControllerAdvice
public class CurrentUserControllerAdvice {
@ModelAttribute("currentUser")
public CurrentUser getCurrentUser(Authentication authentication) {
if (authentication == null) {
return null;
}
return (CurrentUser) authentication.getPrincipal();
}
}
Run Code Online (Sandbox Code Playgroud)
这在运行应用程序时工作得很好,但是(这是我的问题) - 当运行我的测试时,传递到上面的 getCurrentUser 方法的身份验证参数始终为空。这意味着我的视图模板中对 currentUser …
我面对这个问题.我有一个过滤器,根据过滤器的配置设置请求的字符编码(例如,UTF-8).这适用于使用struts html:form标签编码的表单.但是,如果我使用普通的HTML表单标记,则数据编码不正确.
这是web.xml中的过滤器定义:
<filter>
<filter-name>Encoding Filter</filter-name>
<filter-class>EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Encoding Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)
这是过滤器:
public class EncodingFilter implements javax.servlet.Filter {
private String encoding;
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
request.setCharacterEncoding(encoding);
filterChain.doFilter(request, response);
}
public void destroy() {
}
Run Code Online (Sandbox Code Playgroud)
}