Webservice couldnot able to call client - java

I am using jax rpc style webservice client and service applications.It is working fine,But when I deployed the client in Google app engine.The client is unable to call my server application.
I have made my Ip address static.
Here is the client application piece of code which is deployed in app engine.
public class HelloWorldClient{
public String main(String name,String field2) throws Exception {
URL url = new URL("http://XXX.XX.9.2X:9997/ws/hello?wsdl");
Here is the server application code which is in my system and published
public static void main(String[] args) {
Endpoint.publish("http://xxx.0.x.1:9997/ws/hello", new HelloWorldImpl());
I have kept my firewall to off state.What is the reason for this strange behaviour.I even couldnot able to see the error in appengine log.
Is this enough that I made my ip static or should i make my ip portforward.Is both the things are same.

I think the problem is that you are not use the google fetch library. This is the only supported way to send outbound request from Google App Engine
This two links will give you some more infos about that
https://cloud.google.com/appengine/docs/standard/java/outbound-requests
Can i use org.apache.http.client.HttpClient in google app engine?
Regards
Michael

Related

GAE Remote API - Cannot connect

Ok, I'm attempting unsuccessfully to connect to a remote datastore and populate from my local machine using the steps outlined here: https://cloud.google.com/appengine/docs/java/tools/remoteapi#Configuring_Remote_API_on_the_Client
public static void main(String[] args) {
String username = "myemail#gmail.com";
String password = "mygmailpassword";
RemoteApiOptions options = new RemoteApiOptions()
.server("myappname.appspot.com", 443)
.credentials(username, password);
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
try {
DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
...
I'm getting a 404 in installer.install(options):
java.io.IOException: can't get appId from remote api; status code = 404
Am I missing something here? I enabled the remote api in my web.xml and deployed to GAE. I am the owner of the project.
Run your service locally (with remote api enabled) and try running same code using 'localhost' and 8888 (port) and check if your code can access locally running service. Your code seems right. There are 2 possibilities -
1. RemoteApi is not enabled correctly.
2. app-name is not spelled correctly.
Other than this, I also use following code to access remote api-
installer.install(options);
try {
// Update the options with reusable credentials so we can skip
// authentication on subsequent calls.
options.reuseCredentials(username, installer.serializeCredentials());
} finally {
installer.uninstall();
}
However, that shouldn't give you the error you're getting.
I realize this is coming a bit late, but I just found this when googling because I had a similar problem, and I solved it for myself. For me the problem was, that my AppEngine app that was serving the remote API, was a python app, and the python docs instruct configuring the remote api endpoint as /remoteapi.*
However my remote api client is a java application, and apparently the remote api call it makes, goes to an endpoit like this: /remote_api. So adding that to the server route configuration (in my case app.yaml) solved the problem. Please note also, that if your remote api serving appengine app is not in the default module, the url should be something like my-module-name-dot-my-project.appspot.com
Also, you should use useApplicationDefaultCredential() instead of credentials(), it is deprecated.

Can't connect to server

I'm using this. I changed my base URL and database name, but when I try to sign up, I get the following error.
Any ideas? And if you can help and guide me towards what the base URL for couchDB would be great.
My current URL public static final String BASE_URL ="http://10.0.2.2:5984/_utils/database.html?colourity";
That exception basically means that you're trying to speak a protocol to the server that it doesn't handle. For example, if you're trying to connect to a SOCKS4 proxy but the server is a HTML server, it will return you that response.
Basically, I'd try to debug a bit further. See via Log.d() what are you sending to the server, what is it issuing, what it might be answering, and see why the information you're sending to them is not correct.

How to deploy to specific URL

I have 2 grizzly applications I'd like to run side by side on different URLs on the same server. When I change my url from localhost to api.url.local for local debugging it throws a java.nio.channels.UnresolvedAddressException. Is there something I need to do in order for java to recognize another URL (ie - modify hosts file)? Or am I going in the wrong direction?
I'm currently on Windows but will be deploying to Linux. (If it were up to me, I'd run Linux)
public class Main {
public static final URI BASE_URI = getBaseURI();
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost/").port(9998).build();
}
protected static HttpServer startServer() throws IOException {
ResourceConfig rc = new PackagesResourceConfig("com.my.package.api.resources");
rc.getFeatures()
.put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
}
public static void main(String[] args) throws IOException {
AnnotationConfigApplicationContext annotationCtx = new AnnotationConfigApplicationContext(Config.class);
HttpServer httpServer = startServer();
System.out.println(String.format("Jersey app started with WADL available at " + "%sapplication.wadl\nHit enter to stop it...", BASE_URI, BASE_URI));
System.in.read();
httpServer.stop();
}
}
Running two different applications under different urls on the same machine with one ip address is quite easy. But can require some setup depending on what you want to do.
My assumption is that you're doing this on your development machine. The biggest issue here is that the two servers require different port numbers.
Server #1
http://localhost:8080/
Server #2
http://localhost:8081/
If you want named instances instead. You will have to update your hosts file to point the named instance you want to your local machine. BUT, you'll still have to do separate ports per application.
Server #1
http://api.url.local:8080/
Server #2
http://api.url.local2:8081/
You will also have to update your tomcat (I'm assuming you're using tocmat) config. In the element, I believe you will have to update the 'name' attribute to be the name of your application's URL.
Friendly warning, if you are using the same IP Address, but different host names, SSL certificates will not work very well. Typically in that sort of setup you will need either a wildcard or unified communications certificate.
When you deploy to production, I would recommend using Apache HTTP Server as a proxy to your two applications and have two separate IP Address' unless you can use a SSL wildcard or a unified communications certificate.
This part of the answer is for if you wanted to run one application under two different URLs.
Proxy your application with a Apache Http Server instance and use mod_proxy to forward your two different server names or ip address' to the same Java instance.
My recommendation though, just run two instances of your application. Don't worry too much about resources, hardware is really cheep and worth a lot less then worrying about how to run one instance for two different sites.

How to get a response from localhost server in GWT client side?

I have a WCF based web service and hosted on local machine written in c#. I want to get a response from this hosted service in my GWT client side.
Please check the following code:
url = "localhost:8089/request"
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
Request response = builder.sendRequest(null, new RequestCallback() {
#override
public void onResponseReceived(Request request, Response response) {
Window.alert(response + " ");
}
});
Everytime when i am trying to run the code it shows an "http://localhost:8089 is not allowed by Access-Control-Allow-Origin."
PS: i searched for this error but i don't want to disable the web security of all browsers.
Is there any alternative solution to do get response of localhost server running on different porn on same machine. That is why i want to call a url in client side.
Please suggest a solution.
Edit
Let me explain you full scenario in points:
GWT application is hosted on some server (www.abc.com)
WCF is a web service installed at each client.
A client open his/her browser and put the url (www.abc.com/page)
This page want to access the web services hosted on a client machine.
Can't you configure your WCF service to send an Access-Control-Allow-Origin: www.abc.com response header?
Otherwise, I guess you could use a proxy servlet in www.abc.com that proxies the call to the getRemoteAddr, assuming there's no proxy in-between.

Java and Pubsubhubbub

I just wanted to try out the java client for pubsubhubbub from google code (https://code.google.com/p/pubsubhubbub-java/downloads/list). So I downloaded the code, signed up at SuperFeedr and tried to connect to their hub. In fact I modified the test class the is provided with the subscriber client.
sb.subscribe("http://superfeedr.com/hubbub",
"https://some.blog", hostname, null, null);
hostname is the name of the server I created by using the class Web . Server is reachable from the web.
But I all get is this exception in the GetThread class:
org.apache.http.auth.MalformedChallengeException: Authentication challenge is empty
Does anybody have a hint?
Cheers,
Andi
PS: Up to now it's quite tedious to get PuSH working, e.g. at SuperFeedr they tell you what to do (http://superfeedr.com/documentation#pubsubhubbub_implementation) but not how? I tried to implement what's necessary for push my self (HttpClient, PostMethod with parameters,etc.) but nothing works....

Categories

Resources