开发者

Java EE 6 tutorial, getting 404 error with helloservice

I'm working my way through the Java EE 6 tutorial and I'm on the section about web services. I'm trying to get the helloservice running, because I'm going to need to do something similar in the near future. However, while it builds and deploys with no errors, when I try to use it, I get 404 errors from GlassFish. I've looked in the GlassFish logs and found nothing indicating any problems. Here's the code from the service:

package helloservice.endpoint;

import javax.jws.WebService;
import javax.jws.WebMethod;

@WebService
public class Hello {
    private Stri开发者_运维百科ng message = "Hello, ";

    public void Hello() {
    }

    @WebMethod
    public String sayHello(String name) {
        return message + name + ".";
    }
}

Based on what I've read, @WebService should expose the class with the service name HelloService (base class name + "Service"). However, when I go to:

http://localhost:8080/helloservice/HelloService?wsdl

I get a 404 error. I've worked through all the prior examples, so I know that GlassFish is running and that it is responding on port 8080 for other applications I've deployed. I can see in the admin console that helloservice is deployed and running. "asadmin list-domains" shows that my domain1 (my only domain) is running. I thought perhaps the default for the @WebService annotation was wrong, so I set an explicit value using @WebService(serviceName = "Foobar") but that didn't make a difference when I tried checking the wsdl (replacing HelloService with Foobar).

I've seen some other people have had a similar problem, but I have not seen any solutions posted. Can anyone explain what might be wrong, or how to fix it?


Ensure that you are using the Glassfish full profile and not the Glassfish web profile. After your war is deployed, start the Glassfish Administration Console, click on "Applications". Your "Engines" column should look something like:

[ejb,jpa,web,webservices,weld]

If webservices isn't there, your Glassfish implementation isn't seeing your SOAP service.


If you read web.xml from admin console, you can see this.

<servlet-mapping>
    <servlet-name>HelloService</servlet-name>
    <url-pattern>/hello</url-pattern>
</servlet-mapping>

I tried http://localhost:8080/helloservice/hello?wsdl instead of http://localhost:8080/helloservice/HelloService?wsdl (one in tutorial) and it worked fine. Guess tutorial wasn't updated properly.


However, while it builds and deploys with no errors, when I try to use it, I get 404 errors from GlassFish. I've looked in the GlassFish logs and found nothing indicating any problems.

This usually indicates that there are no issues with the deployed artifacts on the server. After all a 404 error indicates that the client has issued an invalid HTTP request. In simpler words, the GET request issued is incorrect, and that you ought to send a different one.

Based on what I've read, @WebService should expose the class with the service name HelloService (base class name + "Service")

Yes, that is the default. But, more importantly, have you specified the context root of the application correctly? The following is the content of glassfish-web.xml from the tutorial:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <context-root>/helloservice</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>
</glassfish-web-app>

Notice the use of the <context-root>/helloservice</context-root> element, which appears before the Service name in the URL. It is likely that you are using an incorrect context root in your request, resulting in the 404 error.

If you need to verify the location that you intend to be sending requests to, you would find hints of the same in the Glassfish logs on deployment of the web service, like the one listed below

INFO: WS00018: Webservice Endpoint deployed

Hello listening at address at http://localhost:8080/helloservice/HelloService

INFO: Metro monitoring rootname successfully set to: amx:pp=/mon/server-mon[server],type=WSEndpoint,name=/helloservice-HelloService-HelloPort

INFO: WEB0671: Loading application [helloservice] at [/helloservice]

INFO: helloservice was successfully deployed in 1,616 milliseconds.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