0

我正在尝试使用 browsermob-proxy 2.1.0-beta4 从我的移动设备捕获流量,但我不断收到一个NoSuchMethodError异常,奇怪的是不断提到 Google -java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.fromHost

这是我的代码(没有导入):

public class BrowserMobProxy {

    @Test
    public void checkConnection() throws JSONException, IOException, InterruptedException {


        SMAPLogger.Info("Connecting to Proxy");
        BrowserMobProxyServer mProxyServer = new BrowserMobProxyServer();
        mProxyServer.start(8888);
//        mProxyServer.setHarCaptureTypes(CaptureType.REQUEST_CONTENT);
        while (true) {
            Thread.sleep(1000);
            Har har = mProxyServer.getHar();
            if (har != null) {
                for (HarEntry entry : har.getLog().getEntries()) {
                    System.out.print("har");
                    System.out.print(entry.getRequest().toString());
                }
            }
        }
    }

}

这是我得到的例外:

11:39:00.618 [LittleProxy-0-ClientToProxyWorker-4] ERROR org.littleshoot.proxy.impl.ClientToProxyConnection - (AWAITING_INITIAL) [id: 0xf2cbf348, /192.168.100.105:40588 => /192.168.100.101:8888]: Caught an exception on ClientToProxyConnection
java.lang.NoSuchMethodError: com.google.common.net.HostAndPort.fromHost(Ljava/lang/String;)Lcom/google/common/net/HostAndPort;
    at net.lightbody.bmp.util.BrowserMobHttpUtil.removeMatchingPort(BrowserMobHttpUtil.java:355) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at net.lightbody.bmp.filters.HttpsAwareFiltersAdapter.getFullUrl(HttpsAwareFiltersAdapter.java:87) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at net.lightbody.bmp.filters.BlacklistFilter.clientToProxyRequest(BlacklistFilter.java:37) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at net.lightbody.bmp.filters.BrowserMobHttpFilterChain.clientToProxyRequest(BrowserMobHttpFilterChain.java:65) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ClientToProxyConnection.doReadHTTPInitial(ClientToProxyConnection.java:227) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:193) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ClientToProxyConnection.readHTTPInitial(ClientToProxyConnection.java:82) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ProxyConnection.readHTTP(ProxyConnection.java:135) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ProxyConnection.read(ProxyConnection.java:120) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ProxyConnection.channelRead0(ProxyConnection.java:587) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) ~[browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ProxyConnection$RequestReadMonitor.channelRead(ProxyConnection.java:715) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:263) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86) [browsermob-dist-2.1.0-beta-4.jar:?]
    at org.littleshoot.proxy.impl.ProxyConnection$BytesReadMonitor.channelRead(ProxyConnection.java:692) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [browsermob-dist-2.1.0-beta-4.jar:?]
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112) [browsermob-dist-2.1.0-beta-4.jar:?]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_60

]
4

1 回答 1

1

您使用的是旧版本的 Google Guava。

Browsermob 依赖于 Guava 版本 17+。

如果您使用的是 Maven,请将以下内容添加到您的 pom 文件中(如果您已经有直接的 Guava 依赖项,请替换该部分):

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>17.0</version> <!-- Or something newer like 19.0 -->
    </dependency>
于 2016-07-20T06:43:26.610 回答