小编ins*_*ect的帖子

当apache.httpclient能够获取内容时,JSoup.connect会抛出403错误

我试图解析任何给定页面的HTML转储.我使用HTML Parser并尝试使用JSoup进行解析.

我在Jsoup中找到了有用的函数,但是在调用时遇到403错误 Document doc = Jsoup.connect(url).get();

我尝试了HTTPClient,以获得html转储,并且它在同一个网址上获得了成功.

为什么JSoup为同一个URL提供403,它提供来自公共http客户端的内容?难道我做错了什么?有什么想法吗?

java html-parsing jsoup

19
推荐指数
1
解决办法
8013
查看次数

在hibernate条件查询中选择"group by"的"all columns"

我想使用"group by"编写条件查询,并希望返回所有列.

Plane sql是这样的:

select * from Tab group by client_name order by creation_time;
Run Code Online (Sandbox Code Playgroud)

我知道它会有count(distinct client_name)多少行.

我当前的查询似乎没有给出正确的结果如下:

Criteria criteria = getSession(requestType).createCriteria(Tab.class);
        criteria.setProjection(Projections.projectionList().add(Projections.groupProperty("client_name")));
        criteria.addOrder(Order.asc("creationTime"));
Run Code Online (Sandbox Code Playgroud)

此查询"client_name"仅返回.我不想手动输入所有列名.必须有某种方式,可以做些什么?

java mysql hibernate group-by hibernate-criteria

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

具有注释驱动的弹簧任务的多个弹簧任务执行器

我有一个类MessageProcessor被另一个类中的另一个方法调用(即调用者).

public class Caller {
@Scheduled(filxedDelay=10)
public void poll(){
//do stuff
messageProcessor.process(msg);
}

}

public class MessageProcessor{

@Async(value="abcExecutor")
public void process(String msg){
//do stuff here.
}

}
Run Code Online (Sandbox Code Playgroud)

Spring文件看起来像:

<task:executor id="abcExecutor" pool-size="9" rejection-policy-"CALLER_RUNS"/>
Run Code Online (Sandbox Code Playgroud)

我想添加另一个@Async执行程序:

 @Async(value="defExecutor")
    public void remove(String msg){
    //do stuff here.
    }

@Scheduled(filxedDelay=10)
public void kill(){
//do stuff
messageProcessor.remove(msg);
}
Run Code Online (Sandbox Code Playgroud)

通过在spring文件中添加另一个执行程序:

<task:executor id="defExecutor" pool-size="9" rejection-policy="CALLER_RUNS"/>
Run Code Online (Sandbox Code Playgroud)

但是如何在中添加多个执行程序 <task:annotation-driven executor="abcExecutor" scheduler="scheduler" mode="proxy" proxy-target-class="true"/>

如何使用注释运行这些多个执行程序?

PS:显然,我不希望这两种@Async方法都使用相同的池

java spring scheduled-tasks spring-annotations

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

传递参数与从函数返回参数

从标题中可以清楚地看出我们应该采用哪种方法?

意图是传递一些方法参数并获得输出.我们可以传递另一个参数,方法会更新它,方法现在不需要返回任何东西,方法只会更新输出变量,它会反映给调用者.

我只想通过这个例子来构建问题.

List<String> result = new ArrayList<String>();

for (int i = 0; i < SOME_NUMBER_N; i++) {
    fun(SOME_COLLECTION.get(i), result);
}

// in some other class
public void fun(String s, List<String> result) {
    // populates result
}
Run Code Online (Sandbox Code Playgroud)

List<String> result = new ArrayList<String>();

for (int i = 0; i < SOME_NUMBER_N; i++) {
    List<String> subResult = fun(SOME_COLLECTION.get(i));
    // merges subResult into result
    mergeLists(result, subResult);
}

