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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:57:43+00:00 2026-06-04T19:57:43+00:00

The Appache HTTP Components library seems to work fine for communicating with a regular

  • 0

The Appache HTTP Components library seems to work fine for communicating with a regular web site, but is unable to connect to a web service.

I am building come components to run inside a Java Desktop application that will communicate with a Web Service-REST using the Jersey framework. The web service is running and I can communicate it with my web browser and with the Test-Web-Service function in netbeans.

The client code works fine if I try to read from a regular web page or even the default page for the Glassfish web server running on my machine.
Why is it that when I try to reach the web service with my client program (code below) do I get a 404 Not Found error from the web server?

import java.io.*;
import org.apache.http.*;
import org.apache.http.client.*;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.client.methods.*;  //HttpHead, HttpPut, HttpGet, etc...
import org.apache.http.util.EntityUtils;

public class ApacheClientDemo {

  public static void demo() throws IOException {           
     String uri = "http://localhost:8080/Proctorest/resources/helloWorld";
     HttpClient httpclient = new DefaultHttpClient();
     HttpGet httpget = new HttpGet(uri);
     HttpResponse response = httpclient.execute(httpget);
     System.out.println(response.getStatusLine().toString());
     HttpEntity entity = response.getEntity();
     System.out.println();
     System.out.println(EntityUtils.toString(entity));       
  }

  public static void main(String[] args) {
    try {
        demo();
    }
    catch(IOException ioe) {
        System.out.println(ioe);
    }
  }
}

When going to a regular web site on-line or a non-web service site hosted locally, the output is

 HTTP/1.1 200 OK

Followed by the content of the web page.

The code above gives me

  HTTP/1.1 404 Not Found

Edit: Below is the code for the web service.
The web service code was generated from a Netbeans sample project.
Netbeans Sample Web Service project

/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
*
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
* Other names may be trademarks of their respective owners.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common
* Development and Distribution License("CDDL") (collectively, the
* "License"). You may not use this file except in compliance with the
* License. You can obtain a copy of the License at
* http://www.netbeans.org/cddl-gplv2.html
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
* specific language governing permissions and limitations under the
* License.  When distributing the software, include this License Header
* Notice in each file and include the License file at
* nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the
* License Header, with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
* 
* Contributor(s):
* 
* The Original Software is NetBeans. The Initial Developer of the Original
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
* Microsystems, Inc. All Rights Reserved.
* 
* If you wish your version of this file to be governed by only the CDDL
* or only the GPL Version 2, indicate your decision by adding
* "[Contributor] elects to include this software in this distribution
* under the [CDDL or GPL Version 2] license." If you do not indicate a
* single choice of license, a recipient has the option to distribute
* your version of this file under either the CDDL, the GPL Version 2 or
* to extend the choice of license to its licensees as provided above.
* However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is
* made subject to such option by the copyright holder.
*/

package helloworld;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import javax.ws.rs.Path;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Produces;
import javax.ws.rs.Consumes;

/**
* REST Web Service
*
* @author mkuchtiak
*/

@Stateless
@Path("/helloWorld")
public class HelloWorldResource {

    @EJB
    private NameStorageBean nameStorage;
    /**
    * Retrieves representation of an instance of helloworld.HelloWorldResource
    * @return an instance of java.lang.String
    */
    @GET
    @Produces("text/html")
    public String getXml() {
        return "<html><body><h1>Hello "+nameStorage.getName()+"!</h1></body></html>";
    }

    /**
    * PUT method for updating an instance of HelloWorldResource
    * @param content representation for the resource
    * @return an HTTP response with content of the updated or created resource.
    */
    @PUT
    @Consumes("text/plain")
    public void putXml(String content) {
        nameStorage.setName(content);
    }
}

/////////// NameStorageBean .java

import javax.ejb.Singleton;

/** Singleton session bean used to store the name parameter for "/helloWorld" resource
*
* @author mkuchtiak
*/
@Singleton
public class NameStorageBean {

    // name field
    private String name = "World";

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
  • 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-04T19:57:44+00:00Added an answer on June 4, 2026 at 7:57 pm

    I can not see how you deploy the service.

    try change (camel case is unusual for a service)

    String uri = "http://localhost:8080/Proctorest/resources/helloWorld";
    

    to lowercase “helloworld”

    String uri = "http://localhost:8080/Proctorest/resources/helloworld";
    

    or try

    String uri = "http://localhost:8080/helloworld";
    

    HOW TO GET ROUTE

    U:…\HelloWorld1\HelloWorld1\web\WEB-INF\sun-web.xml

    <sun-web-app error-url="">
      <context-root>/HW</context-root>
      <class-loader delegate="true"/>
      <jsp-config>
        <property name="keepgenerated" value="true">
          <description>Keep a copy of the generated servlet class' java code.</description>
        </property>
      </jsp-config>
    </sun-web-app>
    

    a) //localhost:8080/HW from <context-root>/HW</context-root>

    U:…\HelloWorld1\HelloWorld1\web\WEB-INF\web.xml

    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <servlet>
            <servlet-name>ServletAdaptor</servlet-name>
            <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>ServletAdaptor</servlet-name>
            <url-pattern>/hw/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    

    b) //localhost:8080/HW/hw from <url-pattern>/hw/*</url-pattern>

    U:….\HelloWorld1\HelloWorld1\src\java\helloworld\HelloWorldResource.java

    .....
    /**
     * REST Web Service
     *
     * @author mkuchtiak
     */
    
    @Stateless
    @Path("/helloworld")
    public class HelloWorldResource {
    ....
    

    c) //localhost:8080/HW/hw/helloworld from @Path("/helloworld")

    put a)b)c) parts from your 3 files together.

    Notice: the url Netbeans shows is wrong, only /HW is correct

    ...
        Incrementally deploying HelloWorld1
        Completed incremental distribution of HelloWorld1
        run-deploy:
        Browsing: http://localhost:8080/HW/resources/helloWorld
    ...
    

    ....
    public static void demo() throws IOException {           
         String uri = "http://localhost:8080/HW/hw/helloworld";
         HttpClient httpclient = new DefaultHttpClient();
         HttpGet httpget = new HttpGet(uri);
         HttpResponse response = httpclient.execute(httpget);
         System.out.println(response.getStatusLine().toString());
         HttpEntity entity = response.getEntity();
         System.out.println();
         System.out.println(EntityUtils.toString(entity));       
      }
    ....
    

    OUTPUT

    debug:
    HTTP/1.1 200 OK
    
    <html><body><h1>Hello World!</h1></body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the latest (4.0.1) Apache http core components library. However, my
I am using Apache HTTP components (4.1-alpha2) to upload a files to dropbox. This
I'm trying to get a web service running CF9 IIS7 testpage.cfm <cfinvoke webservice =https://nww.eastwickpark.nhs.uk/cfcs/test.cfc?wsdl
Yesterday Tomcat was running ok, but today when I try to run my web-app
I'm fetching a web page using the Apache httpcomponents Java library . After connecting
I have few different web services exposed by my web site. Here is a
org.apache.wicket.protocol.http.WebApplicationFactoryCreationException: Unable to create application factory of class org.apache.wicket.spring.SpringWebApplicationFactory at org.apache.wicket.protocol.http.WicketFilter.getApplicationFactory(WicketFilter.java:228) at org.apache.wicket.protocol.http.WicketFilter.init(WicketFilter.java:271) at
I'm a little unfamiliar both with the Servlet API and Apache Http Components. I
I have some big files to download with Apache's Http Components and I want
I'm trying to get into Java web development but seem to be running into

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.