How to use web service in J2ME application? - java

Can somebody specify the step for using web services in a J2ME application`
I have downloaded Eclipse (SOA), have included the wsdl file in my code and have prepared web service in visual studio 2008. I want to use a .net web service in my J2ME application.
Thanks

You can consume webservices in j2me, following would be the architecture look like,
Read More
Here is a quick youtube tutorial

If your phone does not support JSR172, or you want to target every phone in the market, you still can consume webservices manually. That is to say, you need to create an XML to invoke the service, and parse another one to see the results. This can be a lot of work. There is library called kXML2 that may help you in both task. But when I needed to invoke a webservice from j2me I found to be easier to follow this workflow:
1 - Use visual studio to create a simple client application for that webservice in .Net. So I can be sure the service works as expected without relaying in my j2me client, which is still in development.
2 - Use a tracer like http://simile.mit.edu/wiki/HTTPTracer to spy the connection and see what is really happening between client and server...it's kind of fun.
3 - Duplicate this behavior in my own j2me application ...but trying to keep it simple. As an example, I needed to create an XML like
<SOAP>
<data>
<id>
numericID
</id>
</data>
</SOAP>
Since I knew it was going to be a numeric Id, I just create the XML as a String using a stringbuffer.
4 - Be careful about the String encoding and the http headers. You can compare your generated traffic in j2me with the one the client. You need to replicate the exact behavior

Related

Integrating 3rd party API with jhipster based webapp

I am trying to build a simple web app using jHipster. Currently I am trying to build a simple stock entity that will enable a user to input the stock name and the entity should generate a listing of that stock with open, high, low and close data. I am unable to figure out how to integrate the web app with a third party API that supplies the data. I could not find any documentation regarding this issue online. Thank you.
I found this tutorial on implementing API's that might help.
What you need to do is create an HTTP client that can access your API.
I'm not too familiar with jHipster but finding the proper library to import seems like a good first step. Good luck.
Source:
https://zapier.com/learn/apis/chapter-8-implementation/
If you aren't sure which language to choose, a great way to narrow down the selection can be to find an API you want to implement and see if the company provides a client library. A library is code that the API owner publishes that already implements the client side of their API. Sometimes the library will be individually available for download or it will be bundled in an SDK (Software Development Kit). Using a library saves you time because instead of reading the API documentation and forming raw HTTP requests, you can simply copy and paste a few lines of code and already have a working client.

Client android application for site

I want to write a client application for a site (e.g. to read smth from site, add some comments, likes etc). I haven't got access to site sources and there isn't any API for work with it. So at my Android application I decided to parse this site (it has static pages) using : JSOUP Library
And using this library I'm going to write unofficial, but API for my purposes to work with this site, and then use it in my Android application.
Can somebody tell me, is this good practice or there are better ways to do? Is this good idea at all to parse site in Android device.
As I wrote in comment - in general building your own application on top of the third party www service is not a good idea. If you want to do it anyway you have 2 options:
Use jSoup (or any other html parser if exists) and parse third party content on the device
Set up some middleware server to parse content and serve it in some more convenient way.
The second option has a little advantages - you can fix application without forcing users to update it and probably you'll save a bit of device's bandwidth. Of course disadvantage is that you have to pay for server.
General problem with applications like that is that every single change with layout, skin, server configuration can cause your application to stop working, as well as parsing html needs much more work that just connect to existing API.
More over - publishing your application can cause some legal issues (copyright) and is against Google Play's policy:
Do not post an app where the primary functionality is to: Drive
affiliate traffic to a website or Provide a webview of a website not
owned or administered by you (unless you have permission from the
website owner/administrator to do so)

Provide an interface between the web browser and a Java application

Which language/tool do I use to provide an interface between the web browser and a Java application?
My task is create a web page and provide a feature which will enable results to be uploaded as XML files to dynamically update the page.
I have been instructed to use languages such as Java, Javascript(JQuery), Ruby, Grails, PHP etc.
So I have so far written some java classes that will process the XML files but I am running this application from the command line. I DO also understand how to display the XML on the web browser using XSLT.
My problem is, that I have only ever written desktop applications... I don't know what tools to use to provide an interface between my java back-end and the web front-end or how to (for lack of another method) invoke the JVM from the browser.
How do I send uploaded XML files to my java classes and get the XML results back? Can anyone shed some light into which tools I should use and the network packages (if needed) I need to import in Java? (note: this only needs to be run locally)
Feel free to make edits to tags/title and question if necessary.
I have been working in java and i feel that servlet-jsp are the best option
to full fill your requirement.

App with ios 4.3 and SOAP

I,ve created a pictures gallery with ios 4.3 and i want download, decode and save my pictures before start my app.
I want use SOAP with Java Server because i think that is more simple but i,ve had some problems with Core Services library, i need this library to communicate both sides.
It´s impossible add this framework.
I need solve this problems or other solutions.
I´ve seen ASIHTTPRequest but it´s so difficult understand from zero.
SOAP is seldom the simple answer.
ASIHTTPRequest is nice for network access, but not a silver bullet for SOAP. It is just as easy/hard to do with the built in classes from Foundation framework.
First of you need to manually build your SOAP request bodies. Typing up template a XML file with placeholders that can be easily replaced is the simplest way to do it.
Then take the constructed XML as the HTML body of a NSMutableURLRequest and send it using NSURLConnection.
The response will be more XML wrapped in a NSData instance. Use NSXMLParser to decode it.
But given that you want to write the server in Java and an easy solution; I would use Hessian over here http://hessian.caucho.com/ to implement the server.
On the iOS side use HessianKit over here https://sourceforge.net/projects/hessiankit/ and do simple RPC calls.
Disclaimer; I am the author of HessianKit.

Accessing a web service from your browser

I'm relatively new to how web services work so I've gone though a tutorial from
http://blog.saminda.org/2008/07/light-weight-osgi-based-axis2-powered.html
which sets up a web service that prints hello.
The code to print out hello is here. In the same project here, there is another web service that adds two numbers together.
To access the "hello" web service, I just go to my browser and go to http://localhost:8080/bridge/services/Version/getVersion .
But how do I do that for the calculator web service? What's the url? Or do I have to do something extra to register that as a service first?
Looks like it would be http://localhost:8080/bridge/services/Calculator/add
It seems to expect to parameters but there's no indication of how to pass them in the url - you could try appending ?x=2&y=3 to it and see if it returns 5
UPDATE: Yup that seems right, see the post at http://blog.saminda.org/2008/08/exposing-osgi-service-as-web-service.html for a calculator example
UPDATE 2: As I've commented on the original question, the links to the code which you are calling are no longer available. However, it seems like there is a general principle to calling this things. The format seems to be
http://server:port/bridge/services/ClassName/MethodName?parameter=value&anotherparam=value
so in the adding numbers example, ClassName is Calculator, MethodName is add and the x and y parameters (that the code adds together) are passed as URL parameters.
I'm not a Java developer myself, so I don't know if you need to compile the web service code first before it is callable, but if you've got the "hello" code working already, you'll know the answer to this.
I think it'll be - http://localhost:8080/bridge/services/Calculator/add?x=10&y=10
If you are starting with Java Web Services, do read the book "SOA Using Java Web Services", for details see http://www.soabook.com
Well if you have just starting out developing with web-services then you should look at servicestack.net it's an open source web service framework that reduces the learning curve in creating and consuming web services, here is a 'live example' showing you all the source code required to create and call simple web services from an Ajax, Android iOS, or Silverlight applications:
https://github.com/ServiceStackApps/LiveDemos

Categories

Resources