小编lim*_*imc的帖子

使用Servlet 2.5测试Spring Framework 4

我在使用Servlet 2.5让Spring Framework 4与我现有的项目一起工作时遇到了问题.我的web项目实际上运行正常,但我的测试用例失败并且它是由引起MockHttpServletRequest此异常引起的: -

java.lang.NoClassDefFoundError: javax/servlet/AsyncContext
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
Run Code Online (Sandbox Code Playgroud)

我尝试添加任一依赖项,但我会得到其他与Servlet 3.0相关的异常: -

<dependency>
 <groupId>javax</groupId>
 <artifactId>javaee-api</artifactId>
 <version>6.0</version>
 <scope>test</scope>
</dependency>

<dependency>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>servlet-api</artifactId>
  <version>3.0.20090124</version>
  <scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

基于Spring Framework网站,它可以与Servlet 2.5一起使用.但是,Spring 4MockHttpServletRequest似乎依赖于Servlet 3.0.

我该如何解决这个问题?谢谢.

java spring spring-test

15
推荐指数
1
解决办法
8063
查看次数

Spring MVC @ResponseBody返回一个Map会产生"Error 406 NOT ACCEPTABLE"

我在尝试设置@ResponseBody以返回集合时遇到问题.我在类路径中有JAXB jar,我没有设置任何ContentNegotiatingViewResolver.

这是我的简单对象: -

@XmlRootElement(name = "test-object")
@XmlAccessorType(XmlAccessType.FIELD)
public class TestObject implements Serializable {

    @XmlAttribute
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }
}
Run Code Online (Sandbox Code Playgroud)

我写了一个简单的测试,它返回一个对象...这没有问题,我能够看到生成的XML: -

@RequestMapping(value = "one", method = RequestMethod.GET)
public @ResponseBody TestObject getSingleObject() {
    TestObject obj = new TestObject();
    obj.setId(1);

    return obj;
}
Run Code Online (Sandbox Code Playgroud)

我真正想要的是返回一个对象列表.阅读后,似乎这样做的方法是将列表放在地图中并返回地图: -

