Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:50+00:00 2026-05-26T03:00:50+00:00

Look at the test code I have written below. Using pure java I set

  • 0

Look at the test code I have written below.
Using pure java I set an Authenticator and make a URI call to get some xml data and convert it to an object.

I wrote the code below to test performance of hotpotato (netty) vs. pure java (no pipelining).

The trouble is, I can’t figure out how to Authenticate my request with hotpotato or netty, code for either is acceptable, I just want to test the performance diff (i.e. see how many requests will be performed in 5 seconds).

    public static void main(String[] args) throws Exception {
        Authenticator.setDefault(new MyAuthenticator("DummyUser", "DummyPassword"));

        int timeToTestFor = 5000; //5 seconds;
        int count = 0;
        System.out.println("Start time");
        long starttime = System.currentTimeMillis();
        do {
            URL url = new URL(
                    "http://example.com/rest/GetData.ashx?what=pizza&where=new%20york&visitorId=12345&sessionId=123456");

            SearchResultsDocument doc = SearchResultsDocument.Factory.parse(url);
            count++;
        } while (System.currentTimeMillis() - starttime < timeToTestFor);
        System.out.println("DONE Total count=" + count);

        System.out.println("Netty/Hotpotatoe Start time");
        count = 0;
        starttime = System.currentTimeMillis();
        do {
            // Create & initialise the client
            HttpClient client = new DefaultHttpClient();
            client.init();


            // Setup the request
            HttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_0,
                    HttpMethod.GET, "/rest/GetData.ashx?what=pizza&where=new%20york&visitorId=12345&sessionId=123456");

            // Execute the request, turning the result into a String
            HttpRequestFuture future = client.execute("example.com", 80, request,
                    new BodyAsStringProcessor());
            future.awaitUninterruptibly();
            // Print some details about the request
            System.out.println("A >> " + future);

            // If response was >= 200 and <= 299, print the body
            if (future.isSuccessfulResponse()) {
                System.out.println("B >> "+future.getProcessedResult());
            }

            // Cleanup
            client.terminate();
            count++;
        } while (System.currentTimeMillis() - starttime < timeToTestFor);
        System.out.println("DONE Total count=" + count);
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:00:50+00:00Added an answer on May 26, 2026 at 3:00 am

    Here is working example of using basic authentication with Netty only. Tested with Jetty as a server requiring basic authentication.

    import java.net.InetSocketAddress;
    import java.util.concurrent.Executors;
    
    import org.jboss.netty.bootstrap.ClientBootstrap;
    import org.jboss.netty.buffer.ChannelBuffer;
    import org.jboss.netty.buffer.ChannelBuffers;
    import org.jboss.netty.channel.ChannelHandlerContext;
    import org.jboss.netty.channel.ChannelPipeline;
    import org.jboss.netty.channel.ChannelPipelineFactory;
    import org.jboss.netty.channel.Channels;
    import org.jboss.netty.channel.ExceptionEvent;
    import org.jboss.netty.channel.MessageEvent;
    import org.jboss.netty.channel.SimpleChannelHandler;
    import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
    import org.jboss.netty.handler.codec.base64.Base64;
    import org.jboss.netty.handler.codec.http.DefaultHttpRequest;
    import org.jboss.netty.handler.codec.http.HttpChunkAggregator;
    import org.jboss.netty.handler.codec.http.HttpClientCodec;
    import org.jboss.netty.handler.codec.http.HttpHeaders;
    import org.jboss.netty.handler.codec.http.HttpMethod;
    import org.jboss.netty.handler.codec.http.HttpResponse;
    import org.jboss.netty.handler.codec.http.HttpVersion;
    import org.jboss.netty.util.CharsetUtil;
    
    public class BasicAuthTest {
    private static final int PORT = 80;
    private static final String USERNAME = "";
    private static final String PASSWORD = "";
    private static final String URI = "";
    private static final String HOST = "";
    
    public static void main(String[] args) {
    
        ClientBootstrap client = new ClientBootstrap(
                new NioClientSocketChannelFactory(
                        Executors.newCachedThreadPool(),
                        Executors.newCachedThreadPool()));
    
        client.setPipelineFactory(new ChannelPipelineFactory() {
    
            @Override
            public ChannelPipeline getPipeline() throws Exception {
                ChannelPipeline pipeline = Channels.pipeline();
                pipeline.addLast("codec", new HttpClientCodec());
                pipeline.addLast("aggregator", new HttpChunkAggregator(5242880));
                pipeline.addLast("authHandler", new ClientMessageHandler());
                return pipeline;
            }
        });
    
        DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, URI);
    
        request.addHeader(HttpHeaders.Names.HOST, HOST);
    
        String authString = USERNAME + ":" + PASSWORD;
        ChannelBuffer authChannelBuffer = ChannelBuffers.copiedBuffer(authString, CharsetUtil.UTF_8);
        ChannelBuffer encodedAuthChannelBuffer = Base64.encode(authChannelBuffer);
        request.addHeader(HttpHeaders.Names.AUTHORIZATION, encodedAuthChannelBuffer.toString(CharsetUtil.UTF_8));
    
        client.connect(new InetSocketAddress(HOST, PORT)).awaitUninterruptibly().getChannel()
                .write(request).awaitUninterruptibly();
    
    }
    
    public static class ClientMessageHandler extends SimpleChannelHandler {
        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) throws Exception {
            e.getCause().printStackTrace();
        }
    
        @Override
        public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
            HttpResponse httpResponse = (HttpResponse) e.getMessage();
            String json = httpResponse.getContent().toString(CharsetUtil.UTF_8);
            System.out.println(json);
        }
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code that look similar to this: <xsl:choose> <xsl:when test=some_test>
lets get straight to my problem, the code I have written here does not
Take a look at this code: public class Test { public static void main(String...
I am new to Jquery and in learning phase. I have written a test
I am looking into scala TCO and have written the following code import scala.annotation.tailrec
So I'm using rspec to test my code as I'm going through the Rails
I have recently noticed that my test code is too close to the production
I'm having some problems using Sinatra with Capybara. I want to test a pure
What would a simple unit test look like to confirm that a certain controller
I've started to look into the whole unit testing/test-driven development idea, and the more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.