小编eis*_*eis的帖子

隔离框架与模拟框架的区别

"隔离框架"和"模拟框架"这两个术语有什么区别?

frameworks unit-testing mocking

9
推荐指数
2
解决办法
2051
查看次数

如何在子上下文中使用spring安全上下文

我正在尝试在子上下文中使用spring安全上下文,因此我可以在servlet上下文文件中使用url安全性.

我有:

  <filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        classpath:/spring-security.xml
    </param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>myapp-soap</servlet-name>
    <servlet-class>org.springframework.ws.transport.http.MessageDispatcherServlet</servlet-class>
    <init-param>
      <param-name>transformWsdlLocations</param-name>
      <param-value>true</param-value>
    </init-param>
  </servlet>
Run Code Online (Sandbox Code Playgroud)

在web.xml上,spring-security.xml上的一般安全配置和

<!-- Authorization configurations -->
<security:http auto-config="false" use-expressions="true"
    create-session="never"
    authentication-manager-ref="authenticationManager"
    entry-point-ref="authenticationEntryPoint">

    <security:custom-filter
        position="PRE_AUTH_FILTER" ref="serviceAuthenticationFilter"/>

    <security:intercept-url
        pattern="/GetForbiddenUrl" access="hasRole('roleThatDoesntExist')" />
    <security:intercept-url pattern="/**" access="permitAll" />
</security:http>
<!-- annotation security -->
<security:global-method-security pre-post-annotations="enabled"/>
Run Code Online (Sandbox Code Playgroud)

在myapp-soap-servlet.xml上.它不起作用但失败了

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/my-app/v1/soap]] (ServerService Thread Pool -- 192) JBWEB000284: Exception starting filter springSecurityFilterChain:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
Run Code Online (Sandbox Code Playgroud)

但是,如果我将<security:http>部分移动到spring-security root …

spring spring-ws spring-security jboss7.x

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

在现代Spring中应该如何同步http请求?

长期以来,Spring 一直推荐使用RestTemplate来同步 http 请求。然而,现在的文档说:

注意:从 5.0 开始,此类处于维护模式,仅接受较小的更改请求和错误。请考虑使用 org.springframework.web.reactive.client.WebClient ,它具有更现代的 API 并支持同步、异步和流场景。

但我还没有看到如何建议使用WebClient进行同步场景。文档中有这样的内容:

WebClient 可以通过在结果结束时阻塞来以同步方式使用

我已经看到一些代码库到处都使用 .block() 。然而,我的问题是,凭借一些反应式框架的经验,我逐渐明白阻止反应式调用是一种代码味道,实际上应该只在测试中使用。例如这个页面

有时,您只能将部分代码迁移为响应式,并且需要在更多命令式代码中重用响应式序列。

因此,如果您需要阻塞直到 Mono 的值可用,请使用 Mono#block() 方法。如果 onError 事件被触发,它将抛出异常。

请注意,您应该通过尽可能支持端到端的反应式代码来避免这种情况。您必须在其他反应式代码中间不惜一切代价避免这种情况,因为这有可能锁定整个反应式管道。

那么我是否错过了一些可以避免 block() 但允许您进行同步调用的东西,或者是否在任何地方都使用 block() 真的是这样?

或者 WebClient API 的意图是暗示人们不应该再在代码库中的任何地方进行阻塞?由于 WebClient 似乎是 Spring 提供的未来 http 调用的唯一替代方案,因此未来在整个代码库中使用非阻塞调用并更改代码库的其余部分以适应这一点是唯一可行的选择吗?

这里有一个相关的问题,但它只关注发生的异常,而我有兴趣听到一般的方法应该是什么。

java spring synchronous reactive spring-webclient

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

解压缩文件Zip异常:条目大小无效(预计193144但得到193138字节)

我试图解压缩文件(从FTP服务器检索):

