Changing PHP developed backend to Java spring boot - java

I am not sure if this question gonna be considered as duplicated or not, but I wasn't able to find my answer even by googling or through out the QA suggested topics on the SOF. So here I go asking my question:
I have developed a website with Javascript, PHP , AJAX that's using JSON to talk to eachother. And now the client is asking me to change all PHP backend to Spring Boot. That means I gonna talk to the HTML and Javascript and MySql using Java EE Spring Boot and I am not sure how I gonna do it. My main problems are:
1- Is it possible to parse data from Java to the jQuery using JSON ? I mean I retrive data from the MySql and then send it back to the .php file.
The PHP example would be:
$myJSON = json_encode($myObj);
echo $myJSON;
2- Is it possible to get the parsed the respons from the JAVA through the jQuery :
jQuery.ajax({
type:"post",
dataType:"json",
url: myAjax.ajaxurl,
data: {action: 'submit_data', info: info},
success: function(getParsedVAL) {
// the variable getParsedVAL is comming from the JAVA file
successmessage = 'Data was succesfully captured';
$("label#successmessage").text(successmessage);
},
error: function(getParsedVAL) {
// the variable getParsedVAL is comming from the JAVA file
successmessage = 'Error';
$("label#successmessage").text(successmessage);
},
});
success: function(getParsedVAL) {
// the variable getParsedVAL is comming from the JAVA file
successmessage = 'Data was succesfully captured';
}

I’m actually transitioning to spring boot from php. Spring boot actually encodes the java object to json automatically. If you developed the back end with some lightweight framework with routing and model controller structure you can easily convert it to spring boost

Related

Get U are U figerprint template on PHP backend from Java

I'm currently trying to get fingerprint templates from java, I have already sent the templates over HTTP request but I don't know how to get it on Laravel PHP backend to save them as blob on database, I'm sending templates as ByteArrayInputStream. Thanks in advance!
My code:
ByteArrayInputStream[] templatesArray = new ByteArrayInputStream[4];
for(int i=0; i<fingers.size(); i++)
{
templatesArray[i] = new ByteArrayInputStream(fingers.get(i).getTemplate().serialize());
}
Next I send that array over http with Retrofit. I'm getting them as usual on laravel using:
$request->input('fingers')
Is it a POST? Suppose from a practical debugging standpoint I'd suggest starting with a limited script in that PHP apps public/root that simply does a var_dump($_REQUEST); If you don't get data there you will need to look at limits in the PHP environment on max_post_size.
If you do get data you should drop the java tag, add a Laravel tag, and slightly rephrase the question with what you've learned.
Assume it's essentially a file upload. You don't need to base64_encode anything on that Java side do you?

get database data from mysql to vue.js in servlet

Front end: HTML
Backend: Java servlet
I have to get data from database to vue.js to show in an HTML tag without the servlet's help. How can I get that data?
The task is a todo list. When I click on a specific button, text is stored to a database. After that, I have to display all the content that is stored in the database. This means all the data of the todo list should be displayed without the help of a select query from the servlet. How is this possible?
You have to run your servlet eg http://localhost:8888
Create API in your servlet like: POST /api/tasks/ for creation, GET /api/tasks/ to get all tasks etc. I am not Java programmer so I am using general conventions as making API is similar in all languages. If you don't know how - use Google to find something like 'Creating API in Java'
Add eg. Axios to your Vue application.
Consume your API with axios like
Vue.axios.get('http://localhost:8888/api/tasks').then((res)=>{
//server response data is available in res.data
// do whatever your want with your data
})
Hope it helps.

Cordova passbook from restful response

I am building a cordova application using the cordova-plugin-passbook plugin, which can be seen here: https://github.com/passslot/cordova-plugin-passbook.
I am trying to consume a pkpass from our java server that is returning the file as expected if we directly hit our service from a browser, but the problem is that we need to use an auth token and go through our oAuth server first. So I must request the pass via ajax in my front end using Angular.
The data I get back is an octet-stream and somehow I need to parse it and get it to work with the plugin above. The plugin is configured to look for a url ending in ".pkpass", I am wondering if it can be configured to look for the parsed data instead of a url.
Can anyone see in the src of the plugin if there is a possible way to do that? I am not very familiar with objective c, but just trying to think of options.
Thanks
Using cordova fileTransfer plugin, I got this working:
fileTransfer.download(
uri,
fileURL,
function(entry) {
Passbook.downloadPass(fileURL);
},
function(error) {
alert('Error retrieving pass, please try again in a little while.');
},
true,
{
headers: {
"Authorization": "Bearer " + LS.get( 'user_token' )
}
}
);

Sharepoint API for Java

Steps that I am trying to perform the following steps through Java:
1) Connect to a sharepoint site with a given URL.
2) Get the list of files listed on that page
3) Filter the files using Modified date
4) Perform some more checks using Create Date and Modified Date
5) And finally save that file(s) into the Unix box.
As of now, I am able to access a particular file and read through it.
However I need to get hold of file's metadata before reading it.
Is there an API or a way to do all these in Java.
Thanks
With SharePoint 2013, the REST services will make your life easier. In previous versions, you could use the good old SOAP web services.
For instance, you could connect to a list with this query on the REST API:
http://server/site/_api/lists/getbytitle('listname')/items
This will give you all items from that list. With OData you can do additional stuff like filtering:
$filter=StartDate ge datetime'2015-05-21T00%3a00%3a00'
Additionally, you can provide CAML queries to these services, allowing you to define detailed queries. Here's an example in Javascript:
var re = new SP.RequestExecutor(webUrl);
re.executeAsync({
url: "http://server/site/_api/web/lists/getbytitle('listname')/GetItems",
method: 'POST',
headers: {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json; odata=verbose"
},
body: {
"query" : {
"__metadata": {
"type": "SP.CamlQuery"
},
"ViewXml": "<View>" +
"<Query>" + query + "</Query>" +
"</View>"
}
},
success: successHandler,
error: errorHandler
});
If all of this doesn't provide enough flexibility, you might as well take these list items in memory and do additional work in your (server side) code.
I have developed a Sharepoint Rest API java wrapper that allows you to use most common operations of the rest API.
https://github.com/kikovalle/PLGSharepointRestAPI-java

Json based webservice in java and client in javascript

I am new in web service development. Currently I am developing an application (in html5 using javascript and jquery) in which I wanted to send data to web service in Json format.
My question are: 1) How to send(post) data to web service using javascript ? 2) How to retrieve json data at server side ? 3) How to get data from the web service in json format ? 4) How to retrieve json data at client side ?
Cast you json to string than send to server. In the server side cast it json again.
JSON is just a way to encapsulate data.
You should have parses on both sides that parse the json into data you can work with. On your Java serve you can use e.g. https://code.google.com/p/json-simple/
Easiest would be to use jquery ajax() function.
$.ajax({
type: 'post',
dataType: 'json',
data: { "var1": value1, "var2": value2 },
url: 'www.example.com' })
.success( function() {
console.log( 'success' );
});
This depends on what backend do you use on server, I can reccomend node.js with express.
The same as p1, the only difference that you will have to parse data you have received in success() function.
I am not sure if I understand correctly what you mean.

Categories

Resources