1

I have created a web service in java as follows:

@Path("/rest")
public class GetStatus {
    @GET
    @Produces("application/xml")
    @Path("/getMethod")
    public String getDetails() {
                  return "Hello World !!!";
    }

Corresponding web.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>MyWebService</display-name>
    <servlet>
        <servlet-name>ServletAdaptor</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.xmlws</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>ServletAdaptor</servlet-name>
        <url-pattern>/check/*</url-pattern>
    </servlet-mapping>
</web-app>

And I'm consuming it as follows:

String wsdl = "http://localhost:8080/MyWebService/check/rest/getMethod/";
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
HttpGet getMethod = new HttpGet(wsdl);
String responseString = null;
try {
           response = httpclient.execute(getMethod);

            StatusLine statusLine = response.getStatusLine();
            System.out.println("getStatusCode = " + statusLine.getStatusCode());
            if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                response.getEntity().writeTo(out);
                out.close();
                responseString = out.toString();
            } else {
                response.getEntity().getContent().close();
                throw new IOException(statusLine.getReasonPhrase());
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e..printStackTrace();
        }

But currently web service is HTTP. How do I make it HTTPS? What are requirements to do so?

I know how to access HTTPS web service from client but I want to create a HTTPS service first.

Any help appreciated on the same.

4
  • The server/servlet container manages which protocol to respond to. Google for Tomcat https for more info. There's some (relatively) small configuration you need to do. Commented Jun 26, 2013 at 14:13
  • How does Tomcat comes into picture? What if I want to publish it online? Commented Jun 26, 2013 at 14:19
  • Wherever you're publishing it, the web service will be running inside some web server. In your case, it'll be a servlet container (possibly Tomcat) since you're using servlets. Check it. Commented Jun 26, 2013 at 14:23
  • Ok. Got it. You can merge above two comments as an answer. Commented Jun 26, 2013 at 14:37

1 Answer 1

3

The server/servlet container manages which protocol to respond to. Wherever you're publishing it, the web service will be running inside some web server. In your case, it'll be a servlet container (possibly Tomcat) since you're using servlets.

There's some (relatively) small configuration you need to do and you can find it here if you're on Tomcat 7.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.