From my understanding of SOAP, it's all about request and and response and it always outputs the response in a cryptic format (XML).
However, a fellow student told me to create a SOAP Service that displays images from a DB (or a folder with images) - just like we know from Tumblr/Pinterest/etc.
I just don't understand how that's possible - if at all?
I think what they mean is storing the images in a folder somewhere on the server and storing the file path to them as strings in the database. At least that's how I would do it.
You could also possibly encode the data with something like base64 and store that plus other relevant information like the content type (jpeg/gif etc) + a filename for the file to later stick together/decode to form an image.
Also, just in my personal opinion SOAP/XML is the devil, and I would personally serve the data as JSON.
Related
I'm working in a team as a developer. We have developed a product where we generate letters by populating some XML file. This XML file ONLY contains some texts that need to show up in a pdf document. We then send this XML across to a different area via a web service (say WS-A) call.
This WS-A returns a generated PDF document as a byte stream. Please note that beside generating a pdf document, the backend of WS-A is responsible for the pdf template and how and where these XML texts are displayed in the document. Everything up to this point is fine.
I also do understand that our team needs to write test cases to make sure the correct XML contents are populated before sending it through WS-A.
My question is, is writing a test case which verifies this pdf has the right "texts" (only text verification) our team's responsibility?
Or is this something the other team (in charge of WS-A backend) has to test to make sure they don't miss anything in their PDF from the XML they have been provided (before sending it back to us as a byte stream)?
Yes and no as, it sounds to me like it is a shared responsibility.
As the developer, it is you and your teams job to make sure that you are sending the correct XML template and data. Where your responsibility ends, is once the data has been sent to the backend and the PDF has been generated. It sounds to me that the text being sent can vary so, I would just let the other team handle that since the variance is likely from their side of things.
I am building a website using java and google app engine. I need to create urls like www.mywebsite.com/the_dark_knight_rises
when a user goes to that url info is pulled from my database (mysql) about the movie The Dark Knight Rises and is displayed
The problem I have is
1) I don't know how to go on about making these dynamic urls, since my database contains 500k movies so i don't think i can make them manually
2) how do I pull info about that record. I got an idea to take the /the_dark_knight_rises part of the url replace the underscores with spaces and try to seach my database like select * from table where title like 'the dark knight rises' but i am not sure if this is the best solution or how to get that part of the url
Any help/directions are welcome
1) Use getPathInfo() or getRequestURI() to extract path from current url
2) Remove underscores from path and construct movie title
3) Make database call
4) Show movei if exists or show 404 if not.
If your intent is just to do this for SEO or readability purposes, you could always serve the urls as www.website.com/movie_name_in_text?id=abc123
This allows you to do a get by id on the database, but surfaces textual information for people and bots.
You should also probably look into using a Web MVC framework, such as Spring, thundr or similar. They can handle this type of data binding automatically, rather than requiring you to program to the low level servlet api.
Disclaimer, I'm a maintainer of thundr
I have a GWT app which is deployed on GAE. One part of my application relies on static data, which is currently stored in an XML file. The application reads this data into a collection of POJOs. The data is sent over to the client using GWT-RPC. Based on the selections made by the user, it applies filters to the collection to get specific objects (the filtering is done on the client side).
The data may contain up to 3000 records, and the total XML file size would be around 1MB. There'll be no updates on this data from the application side (it's read-only), but I may be frequently adding new records or updating/fixing existing records during the initial few months (as the application evolves). The data has no relationship with any other data in the application.
One of my main consideration in fetch performance. I tried using Apache Digester to parse the XML, but noticed that even parsing 600 records and sending them to the client was a bit slow.
Given these requirements which of the following would be better and why - 1. Keep the data in the XML file, or 2. Store the data in the app engine data store?
Thanks.
One alternative would be to load the XML file directly by GWT (without GWT-RPC and server parsing):
Use RequestBUilder to get the data from the server. Example usage: http://www.gwtapps.com/doc/html/com.google.gwt.http.client.html
Then use XMLParser to parse the reply. Example: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsXML.html#parsing
Here's an example combining both: http://www.roseindia.net/tutorials/gwt/retrieving-xml-data.shtml
The only downside is that you have to manually parse XML via DOM, where GWT-RPC directly produces objects.
Update:
based on the comments I'd recommend this:
Parse XML file with JAXB to create your objects: http://jaxb.java.net/guide/_XmlRootElement_and_unmarshalling.html
Save those to memcache: http://code.google.com/appengine/docs/java/memcache/overview.html
On RPC request, check memcache, if data not there goto 1.
The way I look at things, there are two bottle necks, though interrelated. One is loading the data (reading from XML, parsing). Another is sending it to the client.
Instead of sending the whole bunch, you might consider batch sending, like pagination.
Usually I prefer storing such files under WEB-INF.
My REST web service has to send an image file to the client. I am confused between 2 options : send the image as a byte array, or should I encode it as a base 64 string ? What are the pros and cons of each ? I may have to compress the image using gzip...should it create problem with any one of methods ? I may even need to expose my method as a SOAP service, which method should I prefer in that case ?
Thanks !!
The wonderful thing about a RESTful interface is that it's just HTTP. So if you expose the "byte array" version via REST, any browser can do an HTTP GET on your REST URL and receive and directly render your image. Returning the payload verbatim is far more RESTful than placing an encoding on it. There is not much to recommend an extra base64 encoding layer via REST.
If you're returning SOAP, you absolutely want to return a base64 string. Raw binary data is not compatible with XML, upon which SOAP is built. You can try to work around it via MTOM, but for general-purpose compatibility with SOAP clients you probably want inlined base64-encoded data.
In general, there's no benefit to be gained by compressing an image file. The image formats themselves internally involve compression, and a second compression pass will not gain any more space savings.
If your service returnes JSON or XML (image + some information), than you should encode image in base 64 because both of them string based, and you want to transfer byte array. The only question, whether you should make it yourself or it should be made my framework you use.
Situation with GZip is clear - relay compression to the servlet container (like tomcat - you can configure, whether response should be gzipped). Alternatively you can use something like GZipFilter.
Using Java (.jsp or whatever) is there a way where I can send a request for this page:
http://www.mystore.com/store/shelf.jsp?category=mens#page=2
and have the Java code parse the URL and see the #page=2 and respond accordingly?
Basically, I'm looking for the Java code that allows me to access the characters following the hash tag.
The reason I'm doing this is that I want to load subsequent pages via AJAX (on my shelf) and then allow the user to copy and paste the URL and send it to a friend. Without the ability of Java being able to read the characters following the hash tag I'm uncertain as to how I would manipulate the URL with Javascript in a way that the server would be able to also read without causing the page to re-load.
I'm having trouble even figuring out how to access/see the entire URL (http://www.mystore.com/store/shelf.jsp?category=mens#page=2) from within my Java code...
You can't.
The fragment identifier is only used client side, so it isn't sent to the server.
You have to parse it out with JavaScript, and then run your Ajax routines.
If you are loading entire pages (and just leaving some navigation and branding behind) then it almost certainly isn't worth using Ajax for this in the first place. Regular links work better.
Why can't you use a URL like this:
http://www.mystore.com/store/shelf.jsp?category=mens&page=2
If you want the data to be stored in the url, it's gotta be in the query string.