I am calling a restful web service written in java from java script page and from restful web service i am returning J SON data. how can i encrypt the j son data in java so that no one can see the data using firebug and again i need to decrypt the data in java script page.
Somewhere i read about b son but i couldn't get much info about this.
Is there any way to do this.
Thanks in advance.
i am making ajax call from java script like this...
$.post(url,{cache: false, "_": $.now() },function(){
// code
}, "json");
and from server i am returning json data like this
objectmapper.writeValueAsString("String data");
Regardless of which encryption you use between the client and the server, there must be a point for the client where the data can be read. That is in the browser, which is exposed to javascript, and therefore to Firebug.
Bson is bynary Json (http://bsonspec.org/), and, unless javascript reads and writes the stream by itself (without parsing it into a clear text object), you would fall into the same problem.
Related
I am working on ecommerce application which is having backend written in java programming langauge.
Application is having code to listen Woocommerce Webhook events. I logged in Woocommerce site and check Webhook configuration and logs in Woocomerce->Status->logs. Logs are showing 200 status code in response. So, no problem I can see in Woocommerce webhook but my application is not listening any webhook events like order.created, etc.
What I was thinking to test it with any example java source code sothat I can get where is problem.
So, if anyone is having good java source code to test Woocommerce Webhook, Please suggest. If anyone face this problem ever, please share.
Not sure that you are fully aware of what WOO-Webhooks are intended to do.
Basically is send some post data to a specific link and from there it's up to you to do whatever wanted with data.
A simple receiverwith php can be (that you specified at Delivery URL)
<?php
//echo date("l jS \of F Y h:i:s A");
$msg = "woo order \n";
if($_SERVER['REQUEST_METHOD']=="POST")
{
$data = file_get_contents('php://input');
$msg .= strval($data);
}
// send email
mail("yourmail#mail.com","woo order",strval($msg));
//echo date("l jS \of F Y h:i:s A");
Response on mail can be something like:
Instead of processing, data is dumped to mail. It's up to you here to implement any logic since you got the data.
If wanted to process something with another language java then adapt it (do a web-server, externalize the link, process as suitable the data). Same steps as example provided.
On Logs can be found addition information about what was delivered, how ...
Let us suppose there is a jsp that needs to display the list of files shared shared by a particular IP. Client opens that jsp on his local server and the request is sent to a remote server to fetch the list.
Servlet on the server processes the request and fetches the list of files shared by that IP. Now how do the servlet send that list to the jsp page that requested it ?
JSP :
connection.openConnection(); // Connection sends IP as the query parameter to the
// remote servlet
Servlet :
doGet(..parameters..) {
list = getList(forThatIP);
// NOW HOW DO I SEND THIS LIST ?
}
One method that I thought was to send the whole data as a query string to a servlet on the client side(running a server such as tomcat) and then stash that list onto some file.Later jsp can parse the file and display the data. But that doesn't seem to be a good option.
Note: JSP is invoked when a servlet forwards after successfully sending the IP to remote servlet
You can use request.setAttribute() in the Servlet. Then you can use a JSP tag to retrieve the value in JSP. Investigate a bit on that.
EDIT :
In the Servlet doGet method, you can set the an attribute, say listOfFiles as:
resquest.setAttribute("listOfFiles",list);
Then in the JSP you can retirieve it using the EL expression:
${listOfFiles}
which is an inbuilt feature of JSP.
Alternatively, you can access it using
<% request.getAttribute("listOfFiles")%>
but it is bad to embed Java scriptlets inside JSPs.
If you're passing complex data (lists etc.) over a connection, you can look into using JSON or XML. Your JSP code should be able to parse either easily with the right library.
Actually it depends on how the jsp is invoked.
Do you perform a post onto it ? Does the servlet perform a forward ? Or is a sendRedirect() ?
According to this there are many ways to send data to your jsp. One is using request attributes or better, using request scoped beans. One other can be posting some sort of rappresentation of your list as a post parameter (be it json, xml or some custom format of yours).
Another thing to consider is, what are you using ? JSF ? Some Spring library ? According to that there may be other better (or worse) ways to send datas.
If working with simple JSP/Servlet on a small project I'd personally go with the request.setAttribute() way, indeed this will force me to invoke the jsp via something like
request.setAttribute("myList", yourListObject);
request.getRequestDispatcher("yourjsp.jsp").forward(request, response);
then in the jsp you can:
<% Object myListObj = pageContext.getRequest().getAttribute("myList"); %>
When you call a servlet from code, the best way is to use an HttpServlet and mimic the browser behavior.
Passing the data in the URL is a GET request. Useful only with relatively small chunks of data, but the semantics look like you want ("get a bit of data"). Something like http://myremoteserver.com/myServlet?ip=.... You will need a proper encoding of the parameters (the Java API can handle that).
Passing the data by writting into the stream will be a POST request. It has no limit in the data passed to the server, but the semantics is different ("change something in the system"). You could pass your data as a parameter inside the contents written, I am not really sure how to decode that. Another alternative is using a Servlet (no HttpServlet) and just treat the raw data.
In both cases the response will be returned in the connection output stream. You can use whatever format you like (an standard one like JSON will probably be best, even that defining your own XML). In this case, a viable alternative would be filenames separated by a 'safe' character (like \n or |). Quick, but it will be less flexible in the future.
I would go for a GET request and JSON encoding.
I want to send a file to the Browser via the REST Interface.
Can you suggest the most efficient way to do it, Keeping in mind the following?
Not much traffic.
I am fetching the file from HBase which means when I fetch it from HBase I get it in Byte Array.
The files are not in any folder in the server. The files can only be fetched from the HBase table.
The Front end is PHP and I do not know PHP.
In the REST api you can just pass the byte array to Response and it takes care of itself.
Using the following code -
#Produces("image/jpg")
public Response getImage() {
<Fetch it from where ever you have it>
Response.ok(<byteArrayOfTheFile>).build();
}
I am giving case study of WebService by which i send file:
It is always good to encode the file content and send it to the destination where they will be decode it and read the content.
Sending as an attachment is always open to the world becasue it is not encrypted.And if the network having high trafic chances of failure is high.
I'm working with a SOAP application in Java. A new API was added to the server that wants login credentials and returns a guid which is used in queries to the server. Unfortunately, the sample code was in Perl and I'm having trouble translating it to java:
my $client = SOAP::Lite->service("$URL/webservices.php?wsdl")->newSession("$USER", "$PASSWORD");
my $result = SOAP::Lite->service("$URL/webservices.php?wsdl")->getMyData($client->{'guid'});
I can barely read the Perl here, but I take it there's some sort of "newSession" protocol to SOAP that returns some sort of client object that contains a guid token.
Is there an equivalent to newSession in javax.xml.soap? I'm working with a pre-existing application, so switching to a different SOAP client api would not be easy.
All,
I'm trying to find out, unambiguously, what method (GET or POST) Flash/AS2 uses with XML.sendAndLoad.
Here's what the help/docs (http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00002340.html) say about the function
Encodes the specified XML object into
an XML document, sends it to the
specified URL using the POST method,
downloads the server's response, and
loads it into the resultXMLobject
specified in the parameters.
However, I'm using this method to send XML data to a Java Servlet developed and maintained by another team of developers. And they're seeing log entries that look like this:
GET /portal/delegate/[someService]?svc=setPayCheckInfo&XMLStr=[an encoded version of the XML I send]
After a Google search to figure out why the POST shows up as a GET in their log, I found this Adobe technote (http://kb2.adobe.com/cps/159/tn_15908.html). Here's what it says:
When loadVariables or getURL actions are
used to send data to Java servlets it
can appear that the data is being sent
using a GET request, when the POST
method was specified in the Flash
movie.
This happens because Flash sends the
data in a GET/POST hybrid format. If
the data were being sent using a GET
request, the variables would appear in
a query string appended to the end of
the URL. Flash uses a GET server
request, but the Name/Value pairs
containing the variables are sent in a
second transmission using POST.
Although this causes the servlet to
trigger the doGet() method, the
variables are still available in the
server request.
I don't really understand that. What is a "GET/POST hybrid format"?
Why does the method Flash uses (POST or GET) depend on whether the data is sent to a Java servlet or elsewhere (e.g., a PHP page?)
Can anyone make sense of this? Many thanks in advance!
Cheers,
Matt
Have you try doing something like that :
var sendVar=new LoadVars();
var xml=new XML("<r>test</r>");
sendVar.xml=xml;
sendVar.svc="setPayCheckInfo";
var receiveXML=new XML();
function onLoad(success) {
if (success) {
trace("receive:"+receiveXML);
} else {
trace('error');
}
}
receiveXML.onLoad=onLoad;
sendVar.sendAndLoad("http://mywebserver", receiveXML, "POST");
The hybrid format is just a term Macromedia invented to paint over its misuse of HTTP.
HTTP is very vague on what you can do with GET and POST. But the convention is that no message body is used in GET. Adobe violates this convention by sending parameters in the message body.
Flash sends the same request regardless of the server. You have problem in Servlet because most implementation (like Tomcat) ignores message body for GET. PHP doesn't care the verb and it processes the message body for GET too.