How to use a URI in java - java

Application use: I am creating a connection between a tablet and a desktop. This tablet will send command to my desktop that my java app will then interpret and do accordingly. One of these features I would like to include is controlling Skype. Such as focusing on it. Switching chats. Initiating call. Sending message. ect. But I can't seem get the URI api to work. (This is the only known api that will allow me to initiate calls and chats, so if you know of any other. Please do tell.)
I am not sure If I am doing it right being that this is my first time using a URI ever. This is what I have using
import java.net.URI
public void uriTest(){
try{
URI uri = URI.create("skype:echo123?call");
}catch(Exception ex){
ex.printStackTrace();
}
}
What am I missing? I know it is probably a lot. Is there some sort of way to implement it. Or when you call .create() does it automatically do it for you?
Any help or clarification will be greatly appreciated.

Your code constucted an URI and now you have one, nothing more, nothing less. An URI is - as the name "Universsal Resource Identifier" says - just an identifier.
What you probably want to do is establish a connection to a location identified by that URI. So you need a special identifier, a so-called "Universal Resource Locator" or URL:
URL url = new URL("skype:echo123?call");
Still nothing happening since we only defined a location. Next you have to connect to it:
URLConnection conn = url.openConnection();
Now you got an URLConnection-object (in this case a HttpURLConnection) and you can operate with it: post data, read responses etc. Read up on the API of java.net.HttpURLConnection to learn more.

You should write a web application, and deploy it on a web server program such as Tomcat, on your desktop machine. You can then write an app on your tablet which would connect to the server and send commands to the server.
The web application could parse the commands and do something with Skype application running on the desktop.
You would probably write a JSON api and deploy it on the Tomcat server, and then invoke the JSON api from the tablet app.

Related

Accessing Auto Proxy URL in Android?

My Android app uses curl to make network calls. I want to find out how I can get the URL that's present in the WiFi proxy auto config in an android device, inside of my application to actually be able to route the charles call through the proxy URL retrieved from the PAC file ?
This question is old, but this might be interesting for anyone else coming from search engines:
Do you know which URL the PAC resides on? If not, I would try to connect to the same WiFi with a PC and do a wireshark trace. When you initiate the connection to the WiFi, an option 252 is sent with the DHCP-lease, specifying where to download the PAC-file from. For example, your client might be told to download http://pac.yoursite.com/pac_file.txt - - - or simething like that.
Then, you can open a browser and navigate to that url, which will download the PAC-file for you to read as JavaScript.

REST server and video streaming

I am building a restful web server with jersey in conjunction with an android app. One of the thing that the server needs to do is to save a video uploaded from an android client and be able to see that video in streaming on other android devices using my app.
I wrote this little test function:
#GET
#Path("video")
#Produces(MediaType.APPLICATION_OCTET_STREAM)
public Response video() {
File file = new File("C:/Data/video.mp4");
return Response.ok(file, MediaType.APPLICATION_OCTET_STREAM)
.build();
}
and seems to randomly work. sometimes the client just loads for ages and i need to close the app. when i close i get this exceptions:
An I/O error has occurred while writing a response message entity to the container output stream.
that error makes me think that when the connection is pretty slow like with 3g instead of wiki, the load takes a lot of time and when i close the app the connection closes so the server can't write on it. so here is my doubt:
1) streams should be used with UDP but udp doesn't have handshaking so that type of error makes no sense to me. does it means i am using tcp?
2) im i actually sending a multipart file? because it seems like it just download the entire file and then start the play.
my final thought is: is it worth to do this with rest? there is any external service that can store and stream the file for me, maybe adding some service like compression and stuff like that? and if not how should i do this? can u guyz show me an example?
ty for the patience and sorry for my english :D

Redirect a specific request to another domain

I am making a private server for a game, and I need to redirect all requests from http://crossfire.z8games.com/ to (let's say) http://cfire.v1k.me/ but only while the redirection program is running. I need some suggestions and what language this is best done (in java/c++, etc.)
I don't want to hex edit program, because I want the user to easily switch between my server and the original server.
So, again, I want some suggestions and code examples on how to simply redirect xxx.xx to yyy.yy with a simple application without modifying the hosts file.
You can use Java's HttpURLConnection to check for an error when connecting to the first url. If an error happens, then you try the second one.
Here's an example that shows how to connect to one url. In the catch blocks, that's where you should try to connect to the second url.

Android App and PHP Web Service Security

I'm building an android application which uses a PHP web service (I am building this also).
My question is, how do I prevent unauthorised users using my webservice? For example, could someone get the address of my web service and use it outside of my app (e.g. sending post variables to my service)?
Another related question is how do I prevent spam requests on my webservice? Would it be a case of logging the IP address and limiting the amount of calls?
You can use an HTTPS connection between the Android device and your webservice API endpoint.
Limit you webservice so that it accept only HTTPS connections. You can easily do this using Apache (perhaps using the SSLRequireSSL directive) or directly in your PHP connection handler.
While using an HTTPS transport stream, you can pass specific arguments when making an API call to your webservice to ensure the request has been sent from your application. Nobody will be able to know what specific data are transmitted and will not be able to reproduce an acceptable connection to your remote service.
Regarding your second question, you can indeed limit the number of requests for a given amount of time. Either in PHP or by using specific tools such as fail2ban.
PHP can receive data via POST or GET out of your site and even the internet browser. One of the methods used to do this is by curl.
To what are you referring to this question is known as Cross-site request forgery.
If you are able, you should implement the use of HTTPS in your app and this could solve many security problems.
In case you can not use HTTPS (whether it is expensive or any other problem):
You must verify the information received by POST or GET in your PHP, this language has much ability to solve these "problems"; Take a look at this part of the PHP official documentation.
Suppose you're building a login system:
Also you can add in the login page place a hidden element with secret unique code that can happend only once, save this secret code in session, so, the loging script look in session for this code, compare with what was posted to the script, should same to proceed.
And, if you want to get the IP address of your visitors:
function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Finally, read this.
EDIT
If you can't pay an HTTPS certificate, (as Halim Qarroum says) you can use:
Self signed SSL certificates,
which are free.
Of course this has its advantages and disadvantages

Android MediaPlayer URL's with Cookie

I have an android application that plays music from a site, however to authenticate to the stream, you need to send a cookie first I.E:
http://example.com/site/content?id=SOMEID = mp3 formatted stream
If you access the url without a cookie, you'll get a Server 500 error.
If you have a cookie, then you'll get the stream.
For the life of me, I can't figure out how to make the mediaplayer play a URL while sending a cookie.
I can play any url that doesn't require a cookie, however.
As far as I can tell you can't. Almost everything MediaPlayer does is done in native code, including opening any connections, so there is no way to access the stream it is using AFAICT.
One possible workaround is to create a web server in your Android app, have it authenticate and download your MP3 and having your MediaPlayer call setDataSource with your local server's address (something like http://127.0.0.1:8000/mymp3.mp3). You can have the playback occur while your web server class is still downloading so ideally your users would notice a difference.

Categories

Resources