This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Web Services and the fly likes Developing Java 6 Webservice with Tomcat-project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Developing Java 6 Webservice with Tomcat-project" Watch "Developing Java 6 Webservice with Tomcat-project" New topic
Author

Developing Java 6 Webservice with Tomcat-project

xin sa
Greenhorn

Joined: May 02, 2007
Posts: 11
I have a prob:

1.create a Tomcat-Project named "TomWs"
2.in WEB-INF\src create "HelloServlet.java"

import java.io.*;
import javax.servlet.http.*;
import javax.servlet.*;
import javax.swing.JOptionPane;
import javax.xml.ws.Endpoint;


public class HelloServlet extends HttpServlet {
public void doGet (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{
Endpoint endpoint = Endpoint.publish( "http://localhost:8080/services",
new sayHello() );
res.setContentType( "text/html" );
PrintWriter out = res.getWriter();
out.println( "<html>" );
out.println( "Hallo, mein erstes Servlet meldet sich." );
out.println( "</html>" );
out.close();
JOptionPane.showMessageDialog( null, "Server beenden" );
endpoint.stop();

}
}

"sayHello.java"

import javax.jws.soap.SOAPBinding;
import javax.jws.*;

@WebService(name="XinServ",targetNamespace="http:///")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class sayHello
{
@WebMethod
public String hello( String name )
{
return "Hello " + name + "!";
}

@WebMethod(operationName="body-mass-index")
@WebResult(name = "your-bmi")
public double bmi( @WebParam(name="height") double height,
@WebParam(name="weight") double weight )
{
return weight / (height * height) / 100 * 100;
}
}

3. compile the tow classes in Web-Inf\classes
4. create web.xml in WEB-INF\web.xml

<!DOCTYPE web-app PUBLIC
'-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN'
'http://java.sun.com/dtd/web-app_2_3.dtd'>
<web-app>
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>HelloServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>

5. start Tomcat-server in eclipse
6. (Problem)
-- input the "http://localhost:8080/TomWs/hello" --> nothing in the
browser, but there are small dialog "server beenden"
-- input the "http:localhost:8080/services?wsdl" --> nothing and nothing


Why??? How can i see my WSDL-file?
please help me!!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41591
    
  55
Welcome to JavaRanch.

This is an uncommon way to create a web service. See this thread for a more standard way.

-- input the "http://localhost:8080/TomWs/hello" --> nothing in the
browser, but there are small dialog "server beenden"
-- input the "http:localhost:8080/services?wsdl" --> nothing and nothing


I think the URLs should be http://localhost:8080/TomWs/services/XinServ and http://localhost:8080/TomWs/services/XinServ?wsdl, respectively, but I'm not sure about that.

Also, the URL in the EndPoint constructor (http://localhost:8080/services) looks wrong; "http://localhost:8080/TomWs/services" might be correct (assuming that the name of the web app is "TomWs").


Ping & DNS - my free Android networking tools app
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41591
    
  55
Well, I'll be. After playing around with this it looks as if the EndPoint constructor URL is correct. The WSDL is served at http://localhost:8080/services?wsdl, although the name of the web app is not "services".

(This only works until the little dialog is dismissed, because that causes the endpoint to be stopped.)
xin sa
Greenhorn

Joined: May 02, 2007
Posts: 11
Thank you for your Welcom and your Reply very much.

Does it mean, that you have seen the wsld-File? How did you do it?
i need this wsdl-file with "wsimport" to create the Stubs for client-side programm. But I cann't see it, even now. Or have you a another better idear for this?

ps: befor, this worked without Tomcat (only java6) very good, for my job i must do it with tomcat, but now it doesn't work
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41591
    
  55
Does it mean, that you have seen the wsld-File? How did you do it?

It's at the URL shown in my second post (which is the same one you posted initially). What are you seeing at that URL? As I said, this only works as long as you don't close the little dialog.
xin sa
Greenhorn

Joined: May 02, 2007
Posts: 11
Oh Yes!!! I see it! Thank you!! Thank you!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Developing Java 6 Webservice with Tomcat-project