ZipInputStream zis = new ZipInputStream(
    new FileInputStream(zipFile));
    ZipEntry ze = zis.getNextEntry();
    while (ze != null) {
        String fileName = ze.getName();
        File newFile = new File(outputFileName+outputFolder + File.separator + fileName);
        System.out.println("file unzip : " + newFile.getAbsoluteFile());
        FileOutputStream fos = new FileOutputStream(newFile);
        int len;
        while ((len = zis.read(buffer)) > 0) {
            fos.write(buffer, 0, len);
        }
        fos.close();
        sendFile = newFile;
        ze = zis.getNextEntry();
    }
    zis.closeEntry();
    zis.close();
    System.out.println("Done");
Run Code Online (Sandbox Code Playgroud)

我在.zip文件中只有一个文本文件.此代码在我的本地Windows机器上正常工作.但是,当部署到ubuntu服务器上时,它会抛出以下异常.

java.util.zip.ZipException: invalid entry size (expected 193144 but got 193138 bytes)
at java.util.zip.ZipInputStream.readEnd(ZipInputStream.java:386)
at java.util.zip.ZipInputStream.read(ZipInputStream.java:156) …
Run Code Online (Sandbox Code Playgroud)

java zip unzip

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

Java HashMap实现在Entry类中具有"下一个"成员.有什么用呢

Java HashMap实现在Entry私有类中具有"下一个"成员.因为,键的新值将覆盖旧值,在Entry类中使用"next"成员是什么.

static class Entry<K,V> implements Map.Entry<K,V> {
        final K key;
        V value;
        Entry<K,V> next;
        final int hash;

        /**
         * Creates new entry.
         */
        Entry(int h, K k, V v, Entry<K,V> n) {
            value = v;
            next = n;
            key = k;
            hash = h;
        }
   .....

}
Run Code Online (Sandbox Code Playgroud)

java hashmap

7
推荐指数
1
解决办法
2941
查看次数

防止在Maven child pom中覆盖依赖版本

我在父pom中有一个dependencyManagement部分

<dependencyManagement>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.2.1</version>
    </dependency>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

拥有它的孩子pom

<dependencies>
    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>4.0</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

我试图使用enforcer插件来防止这种覆盖在poms中,允许这些仅在父设置中设置,但是无法设置.我希望这会使构建失败.这可能,使用该插件或其他方式?

DependencyCovergence,它强制所有版本都是相同的,但这太严格了,因为我不想控制所有传递依赖 - 只是明确定义的那些.

如果我可以防止在子pom中引入任何新的依赖关系,我会很高兴 - 所有定义的内容应该在父pom中定义,然后在子代中提到,如果需要的话.

maven-3 maven

7
推荐指数
1
解决办法
9267
查看次数

不支持Spring Boot 405 POST方法?

怎样POST方法不支持Spring Boot MVC?我正在尝试实现一个接受实体列表的简单post方法:这是我的代码

@RestController(value="/backoffice/tags")
public class TagsController {

    @RequestMapping(value = "/add", method = RequestMethod.POST)
        public void add(@RequestBody List<Tag> keywords) {
            tagsService.add(keywords);
        }
}
Run Code Online (Sandbox Code Playgroud)

点击此URL如下:

http://localhost:8090/backoffice/tags/add
Run Code Online (Sandbox Code Playgroud)

请求机构:

[{"tagName":"qweqwe"},{"tagName":"zxczxczx"}]
Run Code Online (Sandbox Code Playgroud)

我收到:

{
    "timestamp": 1441800482010,
    "status": 405,
    "error": "Method Not Allowed",
    "exception": "org.springframework.web.HttpRequestMethodNotSupportedException",
    "message": "Request method 'POST' not supported",
    "path": "/backoffice/tags/add"
} 
Run Code Online (Sandbox Code Playgroud)

编辑:

