We are aware of the appengine limitation relating to writing files to disk. So the idea of having a dynamic sitemap via i/o seems a bit difficult for AppEngine. So here are some ideas that we wish to validate:
Can we have a servlet that generates a google sitemap compatible xml dynamically?
If this is possible, can someone share an example?
Can such a sitemap, in turn, contain dynamic links that return raw textual data suitable for indexing?
If the above is true, the only problem we see is that, such dynamic URLs, that are only meant for indexing content, will become available in search results. Instead we wish that users land directly on the homepage of the website.
With respect to SEO, given that the website is pure GWT, is there a better way to index content?
For dynamic URLs your only solution since you are using Java on Google App Engine is to create a servlet that will create this response.
There are many libraries that you can use that will make sure that your XML is correct but the simplest example that can get you started will look like this:
public class SitemapsServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("application/xml");
resp.getWriter().println("<?xml version="1.0" encoding="UTF-8"?>");
resp.getWriter().println("<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">");
resp.getWriter().println(" <url>");
resp.getWriter().println(" <loc>http://www.example.com/?id=who</loc>");
resp.getWriter().println(" <lastmod>2009-09-22</lastmod>");
resp.getWriter().println(" <changefreq>monthly</changefreq>");
resp.getWriter().println(" <priority>0.8</priority>");
resp.getWriter().println(" </url>");
resp.getWriter().println("</urlset>");
}
}
For the rest of the questions make sure that you understand how the sitemaps are working and what's their purpose.
Related
I am a bit new to the whole APEX service plugins but I was wondering if Salesforce has native support for Swagger, or any similar REST description language, for the REST api's that I create in the APEX service platform?
For example:
#RestResource(urlMapping='/v1/users/*')
global with sharing class UserRestService {
...
#HttpGet
global static List<Member__c> doGet(....)
{
...
}
}
I would like the ability to return the swagger json, a WADL document, or something for this REST service (and all other REST services I have in there). Does anyone know of a way I can do this?
Thanks in advance!
There is no built in support at this time. I was interested in seeing what could be done via currently available public APIs. The first thing I ran into is the grammar does not seem to like parameters to HttpGet methods. That right there will make it challenging since the only way to get input parameters appears to be via the Request entity which means you would have to parse the actual code. In other words, there does not appear to be declarative input binding.
Further, in looking at the tooling API which let's me get some amount of "reflective" information about the class, there is not always sufficient information to render a response payload (in your case, it just shows LIST but not what's in the list)
Again, it looks like one would have to rely on a parser (there is at least one Antl grammar floating around).
(this is getting some internal attention but I can't say any more at this time)
I'm trying to create my first GAE Endpoint app, and instead of generating an endpoint from a class, I'd like to create my own personalised Endpoint... is this possible?
I've written this class:
#Api(name="my_endpoint", path="my_endpoint")
public class MyFirstEndpoint {
#ApiMethod (name="my_method", path="my_method", httpMehod=HttpMethod.GET)
public Response myMethod(#Named("param1") String param1) {
...
}
}
But when I try to generate the Endpoint Client Library in Eclipse, it says that there was an error... and the worst thing is that it doesn't say what error it is!
Yes it's possible to create custom Endpoints.
I had the same error. I think you can't use "_" in the name of the Api nor the ApiMethod...
Try using "myEndpoint" and "myMethod" as the names and keep the "_" in the paths.
A bit unrelated to this particular case, but it's the first thing that popped up on Google when searching for the error: you can't have overloaded methods in your Endpoints classes. Found this by looking in the Error console as described above in a comment.
I take web application course this semester and I want to use google application engine to implement my course project, but I'm wondering if GAE can satisfy this project's requirements.
This course project is a homework submittal system which allows users(students) uploading homework to the sever and teachers checking homework online.
Assuming homework students uploaded is some html and css stuff. What confused me is how to implemnent teacher checking online function? For example:
Student A uploaded a html file hello.html and teacher want to use http: //xxx.xx/xx/xx/hello.html to check this homework.
Can GAE satisfy this requirement? As far as I konw, GAE uses app.yaml to point to different files or htmls, but when students upload their homework, they can not change app.yaml,right?
I get stuck here. Please help me. Thank you!
Yes, you can use GAE to create this application, but you'll have to move away from the idea that you are uploading and serving an HTML file as if it were living directly on the filesystem. You can't do that.
What you can do -- relatively easily -- is store the submitted file or files as datastore objects and provide a URL which takes the desired filename as a parameter and serves it out of the datastore.
You could store the submitted files in a model like this:
class HomeworkItem(db.Model):
author = db.UserProperty()
filename = db.StringProperty()
content = db.TextProperty(multiline=True)
submitted_on = db.DateProperty()
The content field is declared as a TextProperty assuming that you are dealing with HTML and CSS files, but if you were ever going to deal dealing with binary data, you'd want to use a BlobProperty.
You'd need to have two URLs to handle upload and download of assets. You can use a web framework or write some code to handle parameterized URLs, allowing you to encode things like the filename into the URL itself, like this:
http://homeworkapp.edu/review/hello.html
And then the method that handles /review/* URLs would retrieve the data from the datastore and send it back as the reply.
GAE would satisfy your requirement but you would need to save each “hello.html” file in either the Blobstore or the Datastore and build some system to retrieve and serve the uploaded files. See this Q&A for further reference.
What I'm looking for is some sort of class or annotation I can add to Java classes that are dedicated to handling specific requests, and having URLs map to these based on their name. For example, have the URL ".../api/GetContactsRequest" map to a handler named GetContactsRequest (or 404 if no such handler exists). I know I could write servlets and map each URL to each servlet, but I figure the less boilerplate routing code/configuration, the better! These will mostly be application request handlers, communicating using JSON. I haven't figured out how I'll be handling static requests, but I'll most likely just be sending a big web application at the user that navigates itself or something.
For background, I'm using the Google App Engine so I have access to yaml configurations and their servlet APIs. So is there a standard way of doing this with either the Java servlet APIs or the Google App Engine-specific framework? I've only ever used specific Java servlet frameworks like Apache and stuff before, which were all already built by the time I started working on them, so I really don't know what there is to use with this environment. I'm also new to this all in general, and having trouble wading through what Servlets, Services, Filters, Listeners, and Handlers all are, and which is best for this simple routing behavior that I want/need. I'm worried I'll pick the wrong one, or don't even know of the one that would suit my needs.
This is what JAX-RS does - not exactly class name mapping, but mapping via annotations. See some of the features.
There are several implementations, personally I use RESTEasy - it works flawlessly on GAE. Additionally I use Jackson (comes with RESTEasy) to produce JSON.
If you need to produce html then look at htmleasy - it's a thin layer on top of RESTEasy enabling use of different html templating libraries. It'll help you separate logic from presentation.
EDIT:
If you really want to avoid using standard libs and writing something on your own, then write a servlet filter that inspects the request and forwards it to your servlet (or invoke custom code):
public class ForwardFilter implements Filter {
#Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
if(request.getRequestURI().equals("/some/path")){
request.getRequestDispatcher("/path/where/servlet/registered").forward(request, response);
return; // prevents normal request processing
}
// you need this for normal request path
filterChain.doFilter(request, response);
}
}
I was browsing through the code of Vosao CMS, an open source CMS hosted on Google App Engine (which I think is an awesome idea), and I stumbled upon the following code inside the CurrentUser class:
/**
* Current user session value cache class. Due to GAE single-threaded nature
* we can cache currently logged in user in static property. Which we set in
* authentication filter.
*/
public class CurrentUser {
private static UserEntity user;
public static UserEntity getInstance2() {
return user;
}
public static void setInstance2(UserEntity aUser) {
user = aUser;
}
}
I've never used GAE, but this sounds really weird to me.
Is GAE really "single threaded"? Is it safe to store request-scoped data inside a static field when using GAE?
Does this mean that, for each JVM instance, only one HTTP request will be executed at a time, while all the other requests are waiting?
Is this a common GAE idiom? If not, what would be the best GAE idiom to store such an UserEntity for the duration of a request? Shouldn't one use a ThreadLocal here, like they do in Spring Security? Or some kind of scoped bean (managed by the Dependency Injection container)?
Is GAE really "single threaded"? Is it safe to store request-scoped data inside a static field when using GAE?
It used to be that way (until 1.4.3) and it still is by default.
Now, you can specify that your app is threadsafe, and then you will receive concurrent requests to the same JVM/servlet.
Does this mean that, for each JVM instance, only one HTTP request will be executed at a time, while all the other requests are waiting?
For other request, you would probably get another JVM. But that is outside of your control. They can also just wait.
Currently, the Java and Python runtimes on App Engine are both single threaded; you're correct that this means only one HTTP request will be executed per JVM, but multiple JVMs will be started simultaneously to handle multiple incoming requests.
This could change at any time in the future, however - the Java Servlet spec permits multi-threading. As a result, you should definitely use a ThreadLocal.