小编b10*_*10y的帖子

如何在Apache HTTP Client 4中使用Socks 5代理?

我正在尝试创建通过SOCKS5代理通过Apache HC 4发送HTTP请求的应用程序.我不能使用app-global代理,因为app是多线程的(我需要为每个实例使用不同的代理).我没有找到使用HC4的SOCKS5的例子.我怎么用呢?HttpClient

java dns socks apache-httpclient-4.x

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

从include'd/import'ed项目中检索属性值

我试图使用ant的include或import任务来使用公共构建文件.我被困在从包含文件中检索属性.

这些是我的非工作样本,试图检索"儿童财产"

使用ant导入

父文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="parent" basedir=".">
    <import file="child.xml" />
    <target name="parent-target">
        <antcall target="child-target" />
        <echo message="(From Parent) ${child-property}" />
    </target>
</project>
Run Code Online (Sandbox Code Playgroud)

子文件

<?xml version="1.0" encoding="UTF-8"?>
<project name="child" basedir=".">
    <target name="child-target">
        <property name="child-property" value="i am child value" />
        <echo message="(From Child) ${child-property}" />
    </target>
</project>
Run Code Online (Sandbox Code Playgroud)

产量

parent-target:

child-target:
     [echo] (From Child) i am child value
     [echo] (From Parent) ${child-property}
Run Code Online (Sandbox Code Playgroud)

使用ant包括

父文件

<project name="parent" basedir=".">
    <include file="child.xml" />
    <target name="parent-target">
        <antcall target="child.child-target" />
        <echo message="(From Parent) ${child-property}" /> …
Run Code Online (Sandbox Code Playgroud)

ant

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

Class.forName等效于从String创建ParameterizedType的

调用java.lang.reflect.Type.toString()提供了非常好的泛型类型表示:

@Test
public void typeToStringWithTypeToken() {
    assertEquals("java.util.List<java.lang.String>", new TypeToken<List<String>>() {}.getType().toString());
}
Run Code Online (Sandbox Code Playgroud)

我需要的是Type.toString()方法的反向,即可以Type从给定的字符串表示创建s 的方法:

public static Type parseTypeString(String typeString) throws ClassNotFoundException {
    if (typeString.indexOf('<') == -1) {
        return Class.forName(typeString);
    }
    // ??? how to implement rest
    throw new IllegalStateException("not implemented");
}
Run Code Online (Sandbox Code Playgroud)

哪个可以通过以下特殊类型的测试:

@Test
public void justSimpleClassName() throws Exception {
    assertEquals(Integer.class, parseTypeString("java.lang.Integer"));
}

@Test
public void listOfInteger() throws Exception {
    assertEquals(new TypeToken<List<Integer>>() {}.getType(), parseTypeString("java.util.List<java.lang.Integer>"));
}

@Test
public void complexType() throws Exception {
    assertEquals(new TypeToken<Map<List<Integer>, Set<String>>>() {}.getType(), …
Run Code Online (Sandbox Code Playgroud)

java generics

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

仅发布依赖项

我想从模块的jar工件中单独发布模块的依赖项.

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0">
  <info organisation="com.mycompany" module="platform" />
  <configurations defaultconfmapping="release->*;compile->*" defaultconf="release">
    <conf name="release" />
    <conf name="compile" extends="release" />
  </configurations>
  <publications>
    <artifact name="platform-api" type="jar" ext="jar" />
  </publications>
  <dependencies>
    <dependency org="com.google.inject" name="guice" rev="3.0" />
    <dependency org="org.slf4j" name="slf4j-api" rev="1.6.6" />

    <dependency org="com.google.guava" name="guava" rev="13.0-rc1" conf="compile" />
    <dependency org="log4j" name="log4j" rev="1.2.17" conf="compile" />
    <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.6.6" conf="compile" />
  </dependencies>
</ivy-module>
Run Code Online (Sandbox Code Playgroud)

对于上面的配置,我想要一个仅包含guice和slf4j-api jar的工件,没有platform-api.jar.我目前的解决方案是在依赖模块中定义两个依赖项,一个是传递的,另一个不是:

<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" conf="myconf->release">
  <exclude org="com.mycompany" />
</dependency>
<dependency org="com.mycompany" name="platform" rev="1.0-SNAPSHOT" transitive="false" conf="myotherconf->release" />
Run Code Online (Sandbox Code Playgroud)

但是当第三个模块依赖于这两个模块时,这个解决方案会导致问题,而且它只是丑陋.

ivy

0
推荐指数
1
解决办法
589
查看次数

标签 统计

java ×2

ant ×1

apache-httpclient-4.x ×1

dns ×1

generics ×1

ivy ×1

socks ×1