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 8991595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:45:55+00:00 2026-06-15T22:45:55+00:00

I am developping a Swing application that needs to communicate with a distant HTTP

  • 0

I am developping a Swing application that needs to communicate with a distant HTTP server. That application can be potentially used behind proxies.

I must then :
– detect automatically network proxy (potentially several on the same network)
– let the user manually enter a proxy configuration.

I want to write an integration test to validate thoses aspects, without having to install proxies on every CI machines and every developper machine.
How I see things :

  • integration test (with junit) start an “embedded” proxy (@BeforeClass) and a somewhat dummy http server
  • my tests (@Test)
    • test that this proxy can be detected automatically and open a connection to my dummy http server and successfully retrieve datas from it
    • manually set the proxy and perform the same test as above

I have heard about the “littleProxy” component but didn”t tried it yet.

Can anyone shed some advice / help / guidance regarding the best approach to solve my problem ?

  • 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-06-15T22:45:56+00:00Added an answer on June 15, 2026 at 10:45 pm

    I would consider whether you are testing the right thing. You don’t need to test proxy servers or Java’s network classes.

    Consider this utility type for reading data from a URL:

    public final class Network {
        public interface UrlOpener {
            public InputStream open(URL url) throws IOException;
        }
    
        private static UrlOpener urlOpener = new UrlOpener() {
            public InputStream open(URL url) throws IOException {
                return url.openStream();
            }
        };
    
        public static InputStream openUrl(URL url) throws IOException {
            return urlOpener.open(url);
        }
    
        public static void setUrlOpener(UrlOpener urlOpener) {
            Network.urlOpener = urlOpener;
        }
    }
    

    This can be used as an abstraction layer between your code and Java’s network I/O:

    public class SomeType {
        public void processData(URL url) throws IOException {
            InputStream input = Network.openUrl(url);
            // process the data
        }
    }
    

    Your tests use this layer to mock out the data:

    @Before public void setup() throws IOException {
        final URL mockUrl = this.getClass().getResource("/foo/bar.txt");
        Network.UrlOpener opener = Mockito.mock(Network.UrlOpener.class);
        Answer<InputStream> substituteUrl = new Answer<InputStream>() {
            public InputStream answer(InvocationOnMock invocation) throws Throwable {
                return mockUrl.openStream();
            }
        };
        Mockito.when(opener.open(Mockito.any(URL.class))).then(substituteUrl);
        Network.setUrlOpener(opener);
    }
    
    @Test public void testSomething() throws IOException {
        SomeType something = new SomeType();
        something.processData(new URL("http://example.com"));
    }
    

    This saves any mucking around with firewalls etc.

    In order for this approach to work you would want to have confidence in a set of recorded transactions from real servers to use in your tests.

    This approach can be complemented with a dedicated machine running more comprehensive integration tests.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please help. I am developing a swing application that can open reports made using
I am developing an application that will be running behind the scenes in Windows
I have a server application and two Swing-based client applications. We're developing them in
I'm developping a mono user desktop application using SWING. I had a little experience
In the application I'm developping (in Java/swing), I have to show a full screen
i am developing a java swing application that doesn't fit the normal application profile.
We are developing a desktop application using Java Swing that requires to show width
I'm developing an application that features multiple Swing GUIs. The main GUI has a
I am developing client-server application in Java which need user login. For that I
I'm developping a Java/Swing application with a menu using JMenuBar, JMenu and JMenuItem. System

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.