Cordova passbook from restful response - java

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' )
}
}
);

Related

How to get "POST" method to show with Rest Web Services

I am new to Rest web services, and I am trying to figure out what I am doing wrong. When I run on server with the address:
localhost:8080/rest/webresources/error
Then the output message I want (the error message) shows up.
But when I run on the server to show input values using:
localhost:8080/rest/webresources/inputvalues
it doesn't. What am I doing wrong? I feel like my path is wrong, and I tried different combinations of it, but it still gives me a 404 not found error.
#Path("error")
public class RestWeb {
#GET
#Produces(MediaType.TEXT_HTML)
public String getText() {
return "<body> Error. Invalid data. </body>";
}
#POST
#Produces(MediaType.TEXT_HTML)
#Path("/inputvalues")
public String getParamText(#FormParam("travel") String travel,
#FormParam("start") String start,
#FormParam("duration") String end,
#FormParam("party") String people) {
String returnString = processInput(travel, start, end, people);
return "<body> " + returnString + " </body>";
}
Assuming that the REST services were correctly written and deployed, the problem here is the lack of understanding of the way a POST Rest Service is expected to behave as.
From the comment section above it is clear that you are trying to call a POST API directly from a browser.
That can be done fine for a GET type of a service but won't work for a POST type service.
Reason
The REST API uses several HTTP methods to perform various actions on REST resources. Any REST API that uses a GET call can be invoked using a web browser.
A post service however expects a certain set of input parameters (Here in your case, form params "travel", "start", "duration" and "party" are required)
You cannot call POST API's directly by simple typing the path of the Service URL in the browser.
You can use tools like POSTMAN, RESTer and a lot of such software available on the web, with extensive tutorials on how to use these for POST type REST API calls.

Changing PHP developed backend to Java spring boot

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

Spring, Angular JS and exception handling in the service layer

Our development team is building an application that uses jasper-reports 6.2.0, spring-mvc 3.2.14, java-ee-7, tomcat 8 and in the front-end we use angularjs. Our rest requisitions are all made via ajax.
The application is entirely built to receive json objects as response for our requisitions, because our requisitions via angularjs are all made via Ajax. In a specific application feature we have a regular get requisition using window.location = url, because we need to return a streaming which is nothing more than a byte array containing a PDF file content.
That being said, when we have a back-end error while generating this PDF file our application redirects user to a blank screen with a json object printed in it.
I've already had experience in spring-mvc exception handling globally ou per exception case, using exception handling with ExceptionHandler annotation or per ControllerAdvice to generalize the exception handling, but always handling classes in the controller layer annotated with Controller returning a ModelAndView object, but never classes in the service layer annotated with Service.
My question is how to capture a exception and make the application redirects users to a error screen with some parameterized message when we have regular get requisitions.
In my experience, and even if it's not exactly an answer to the question, main issue is not server side but client side :
stop doing window.location = url to download Content-Disposition:attachement files in an RIA application. Particularly when the download can cause errors thrown to the client. really.
Libs like fileDownload ( https://github.com/johnculviner/jquery.fileDownload ) allow to download the file in background, avoiding all the mess when an error append, and the UI freeze waiting for the server response.
So lets say you want to take care of exception on client side on the basis of http status code then you can make a interceptor like :
var app = angular.module('appname',[]);
app.factory('myHandler', function ($injector) {
var interceptor = {
response: function (response) {
.
.
.
return response;
},
responseError: function (response) {
if (response.status == 401) {
location.href = "#/error";
}
else if(response.status == 403){...}
else if().....
return response;
}
};
return interceptor;
});
and inject it in your application as :
app.config(function ( $injector) {
$httpProvider.interceptors.push('myHandler');
...
});
now every request would first go here , check if error status or whatever you want it to and then if no error (in which case you dont change location.href) it continues ,magically to wherever it was going else goes to specified templateURL on the basis of routeProvider.
Helpful links injector, httpProvider

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

sending data from java to built website

i seem to have reached a impass with my code, im trying to make a java server that maintains my website. My problem is getting data from my java to my website.
this is my ajax im suing to to send stuff to my java, i sends, but i dont know how to send data to my success
function doAjax()
{
// var valstring = JSON.stringify(values);
// var user = {json:valstring};
var data=$("#with").val()+":"+$("#date").val()+":"+$("#where").val();
$.ajax({
type: "GET",
data: data,
url: "http://localhost:55556",
cache: false,
success: function(result)
{
alert("sent");
alert(result.toString());
},
failure: function()
{
alert('An Error has occured, please try again.');
}
});
}
});
my java server on the other hand looks like so
while(//connection)
{
clientSocket = AcceptConnection();
inp = new BufferedReader(new InputStreamReader (clientSocket.getInputStream()));
//using inp to get data
//other tedious code
}
but now if i use .getOutputStream() it doesn't do anything, any of u guys have a solution?
I would honestly appreciate suggestions or any knowledge on how to get that success *function* to work or even an alternative. just keep in mind that this website is already built, not outputted via socket
A simple socket server doesn't understand the HTTP protocol. Shouldn't this be obvious? Either install a Java webserver, like Tomcat, or find a HTTP Server library to use to build your own. My suggestion would be to install Tomcat (or another servlet container), and learn how to use JSP and Servlets. Writing your own webserver will be a total waste of time unless you are doing it to put on an embedded device, which I doubt you are. And even then, it would make more sense to find a solution that already exists. Building a webserver is very involved, and you will unquestionably introduce bugs into it.

Categories

Resources