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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:15:22+00:00 2026-06-12T01:15:22+00:00

I have a Jetty server and I have disabled HTTP connections through rest services

  • 0

I have a Jetty server and I have disabled HTTP connections through rest services , so client connections must only come through https, but when a client tries to connect through http it throws a SocketException and treats that as the rest response. What I want to do is give a response when this happens and actually throw a custom descriptive error

  • 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-12T01:15:24+00:00Added an answer on June 12, 2026 at 1:15 am

    You may want to use a Filter like this

    public abstract class SSLOnlyFilter implements Filter {
    
      public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)  {
        // ... cast to HTTP counterparts
        if (request.isSecure()) {
          chain.doFilter(request, response);
        } else {
          response.setStatus(HttpServletResponse.SC_OK);
          // Set the message in the body
        }
      } 
    }
    

    Or a custom error page (less preferred)

    <error-page>
       <exception-type>java.net.SocketException</exception-type>
       <location>/someServletHere</location>
    </error-page>
    

    in your deployment descriptor.

    But I suggest to issue HTTP redirects when the client tries to connect without SSL. There are two easy ways to issue HTTP redirects: the RewriteHandler module and a Filter.

    This is how one configures the module with a RedirectRegexRule

    <New id="Rewrite" class="org.eclipse.jetty.rewrite.handler.RewriteHandler">
      <Call name="addRule">
        <Arg>
          <New class="org.eclipse.jetty.rewrite.handler.RedirectRegexRule">
            <Set name="regex">/(.+)</Set>
            <Set name="replacement">https://host:port/$1</Set>
          </New>
        </Arg>
      </Call>
    </New>
    

    Alternatively, you can do it with a Filter

    public abstract class SSLOnlyFilter implements Filter {
    
      public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)  {
        // cast to HTTP request and response
        if (request.isSecure()) {
          chain.doFilter(request, response);
        } else {
          response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
          // Edit this line with actual parameters. Note HTTPS
          response.setHeader("Location", "https://host:port/url");
        }
      } 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started a jetty server in my remote server. But I got problem
I have a basic Jetty server running locally. If I pull up http://localhost/servlet1 in
We have for all our tests a method which starts a Jetty Server to
I want to use the jetty httpclient (in netbeans) but have the least number
I have a Spring ApplicationContext where I declare Jetty server bean and start it.
I have deployed a .war file inside Jetty Server. The server has been started,
I have a piece of javascript executing on a jetty server which is sending
I have a piece of javascript executing on a jetty server which is sending
I have a third party server that is periodically sending http post request messages
I have an application which provides services using CXF's Servlet transport and Jetty 6.1.

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.