I'm trying to use cloudrail SDK in my java desktop app for testing ,
but I have problem with runing the sample code in cloudrailsite;
the following codes are main class:
public class DropboxWithCloudRail {
private static String REDIRECT_URL = "http://localhost:3000/";
InputStream inputStream = null;
public void loadDropbox() throws FileNotFoundException, ParseException {
CloudRail.setAppKey("*************");
Dropbox service = new Dropbox(new LocalReceiver(8082),
"*************",
"*************",
REDIRECT_URL,
"Dropbox"
);
service.createFolder(
"/myFolder1"
);
}
}
I set the Redirect URIs in dropbox console http://localhost:3000/
but when I run the project , I get this page:
This site can’t be reached
localhost refused to connect.
Did you mean http://localhost3000.org/?
Search Google for localhost 3000
ERR_CONNECTION_REFUSED
The issue seems to be that you configure your LocalRedirect receiver with the port 8082 which makes it wait for incoming redirects on http://localhost:8082. So this is the URL you have to use as a redirect uri for Dropbox and not http://localhost:3000.
Related
I want to connect to my localhost server for testing my app. For this reason, I am using the retrofit library. This is my interface class, which defines the url to connect to:
import retrofit2.Call;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;
public interface PostInterface {
String JSONURL = "http://80.0.0.13/";
#FormUrlEncoded
#POST("login_screen/backend.php")
Call<String> getUserLogin(
#Field("input") String input,
#Field("username") String uname,
#Field("password") String password
);
}
I am calling this interface in my java code:
Call<String> call = null;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(PostInterface.JSONURL)
.addConverterFactory(ScalarsConverterFactory.create())
.build();
PostInterface api = retrofit.create(PostInterface.class);
call = api.getUserLogin("sign in", "abc", "abc#xyz");
if (call != null) {
call.enqueue(new Callback<String>() {
#Override
public void onResponse(Call<String> call, Response<String> response) {
if (response.body() != null) {
Log.d("success",response.body());
}
}
#Override
public void onFailure(Call<String> call, Throwable t) {
Snackbar snackbar = Snackbar.make(findViewById(android.R.id.content), t.toString(), Snackbar.LENGTH_SHORT);
snackbar.show();
}
});
}
Strangely, the onFailure() method keeps triggering everytime with the following throwable:
javaSocketTimeoutException: Failed to connect to /80.0.0.13 (port 80)....
But when I try the url in my android browser or pc browser, it works fine.
Things I have checked:
The project is stored inside C:\xampp\htdocs, having the exact same hierarchy as in my live server location.
Both Apache and SQL ports are open in my xampp control panel.
My localhost port number is default 80
When I run the app in my emulator using this ip http://10.0.2.2:80/, then it works fine
Why is the app failing to connect to my local server?
EDIT: I can access my site from my phone browser using my pc ip address, but when I want to access it from the app, then the onFailure() triggers
After much struggling, I finally found the solution from a post in github:
Turn on USB Tethering & USB Debugging Mode in your mobile.
Connect your mobile to your laptop/desktop through USB.
Now just change the ip address (run "ipconfig" in cmd)
This is because localhost is not a valid URL for android.
The localhost is a loopback address, which means that the network request will be handled by current device by some application (PHP server).
So, when you enter localhost on your machine (PC/laptop), it will check for server application listening at specified port (in your case 80) and will forward that request to the server application. In your case it is XAMPP which is listening at port 80.
But, when you goto an Android application, there is no server application running on android device or emulator since they are different device. Hence you get 404 error for localhost on Android.
To fix this, simply get the IP address of your PC (using ipconfig command) and use that instead of localhost.
E.g.: In cas the IP address is 192.168.0.129, then your URL would be http://192.168.0.129:80/
I have developed a web site locally on my mac using tomcat 8.0.027 and java jdk 7. The site relies on websockets and all works well locally. When I deploy the site to a virtual private java server I get an error 404. The url for the websocket is ws://www.modelstudio3d.com/handler, my site is www.modelstudio3d.com. I've tried appending :8080 to the host name, that changes the error to connection refused. Changing the url to ../handlerx also generates a connection refused. I've checked that I'm not packaging additional websocket jars in my war file (I'm not as far as I can tell). My server is running tomcat 8.0.22 and JDK 7. My ISP is unable to provide any guidance.
My client code is
this.getWebSocketURI = function () {
var loc = window.location, wsUri;
if (loc.protocol === "https:") {
wsUri = "wss:";
} else {
wsUri = "ws:";
console.log("Websocket is not secure.");
}
wsUri += "//" + loc.host;
wsUri += loc.pathname + "handler";
console.log("wsUri" + wsUri);
return wsUri;
};
this.init = function () {
var self = this;
self.websocket = new WebSocket(self.getWebSocketURI());
...
The interesting part of the server code is
#ServerEndpoint(value = "/handler",
configurator = GetHttpSessionConfigurator.class)
public class WebSocket {
I've read something here about an Apache location filter that might be interfering by redirecting ws: to http: but have no idea where that resides or how to change it.
My hosting service finally agreed to investigate the problem. They say mod_proxy_wstunnel is not enabled and cannot be enabled. Don't use Mocha Host if you need to use websockets.
I am trying to consume below public web service using Eclipse.
http://www.webservicex.com/globalweather.asmx?wsdl
When I execute in the java client it gives the error;
java.net.ConnectException: Connection timed out: connect
Below is the simple client program;
public class ClientTest1
{
public static void main(String[] args)
{
GlobalWeatherSoapProxy obj1 = new GlobalWeatherSoapProxy();
try
{
System.out.println(obj1.getCitiesByCountry("Japan"));
}
catch(Exception e1)
{
System.out.println(+e1.getMessage());
}
}
}
However strangely this works fine when consumed through SOAP UI. Hence I assume this is something to do with Eclipse configuration.
Thank you in advance for any help.
Eclipse has nothing to do with it. Your code is executed by the JVM, even if your development environment is Eclipse. A connection time out means that your client is not able to connect with the endpoint.
You have auto-generated the client proxy in some way getting GlobalWeatherSoapProxy. This class will obtain the reference to endpoint by loading WSDL. Alternatively url can be provided by code. Review the content of that class to see how endpoint URL is loaded
You should see something like (check this full example)
URL url = new URL("http://localhost:9999/ws/hello?wsdl");
QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");
Service service = Service.create(url, qname);
HelloWorld hello = service.getPort(HelloWorld.class);
I have a desktop application built with jdk 6 which publishes web services to be consumed by a web application. So far I've had no problem while both applications are running in the same physical computer, i can access the wsdl without any problem and the web application works with the desktop application just fine. The thing is I cannot access to the services from a remote computer in the same network. The two PCs are connected and can interact. If I run both applications in PC1, from PC2 I can use the webapp through
http://PC1:8080
I am currently publishing like this:
public Publicador(){
servicios= new Servicios();
Endpoint endpoint = Endpoint.publish("http://PC1:8686/servicios", servicios);
}
where PC1 is the name of the pc. From PC1, i can see the generated wsdl from the following address, and it's the one I used for the wsimport command:
http://PC1:8686/servicios?wsdl
But I cannnot from PC2.
Any ideas why it is not visible from outside PC1?
Incredible as it may seem, I found the simplest of answers... Instead of publishing as
Endpoint endpoint = Endpoint.publish("http://PC1:8686/servicios", servicios);
I published as
Endpoint endpoint = Endpoint.publish("http://0.0.0.0:8686/servicios", servicios);
and that solved it...
Another solution was to get the address to publish from a file, that worked too. I don't know why it didn't hardcoded... I ended up doing it like this:
Properties prop = new Properties();
InputStream is = null;
String currenDir = System.getProperty("user.dir");
String nombreArchivo = currenDir + File.separator + "ubicacion.PROPERTIES";
try {
is=new FileInputStream(nombreArchivo);
prop.load(is);
} catch(IOException ioe) {}
String pc = prop.getProperty("ServiciosWeb");
Endpoint endpoint = Endpoint.publish( pc, servicios);
}
I am trying to get started with WebSockets, and trying to write a simple application to send messages back and forth via a websoket.
However, it looks like the socket that I am trying to create never gets connected. Why can that be?
Below is the code of my WebSockets class. When .onConnect() is called, it logs:
I am socket, I was connected. Am i connected? - false
Update: in JavaScript, where I create the socket in question, the readyState is 1, which means "socket open, communication is possble".
import a.b.Misc; //writes logs.
import com.sun.grizzly.websockets.BaseServerWebSocket;
import com.sun.grizzly.websockets.DataFrame;
import com.sun.grizzly.websockets.WebSocketListener;
public class ChatWebSocket_v2 extends BaseServerWebSocket {
private String user;
public ChatWebSocket_v2(WebSocketListener... listeners) {
super(listeners);
}
public String getUser() {
if (user == null) {
Misc.print("User is null in ChatWebSocket");
throw new NullPointerException("+=The user is null in chat web socket");
}
return user;
}
public void setUser(String user) {
Misc.print("Just set user: " + user);
this.user = user;
}
#Override
public void onMessage(String message) {
Misc.print(message +"\n");
}
#Override
public void onMessage(byte[] message) {
Misc.print(new String(message) +" << Bytes\n");
}
#Override
public void onConnect() {
Misc.print("I am socket, i was connected. Am i connected? - " + this.isConnected());
}
#Override
public void onClose(DataFrame df) {
Misc.print("I am socket, i was closed");
}
}
If you're just trying to make a connection somewhere, you might want to try this instead. There is a live working demo and you can download the javascript code and play with it yourself. Note that the javascript code only works if you have it installed on a server (due to browser security because it's 'fancy'.) There is also a step by step browser-based client tutorial in the works that I will post as soon as it's ready. Most proxy servers haven't been upgraded to handle websockets so they will screw up connection request and most people won't be able to connect to websocket servers from work. Firefox 7 (release) or Google Chrome 14 or later support the latest version of the websocket protocol that the demo server runs.
If you want to try to get the grizzly demo working, you might have some debugging to do and maybe I'll help with that. Note that in comments below the article, other people said they couldn't get it working either and I haven't found any follow up. At this point it seems no better than the echo app above even if we do get it running and is possibly overly complicated and underly documented if you're just trying to get started. But if you want to try to get it running, you should 'git' the latest version of the code here, which was at least committed recently and may be fixed.
Then make sure that app.url in the application javascript file is set to your installation directory. His is hard-coded as:
url: 'ws://localhost:8080/grizzly-websockets-chat/chat',
If you're using Firefox 7, the javascript needs to be modified to use the Moz prefix, for example:
if (typeof MozWebSocket != "undefined") { // window.MozWebSocket or "MozWebSocket" in window
ok
} else if (window.WebSocket) { // he uses if ("WebSocket" in window)
ok
} else {
do your print "browser doesn't support websockets"
}
.... then if the browser supports websockets
websocket = new WebSocket(app.url); or
websocket = new MozWebSocket(app.url);
// depending on which it is.
The HLL websocket server demo code has this all sorted out.
(another) UPDATE: As I work through grizzly myself, I found on the Quick Start in the glassfish admin console, there's a hello sample that's pretty easy to set up and run. You'll find instructions there. The sample directory also contains a war file named: websocket-mozilla; so I guess its supposed to use websockets. Someone who's familiar with jsp should review the source code. All I can see is that it's using an http session. No mention of a websocket at all. It's a lot like the hello sample.