调试Spring Web Request Handler

     public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.checkRequest(request); 

 protected final void checkRequest(HttpServletRequest request) throws ServletException {
        String method = request.getMethod();
        if(this.supportedMethods != null …
Run Code Online (Sandbox Code Playgroud)

java spring spring-boot

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

将postgresql转储导入Heroku

我有一个java应用程序和postgresql数据库,以便在Heroku上运行它.我可以推送我的应用程序,但DB内容怎么样?我从数据库导出了一个完整的转储,但我不知道如何导入它.

通过谷歌搜索,你可以找到关于db:push这是一个有限的rubygem,而不是推动所需的所有东西.我有序列,bigint数据类型等.我也尝试导入使用heroku pg:psql --app MYAPP < db_all.out它只是连接和停止,并转到heroku pg:psql --app MYAPP并发出\i db_all.out有关权限的投诉.

我该怎么办?

postgresql heroku

6
推荐指数
2
解决办法
5157
查看次数

用PHP测试.如何确保正确运行?

首先,我不知道它是否被称为单元测试.如果它有不同的名称,请随时纠正我.

我正在开发像这样的Web应用程序.

假设我正在开发一个表单来将值保存到数据库中.我开发HTML和PHP.我有时间在浏览器中按F5并检查HTML/jQuery是否没有错误,PHP不会出现错误的分号等错误.

当它完成并且一切都准备好进行测试时,我开始测试我的代码的一小部分.喜欢;

  1. -Do $ _POST数组是否正确地从表单文件中获取值?(我用print_r测试)
  2. - "$ email"变量是否正确清理为有效的电子邮件?(我用不同的能力测试它,例如:aaa @ bbb,aa @ bb.com,@@ b.net等)
  3. - 提交的表单是否通过了所有控件,并成功插入到数据库中?(我查看我的MySQL表.)
  4. - 表单是否正确显示错误/成功消息?
  5. -...等等.

如果它使用正确的值,并且失败并返回错误的值; 我相信表单按预期工作,没有错误,所以我转向其他事情.

而不是这样做,我想确保事情完美无缺,否则在没有垃圾邮件F5浏览器的情况下通知我这个问题.

像这样;

<?php
/* Unit Testing Start --
-ensure: isset($_POST['submit']) returns TRUE;
-ensure: isset($email) returns TRUE;
-ensure: isValidEmail($email) returns TRUE;
-ensure: connectDatabase() returns TRUE;
-ensure: getMysqlAffectedRows() returns 1;
-ensure: hasErrors() returns false;
*/

?>
Run Code Online (Sandbox Code Playgroud)

我的表单代码使用我上面发布的功能.

当它运行时,它应该向我显示如下消息:(最好还记录它)

Test complete. Tested (6) possibilities, (4) succeeded, (2) failed. 
Failed 1: isValidEmail() returned FALSE, expected: TRUE. 
Failed 2: getMysqlAffectedRows returned NULL/0, expected …
Run Code Online (Sandbox Code Playgroud)

php testing automated-tests

6
推荐指数
1
解决办法
422
查看次数

访问被拒绝:http://repo.maven.apache.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom,ReasonPhrase:Forbidden

我试图构建 Maven 项目,

每当我在命令行上运行“mvn clean install”时,都会出现以下错误:

无法解析项目 com.my_project:jar:0.0.1-SNAPSHOT 的依赖项:无法收集 [com.datastax.cassandra:cassandra-driver-core:jar:3.0.1 (compile), org.apache.kafka 的依赖项:kafka-clients:jar:0.9.0.1(编译)、org.apache.kafka:kafka_2.10:jar:0.9.0.1(编译)、com.thinkaurelius.titan:titan-core:jar:1.0.0(编译) ), com.tinkerpop.blueprints:blueprints-core:jar:2.6.0 (编译), com.thinkaurelius.titan:titan-cassandra:jar:1.0.0 (编译), com.thinkaurelius.titan:titan-all: jar:1.0.0(编译)、org.aspectj:aspectjrt:jar:1.6.5(编译)、com.jayway.awaitility:awaitility:jar:1.6.5(编译)、junit:junit:jar:4.11(测试)]:无法读取 commons-codec:commons-codec:jar:1.4 的工件描述符:无法从/向中央传输工件 commons-codec:commons-codec:pom:1.4 (http://repo.maven.apache.org/maven2):拒绝访问:http : //repo.maven.apache.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom , 理由:禁止。-> [帮助 1]

请帮助我,我是 JAVA 世界的新手。

这是我拒绝访问的某种代理设置吗?

maven

6
推荐指数
2
解决办法
8063
查看次数