@RequestMapping(value = "all", method = RequestMethod.GET)
public @ResponseBody Map<String, ? extends Object> getAllObjects() {
    TestObject obj1 = new TestObject();
    obj1.setId(1);

    TestObject …
Run Code Online (Sandbox Code Playgroud)

xml spring spring-mvc jaxb

14
推荐指数
3
解决办法
2万
查看次数

如何检测音频已在网页中播放完毕?

在我的项目中,我需要将音频(例如:mp3等)嵌入到网页中.当用户访问该页面时,音频将开始播放.当音频结束时,将出现问卷(表单字段)供用户回答.

有没有办法检查音频是否已经使用jquery完成播放,以便问卷可以在用户收听整个音频后出现?

我知道检查的一种方法是确定音频长度,然后我可以设置一个计时器来显示问卷,但我希望jquery有一些事件处理程序可以让我完成这个.

我看到jquery有很多音频插件,我不能确定哪个会做我想要的:http://plugins.jquery.com/plugin-tags/audio

任何想法都非常感谢.

谢谢.

javascript audio jquery jquery-plugins

13
推荐指数
1
解决办法
1万
查看次数

泽西岛:@Consumes在没有设置内容类型时不起作用

我想知道@Consumes如何在这里工作.

我有一个简化的资源,如下所示,我只希望这个资源使用"application/vnd.myApp + xml".

@Path("/app")
@Consumes("application/vnd.myApp+xml")
@Produces("application/vnd.myApp+xml")
public class AppResource {
    @POST
    public Response postStuff() {
        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

我有以下测试用例: -

public class AppResourceTest extends JerseyTest {
    @Test
    public void testApp() {
        // #1: Works fine
        ClientResponse response = resource().path("app")
                    .accept("application/vnd.myApp+xml")
                    .post(ClientResponse.class);

        ...

        // #2: Throws a 415 Unsupported Media Type
        ClientResponse response = resource().path("app")
                    .accept("application/vnd.myApp+xml")
                    .type("text/plain")
                    .post(ClientResponse.class);

        ...

        // #3: Works fine
        ClientResponse response = resource().path("app")
                    .accept("application/vnd.myApp+xml")
                    .type("application/vnd.myApp+xml")
                    .post(ClientResponse.class);

        ...
    }
}
Run Code Online (Sandbox Code Playgroud)

从上面的3个测试中,#2和#3按预期工作.

至于#1,如果我没有设置内容类型,为什么不抛出415呢?

java rest junit jersey

13
推荐指数
1
解决办法
6175
查看次数

将C#RSACryptoServiceProvider转换为JAVA代码

我得到了Web服务团队编写的这个C#代码,它公开了我计划使用的一些Web服务.我的密码需要使用此代码加密,以便Web服务知道如何解密它.

using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
    rsa.FromXmlString(publicKey);
    byte[] plainBytes = Encoding.Unicode.GetBytes(clearText);
    byte[] encryptedBytes = rsa.Encrypt(plainBytes, false);
    return Convert.ToBase64String(encryptedBytes);
}
Run Code Online (Sandbox Code Playgroud)

我正在使用Java来使用这个Web服务,而且现在,我在将#C代码转换为Java代码时遇到了问题,因为该Web服务无法正确解密我的密码.

这是我目前失败的尝试: -

// my clear text password
String clearTextPassword = "XXXXX";

// these values are provided by the web service team
String modulusString = "...";
String publicExponentString = "...";

BigInteger modulus = new BigInteger(1, Base64.decodeBase64(modulusString.getBytes("UTF-8")));
BigInteger publicExponent = new BigInteger(1, Base64.decodeBase64(publicExponentString.getBytes("UTF-8")));

KeyFactory keyFactory = KeyFactory.getInstance("RSA");

RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(modulus, publicExponent);
PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);

Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding"); …
Run Code Online (Sandbox Code Playgroud)

c# java security encryption rsa

12
推荐指数
1
解决办法
7083
查看次数

Jenkins:如何更改LDAP密码

我的机构要求我定期更改我的LDAP密码.

过去,我能够执行以下步骤来更改密码: -

但是,Jenkins的最新版本不再使用<managerPassword/>.相反,我看到了<managerPasswordSecret/>.

我不知道如何生成新的密码,所以我做了以下事情: -

  • /var/lib/jenkins/config.xml先备份.
  • 编辑/var/lib/jenkins/config.xml并更改<useSecurity/>false.
  • 重启Jenkins服务.
  • 去詹金斯.
  • 启用LDAP安全性.
  • 输入新的LDAP密码.
  • 保存.
  • 打开/var/lib/jenkins/config.xml并复制<managerPasswordSecret/>.
  • 恢复备份配置文件.
  • 替换<managerPasswordSecret/>为新值.

这令人难以置信.

有没有更简单的方法让我在将来维护我的LDAP密码更改?

非常感谢!

continuous-integration hudson jenkins

12
推荐指数
3
解决办法
8866
查看次数

CodeIgniter:从所有文件夹中删除index.html是否安全?

我是CodeIgniter的新手.我注意到所有CodeIgniter文件夹(缓存,配置,控制器,核心,错误等)都包含一个index.html文件,基本上说"禁止访问目录".如果我错了,请纠正我,但我不认为可以根据CodeIgniter的默认配置从Web获取任何这些文件夹.

这些index.html文件的目的是什么?我可以删除它们,还是将它们单独留下?

非常感谢.

php codeigniter

11
推荐指数
1
解决办法
2839
查看次数

Eclipse RCP:如何从目标定义文件中的软件站点下载增量包?

我正在使用这种技术为我的Eclipse RCP项目创建一个目标平台:http://www.modumind.com/2009/09/01/creating-an-eclipse-rcp-target-platform/

使用软件站点直接下载RCP SDK.至于delta包,我手动从网站下载它,并在目标定义文件中添加了目录,在我想下次升级delta pack版本时,我觉得这很乏味.

是否可以使用软件站点下载增量包?或者至少以较少的手动和更易维护的方式进行?

谢谢.

java eclipse-rcp target-platform delta-pack

10
推荐指数
2
解决办法
9480
查看次数

Spring Security:requires-channel ="https"导致重定向循环

我在尝试<security:intercept-url ... requires-channel="https"/>在WAS上正常工作时遇到了问题.应用程序服务器已启用SSL.

当我有这样的配置时: -

<security:http auto-config="true">
    <security:form-login .../>
    <security:logout .../>

    <security:intercept-url pattern="/admin/**" access="ROLE_ADMIN" />
    <security:intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" />
</security:http>
Run Code Online (Sandbox Code Playgroud)

......我可以打两http://server/myapphttps://server/myapp.在这两种情况下,Spring Security都能拦截此URL并向我显示登录页面.

现在,我想要做的是将所有http网址重定向到https网址.所以,我加入requires-channel="https"<security:intercept-url />

<security:http auto-config="true">
    <security:form-login .../>
    <security:logout .../>

    <security:intercept-url pattern="/admin/**" access="ROLE_ADMIN" requires-channel="https" />
    <security:intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" requires-channel="https" />
</security:http>
Run Code Online (Sandbox Code Playgroud)

...现在,当我尝试击中时http://server/myapp,我看到http://server/myapp/myapp/myapp/myapp/myapp/myapp它进入重定向循环.

所以,我重新定义了端口映射: -

<security:http auto-config="true">
    <security:form-login .../>
    <security:logout .../>

    <security:intercept-url pattern="/admin/**" access="ROLE_ADMIN" requires-channel="https" />
    <security:intercept-url pattern="/**" access="ROLE_ADMIN,ROLE_USER" requires-channel="https" />

    <security:port-mappings>
        <security:port-mapping http="80" https="443"/>
    </security:port-mappings>
</security:http>
Run Code Online (Sandbox Code Playgroud)

...当我尝试点击时 …

java ssl websphere spring spring-security

10
推荐指数
1
解决办法
1960
查看次数

配置IntelliJ以使用Groovy编译器而不是Java编译器

在我的maven项目中,我正在将我的Java代码与一些Groovy代码混合在一起.我现在主要使用Groovy构建bean.我的一些Java代码直接使用Groovy bean.

我像这样配置了Maven编译器插件: -

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <compilerId>groovy-eclipse-compiler</compilerId>
        <source>${jdk.version}</source>
        <target>${jdk.version}</target>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.8.0-01</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.1.5-03</version>
        </dependency>
    </dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)

当我使用我的测试用例时mvn test,它工作得很好.

但是,当我通过右键单击测试文件直接从IntelliJ运行测试用例并运行它时,我在Groovy bean上遇到"找不到符号"错误.当我读取错误日志时,IntelliJ使用Java编译器在运行测试之前编译我的项目...因此,测试失败.

我似乎无法弄清楚如何指示IntelliJ始终使用Groovy编译器而不是Java编译器.

我应该在SDK下更改什么才能使用Groovy编译器?我尝试添加Groovy相关的JAR文件,但我还有其他错误.

在此输入图像描述

更新1:根据@Seagull建议

我在"全球图书馆"下添加了groovy JAR: -

在此输入图像描述

当我直接从IntelliJ执行测试文件时,我收到一些Groovy警告,我仍然得到同样的错误: -

在此输入图像描述

谢谢.

java groovy intellij-idea maven

8
推荐指数
2
解决办法
1万
查看次数