// in some other class
public List<String> fun(String s) {
    List<String> res = new ArrayList<String>(); …
Run Code Online (Sandbox Code Playgroud)

java parameter-passing pass-by-reference

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

导致TestNG中的Test跳过的配置失败,没有XML中的信息

我正在试验TestNG,它正在从eclipse开始工作.我创建了一个测试套件并尝试从命令行运行它.

构建失败,错误说明

构建期间的最终输出说:

  [testng] ===============================================
   [testng] Suite
   [testng] Total tests run: 1, Failures: 0, Skips: 1
   [testng] Configuration Failures: 1, Skips: 2
   [testng] ===============================================
   [testng] 
   [testng] The tests failed.
Run Code Online (Sandbox Code Playgroud)

testng-results.xml和index.html没有报告任何失败.

testng-failed.xml是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Failed suite [Default suite]">
  <test name="Default test(failed)">
    <classes>
      <class name="ABC.test.integration.PersistUrlTests">
        <methods>
          <include name="springTestContextAfterTestClass"/>
          <include name="springTestContextBeforeTestClass"/>
          <include name="springTestContextPrepareTestInstance"/>
          <include name="springTestContextAfterTestMethod"/>
          <include name="checkTest"/>
        </methods>
      </class> <!-- ABC.test.integration.PersistUrlTests -->
    </classes>
  </test> <!-- Default test(failed) -->
</suite> <!-- Failed suite [Default suite] -->
Run Code Online (Sandbox Code Playgroud)

测试看起来如下:

@Test …
Run Code Online (Sandbox Code Playgroud)

java junit testng

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

当几乎所有线程都处于NATIVE状态时,ThreadDump问题

我在大多数线程处于(state = IN_NATIVE)状态的应用程序中进行了主机的线程转储。

在这些情况下,只有几个线程被阻塞:

Thread 31681: (state = BLOCKED)
 - sun.misc.Unsafe.park(boolean, long) @bci=0 (Interpreted frame)
 - java.util.concurrent.locks.LockSupport.park(java.lang.Object) @bci=14, line=156 (Interpreted frame)
 - java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await() @bci=42, line=1987 (Compiled frame)
 - java.util.concurrent.LinkedBlockingQueue.take() @bci=29, line=399 (Compiled frame)
 - java.util.concurrent.ThreadPoolExecutor.getTask() @bci=78, line=947 (Interpreted frame)
 - java.util.concurrent.ThreadPoolExecutor$Worker.run() @bci=18, line=907 (Compiled frame)
 - java.lang.Thread.run() @bci=11, line=662 (Interpreted frame)
Run Code Online (Sandbox Code Playgroud)

Thread 20966: (state = BLOCKED)
 - java.lang.Object.wait(long) @bci=0 (Compiled frame; information may be imprecise)
 - com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run() @bci=34, line=534 (Compiled frame)
Run Code Online (Sandbox Code Playgroud)

Thread 31682: (state = BLOCKED) …
Run Code Online (Sandbox Code Playgroud)

java multithreading jstack thread-safety thread-dump

5
推荐指数
1
解决办法
5883
查看次数

DynamoDBSaveExpression 对 GSI 进行条件检查

我想进行更新,但我想添加的条件检查不是基于主表的哈希/范围,而是基于 GSI。

实际上,如果给定的属性(即 GSI 的哈希值)已经存在,我想使保存失败。

例如,在一个虚构的员工表中,“SSN”是哈希键,“EmployeeId”上有一个 GSI。这两个属性都必须是独一无二的。在保存员工时,我想确保表中没有使用“SSN”或“EmployeeId”。我可以为表的哈希值(即 SSN)执行此操作,但不能为 GSI 的哈希值执行此操作。

是否支持?我在文档中没有看到。

谢谢!

amazon-dynamodb secondary-indexes dynamodb-queries

5
推荐指数
1
解决办法
1154
查看次数

将 cloudwatch 日志推送到 elasticsearch 的 Cloudformation 模板

我正在寻找一个 Cloudformation 模板来将 cloudwatch 日志推送到另一个帐户中的 elasticsearch。即使是同一个帐户也可以,我可以更新。

似乎是一个标准问题,但还没有看到任何模板可以自动执行https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_ES_Stream.html 中描述的步骤。

amazon-web-services aws-cloudformation amazon-cloudwatch aws-elasticsearch

5
推荐指数
1
解决办法
2637
查看次数

你写的代码行

出于好奇,有没有办法获得你编写的代码行数(在特定的项目中)?

我尝试过perforce p4 describe #CLN | wc -l,但除了这么多边缘情况(包含注释,添加新行等)之外,它还会跳过新添加的文件.边缘情况可以忽略,如果我们尝试显示物理代码行但新添加的文件仍然会导致问题.

perforce lines-of-code

4
推荐指数
2
解决办法
6227
查看次数

Mockito验证:在验证()期间验证,而不是在模拟方法调用期间验证

我用方法列表调用方法performAction并验证相同的方法.调用此方法后,我修改了一些"对象".

Mockito验证失败说参数不匹配(显示修改过的对象)但我可以在调试模式下看到对象在需要时是正确的.

理想情况下,这不应该发生,因为应该在实际调用方法时应用验证.在测试方法验证调用期间验证是否适用于模拟方法调用时?

测试类

@Test
public void test() throws Exception {
    List<ABC> objects = new ArrayList<ABC>();
    //populate objects.
    activity.performActions(objects);               
    verify(activity, times(1)).doActivity(objects);
}
Run Code Online (Sandbox Code Playgroud)

测试方法:

public void performActions(List<ABC> objects) {

    activity.doActivity(urlObjects2PerformAction);
    //Modify objects                

}
Run Code Online (Sandbox Code Playgroud)

我得到的错误如下(这是完整的代码.我给出了最小的可能代码段):

Argument(s) are different! Wanted:
activity.doActivity(
.......
......
Run Code Online (Sandbox Code Playgroud)

java junit verify mockito

4
推荐指数
1
解决办法
2784
查看次数