Note that there are some explanatory texts on larger screens.

plurals
  1. PODeploying and running a war file
    primarykey
    data
    text
    <p>(Please see the code Code below) I am able to run it on Tomcat in the eclipse environment and it works as it should. I have exported the following to a war file and created a Manifest.MF with:</p> <pre><code>Manifest-Version: 1.0 Main-Class: com.process.Test </code></pre> <p>When the code is ran in Eclipse the response from there server side is output to a console.</p> <p>Now finally my question (Pardon my ignorance, I am fairly new to this): </p> <p><strong>Once the war is deployed on my Tomcat server, how do I send a REST request or run the war and display the server response?</strong></p> <p>What is the equivalent to :http://localhost:8080/rest/xml/list on a live server?</p> <p>Web.xml</p> <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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"&gt; &lt;display-name&gt;com.process.Test&lt;/display-name&gt; &lt;servlet&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;servlet-class&gt;com.sun.jersey.spi.container.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;com.sun.jersey.config.property.packages&lt;/param-name&gt; &lt;param-value&gt;com.process.Test&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Jersey REST Service&lt;/servlet-name&gt; &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>Client side code:</p> <pre><code>import java.net.URI; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.UriBuilder; import com.sun.jersey.api.client.Client; //import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.config.ClientConfig; import com.sun.jersey.api.client.config.DefaultClientConfig; public class Test { public static void main(String[] args) { //Instead on using Apache Client //used default Jersey client //to send requests ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); String _package = "api.amebatv.com"; WebResource service = client.resource(getBaseURI(_package)); //runRequest(service,"indexpath"); runRequest(service,"list"); } /* * For testing purposes the base URI is :http://localhost:8080/package name * Will change to domain name for production code */ private static URI getBaseURI(String _package){ return UriBuilder.fromUri( "http://localhost:8080/api.process.com").build(); } private static void runRequest(WebResource service,String path){ String response = service.path("rest/xml/"+path).accept(MediaType.APPLICATION_XML).get(String.class); System.out.println("Post Response :"+response); } } </code></pre> <p>Server Side:</p> <pre><code>@Path("/xml") public class Service { // List of video objects private ArrayList&lt;Video&gt; videolist; //Parser object, parses xml into video objects private Parser parser = new Parser(); /* * Constructor * Parse XML and create video list on call */ public Service(){ parser.createXML(); videolist = parser.getList(); } /************************************************ *GET * Path: /indexpath * list of all only &lt;video&gt; items * @return : ArrayList of Video objects ***********************************************/ @GET @Path("/list") @Produces(MediaType.APPLICATION_XML) public List&lt;Video&gt; getCustomerInXML() { return videolist; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload