Sunday, 11 August 2013

[GWT-2.5.1]How can I succeed at a RPC deploying without the domain name server?

[GWT-2.5.1]How can I succeed at a RPC deploying without the domain name
server?

I hope to parse some XML data using a server side code.
[ParsingService interface]
package com.client;
import java.util.List;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
import com.shared.WebNewsItem;
@RemoteServiceRelativePath("parsingService")
public interface ParsingService extends RemoteService {
List<WebNewsItem> getWebNews(String url);
}
[ParsingServiceAsync interface]
package com.client;
import java.util.List;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.shared.WebNewsItem;
public interface ParsingServiceAsync {
void getWebNews(String url, AsyncCallback<List<WebNewsItem>> callback);
}
[ParsingServiceImpl server side code]
package com.server;
import java.util.List;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.client.ParsingService;
import com.shared.WebNewsItem;
@SuppressWarnings("serial")
public class ParsingServiceImpl extends RemoteServiceServlet implements
ParsingService {
@Override
public List<WebNewsItem> getWebNews(String url) {
WebNews news = new WebNews(url);
return news.getItems();
}
}
[WebNewsItem shared class]
package com.shared;
import java.io.Serializable;
public class WebNewsItem implements Serializable {
private static final long serialVersionUID = -2556739786406044054L;
private String title;
private String link;
private String guid;
private String category;
private String pubDate;
private String description;
public WebNewsItem(String title, String link, String guid, String
category, String pubDate, String description) {
this.title = title;
this.link = link;
this.guid = guid;
this.category = category;
this.pubDate = pubDate;
this.description = description;
}
public WebNewsItem() {
}
public String getTitle() {
return title;
}
public String getLink() {
return link;
}
public String getGuid() {
return guid;
}
public String getCategory() {
return category;
}
public String getPubDate() {
return pubDate;
}
public String getDescription() {
return description;
}
}
And, [WebNews server side class]
package com.server;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import com.shared.WebNewsItem;
public class WebNews {
private Document document;
private Element root;
private NodeList itemNodeList;
private List<WebNewsItem> items = new ArrayList<WebNewsItem>();
public WebNews(String url) {
try {
document =
DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(url);
root = document.getDocumentElement();
itemNodeList = root.getElementsByTagName("item");
addItems(items);
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
}
public List<WebNewsItem> getItems() {
return items;
}
private void addItems(List<WebNewsItem> items) {
for(int i=0; i<itemNodeList.getLength(); i++) {
Element element = (Element) itemNodeList.item(i);
items.add(new WebNewsItem(
element.getElementsByTagName("title").item(0).getFirstChild().getNodeValue(),
element.getElementsByTagName("link").item(0).getFirstChild().getNodeValue(),
element.getElementsByTagName("guid").item(0).getFirstChild().getNodeValue(),
element.getElementsByTagName("category").item(0).getFirstChild().getNodeValue(),
element.getElementsByTagName("pubDate").item(0).getFirstChild().getNodeValue(),
element.getElementsByTagName("description").item(0).getFirstChild().getNodeValue()));
}
}
}
Maybe if the client specifies a XML URL, this service will start.
Fortunately, the client received the news. But it only happend on my
localhost:8080 after compiling. So, it seemed as if the html page could be
seen such a crust. This is because of RPC not calling on my vps server.
[web.xml file]
<?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" version="2.5">
<servlet>
<servlet-name>ParsingServiceImpl</servlet-name>
<servlet-class>com.server.ParsingServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ParsingServiceImpl</servlet-name>
<url-pattern>/webapp/parsingService</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>Service.html</welcome-file>
</welcome-file-list>
</web-app>
[GwtXml.gwt.xml]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
<module rename-to="webapp">
<inherits name="com.google.gwt.user.User" />
<source path="client" />
<source path="server"/>
<source path="shared" />
<entry-point class="com.client.GwtXml" />
<servlet class="com.server.ParsingServiceImpl" path="/parsingService"/>
</module>
The host page is ok.
<script src="webapp/webapp.nocache.js"></script>
I think that these were complicated by having no domain on my web site.
(http://123.4.567.890/) But I could not say because this server is 15-day
free trial. And a week has passed.
On that server, I installed jetty9 server. I can deploy to jetty9 server
for my some non-RPC GWT applications. But...
OS: Ubuntu
$JETTY_HOME=/usr/local/jetty9/
[GwtXml.war]
/usr/local/jetty9/webapps/GwtXml.war
[GwtXml.xml]
/usr/local/jetty9/webapps/GwtXml.xml
The code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//En"
"http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/GwtXml</Set>
<Set name="war">/usr/local/jetty9/webapps/GwtXml.war</Set>
</Configure>
Those permissions:
sudo chmod -R go+rx blabla

When I go to http://123.4.567.890:8080/GwtXml
(http://123.4.567.890:8080/GwtXml/),


And when I click to the war directory,
WEB-INF
Service.html
style.css ....
When I click Service.html,
JS and CSS are ok. But RPC is not good. If this is not on the vps server,
it works fine.

(i)Why my welcome-file in the web.xml doesn't work?
(ii)Why my RPC server side code doesn't work on the vps server?

This is a URL to parse
(http://news.google.com/news?hl=en&ned=us&ie=UTF-8&output=rss&num=10&q=).

No comments:

Post a Comment