我已经创建了一个Axis Web服务作为在Tomcat 7上运行的Java 6应用程序.为了安全起见,Spring Security 2.0.1框架已经集成.
出于安全考虑,应使用基本身份验证来保护服务端点.但是,WSDL文档应该是公开的.
我创建了一个像这样的Spring安全配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd">
<http>
<intercept-url pattern="/services/InitechAuthenticationService*" access="ROLE_WSUSER" />
<intercept-url pattern="/services/InitechAuthenticationService?wsdl" filters="none" />
<http-basic />
</http>
<authentication-provider>
<user-service>
<user name="internal" password="${WS_USER_INTERNAL_PASSWORD}" authorities="ROLE_WSUSER" />
<user name="external" password="${WS_USER_EXTERNAL_PASSWORD}" authorities="ROLE_WSUSER" />
</user-service>
</authentication-provider>
</beans:beans>
Run Code Online (Sandbox Code Playgroud)
问题是无论拦截线的顺序如何,线都是如此
<intercept-url pattern="/services/InitechAuthenticationService*" access="ROLE_WSUSER" />
Run Code Online (Sandbox Code Playgroud)
似乎总是应用和行
<intercept-url pattern="/services/InitechAuthenticationService?wsdl" filters="none" />
Run Code Online (Sandbox Code Playgroud)
被忽略了.我本以为可以通过某种方式控制行为,例如通过指定顺序(以便Spring Security选择第一个或最后一个匹配规则)或规则的特殊性,以便Spring Security选择最具体的规则,即在这种情况下,最后一个是"wsdl".如何排除WSDL文档的身份验证,同时启用身份验证以实际使用WS?
我有一个使用Maven配置的Java Spring项目.随着单元测试及其配置文件的数量快速增加,我正在尝试将测试配置集中到一个属性文件(同一个属性文件,用于构建项目).
单元测试位于树中(当然相对于项目路径)
src/test/java/com (...)
这些测试的资源文件位于
src/test/resources(...)
最后,资源文件应该读取的属性文件位于目录中
src/main/filters
现在,我有一个Junit类,我在其中指定配置文件位置,如下所示:
@ContextConfiguration(locations = { "classpath:com/initrode/quartz/SyncManagerJobTest-context.xml"})
Run Code Online (Sandbox Code Playgroud)
在配置文件SyncManagerJobTest-context.xml中有一行
<context:property-placeholder location="/src/main/filters/deploy.local.properties"/>
Run Code Online (Sandbox Code Playgroud)
这导致从目录中读取属性文件.我想读的是属性文件,它位于src/main/filters下.我尝试使用../../向上遍历目录,但这没有帮助.使用classpath:也没有用.我可以使用带有"file:"的绝对路径,但这需要项目中的每个开发人员修改配置,这也不好.
总而言之,问题是:如何强制src/test/resources /中的配置文件读取src/main/filters中的属性文件?
还有一个相关的奖励问题:在Java环境中处理文件时,是否还有其他修饰符而不是"file:"和"classpath:"?
我在Eclipse中在代理后面执行单元测试时遇到问题,因为单元测试使用的类调用一些代理后面的Web服务.在Tomcat中,我当然可以指定要使用的代理,但是当我直接从Eclipse运行单元测试时,Eclipse的代理配置似乎被忽略了.在这种情况下,如何配置单元测试或Eclipse以使用代理?
我有以下代码
Criteria criteria = this.getCriteriaForClass(DeviceListItem.class);
Projection rowCountProjection = Projections.countDistinct("color");
criteria.setProjection(rowCountProjection);
int rowCount = ((Long) criteria.uniqueResult()).intValue();
return rowCount;
Run Code Online (Sandbox Code Playgroud)
,其目的是找出名为"color"的字段具有不同值的行数.问题是
Projections.countDistinct("color");
Run Code Online (Sandbox Code Playgroud)
返回相同数量的结果
Projections.count("color");
Run Code Online (Sandbox Code Playgroud)
即使数据库视图中有多个具有相同颜色的行.将Criteria对象转换为SQL时,我发现Hibernate生成的SQL是
select count(this_.COLOR) as y0_ from DEVICESLIST_VIEW this_ where 1=1
Run Code Online (Sandbox Code Playgroud)
当我期待它的时候
select count(distinct this_.COLOR) as y0_ from DEVICESLIST_VIEW this_ where 1=1
Run Code Online (Sandbox Code Playgroud)
为什么它没有像预期的那样工作,是否有一些补救措施?不幸的是,在这种情况下我没有选择使用HQL.
我有一个在Java 6,Spring 2.5.6和Hibernate 3.2.7上运行的Web应用程序.现在需要从几个数据库中获取一些数据,这些数据库的名称在运行时之前是未知的.实现这一目标的最佳方法是什么?
我已经查看了http://blog.springsource.com/2007/01/23/dynamic-datasource-routing/上的文章,但这似乎只适用于预先知道所有数据库配置的情况. .
通常HTML元素属性值用引号标记,如
<input type="hidden" value="test" />
但是,有时您会看到类似的代码
<input type='hidden' value='test' />
它是有效的HTML,它会导致任何问题吗?怎么样混合两者,比如
<input type='hidden' value="test">
?
Float:right为div表格单元格内部指定似乎对IE没有任何影响.除了其他方面,我还尝试了text-align,将图层内容对齐,但在IE 7中没有成功.
CSS片段:
.workloadcell {
background-color: #E6D7E9;
padding: 0px;
width: 14px;
height: 16px;
text-align: right;
}
div.workload {
background-color: #E6D7E9;
text-align: right;
width: 14px;
float: right;
}
Run Code Online (Sandbox Code Playgroud)
HTML片段:
<td class="workloadcell">
<div class="workload">
1
</div>
</td>
Run Code Online (Sandbox Code Playgroud)
HTML和CSS都可以验证,而在Firefox中,文本可以正确对齐.如果你想通过复制/粘贴它来测试完整的代码,它就在这里:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Table Test</title>
<style type="text/css">
td {
border: 1px solid black;
}
.workloadcell {
background-color: #E6D7E9;
padding: 0px;
width: 14px;
height: 16px;
text-align: right;
}
div.workload {
background-color: #E6D7E9;
text-align: …Run Code Online (Sandbox Code Playgroud) 我需要为 DLL 创建一个包装器,根据需要加载和卸载它(对于那些对这个问题的背景感兴趣的人,请参阅如何解决 Tomcat 应用程序访问的内存泄漏第 3 方 DLL(无源代码)?)。我在 Visual Basic 6 中执行此操作,并且使用以下示例进行加载和卸载:
Private Declare Function FreeLibrary Lib "kernel32" (ByVal hLibModule As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Sub cmdTestLoadingDLL_Click()
Dim lb As Long, pa As Long
lb = LoadLibrary("D:\projects\other\VB_DLLs\TestDLL\TestDLL.dll")
Msgbox "Library address: " + lb
FreeLibrary lb
End Sub
Run Code Online (Sandbox Code Playgroud)
我可以使用Process Explorer看到,当显示消息框时,DLL 被加载到内存中,然后被丢弃。然而,调用方法自然是不够的——我需要访问动态加载的 DLL 中的方法。
我怎样才能实现这个目标?我想调用 TestDLL 中 mainClass 类中的方法 getVersion,如下所示:
Private Declare Function FreeLibrary …Run Code Online (Sandbox Code Playgroud) 偶尔需要在循环中只存储一次布尔值(记录它已从false更改为true或反之亦然),同时执行循环到结束但不再关心布尔值的变化值.例:
public static boolean dbDelete(Collection argObjectCollectionToDelete) {
boolean result = true;
for (Object object : argObjectCollectionToDelete) {
boolean dbDelete = dbDelete(object);
if (!dbDelete) {
result = false;
}
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
有没有办法执行相当于代码
if (!dbDelete) {
result = false;
}
Run Code Online (Sandbox Code Playgroud)
要么
if (!dbDelete && !result) {
result = false;
}
Run Code Online (Sandbox Code Playgroud)
以更优雅的方式,最好是一条线?
我有一个包含三种不同状态类型的枚举.这些状态应显示在发送给用户的电子邮件中,包含要显示的状态的字符串存储在messages.properties中(使用Spring类org.springframework.context.MessageSource的实现读取).这在普通的Spring控制器中运行良好.但是,我更愿意在Enum中获得"显示状态"(在一个地方包含逻辑).
但是,将消息源自动连接到枚举,如下面的代码似乎不起作用,因为messageSource属性始终为空.
public enum InitechStatus{
OPEN("open"), CLOSED("closed"), BROKEN("broken");
public final String name;
@Autowired
private MessageSource messageSource;
InitechStatus(String name) {
this.name = name;
}
@Override
public String toString() {
String displayStatusString = messageSource.getMessage("page.systemadministration.broadcastmail.status."
+ this.name, null, Locale.ENGLISH);
return displayStatusString;
}
}
Run Code Online (Sandbox Code Playgroud)
如何在Enum中使用自动连线的消息源(或者是否有其他方法来实现我正在尝试的内容)?
java ×6
spring ×3
hibernate ×2
html ×2
properties ×2
alignment ×1
apostrophe ×1
autowired ×1
boolean ×1
criteria ×1
css ×1
css-float ×1
datasource ×1
dll ×1
dynamic ×1
eclipse ×1
enums ×1
file ×1
junit ×1
maven-2 ×1
oracle ×1
proxy ×1
toggle ×1
unit-testing ×1
vb6 ×1
web-services ×1
windows ×1