WHAT I DID:
I have tried to call the web service by "POST" method from my android app using the following code.
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://myserver.com:5060/convert/service");
try {
File file = new File(inputPath);
httppost.setHeader("Content-Type", "application/msword");
httppost.setHeader("Accept", "application/pdf");
httppost.setEntity(new ByteArrayEntity(readFile(file)));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (Exception e) {
e.printStackTrace();
}
When I do this api call, I am getting the following exception.
"org.apache.http.NoHttpResponseException: The target server failed to
respond"
But when I do the same web service call from standalone java project using the same code, I am getting the correct response.
Not getting any errors like above.
WHAT I WANT:
Based on my java web service call, I know that there is no issue in service and also the source code. So What may be the issue? How can I get rid of this issue?
I have fixed the issue.
The issue is because of port number 5060. I did found this by using TCP/IP monitor tool in eclipse.
By defaule 5060 port is not being called from android(I didn't know the reason). Because the request not hits the server.
So I have changed the port number to 8090 in my server and restarted the server.
Then I called the service from android. Now It's working great.
Related
I have a running code that i am already using to connect to a server using SSL. The API i am using is commons-httpclient-3.1.jar and i cant not upgrade the jar.
The servers have upgraded to only use TSL 1.2.
Now my existing code is not working.
My current code is
HttpClient httpClient = new HttpClient();
PostMethod post = new PostMethod("https://XYZserver");
post.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
File f = new File("C://sampleXml.xml");
RequestEntity entity = new FileRequestEntity(f, "Application/xml");
post.setRequestEntity(entity);
int statusCode = httpClient.executeMethod(post);
If i modify my code as per link How to force Commons HTTPClient 3.1 to use TLS 1.2 only for HTTPS? then my code is working fine.
I have few questions (As i was unable to find their answers?)
Why do we require a separate class CustomHttpsSocketFactory. Is it possible to modify existing code to use TLS
Is there any other way to do?
I am running two web application using IntelliJ. Both are running on http port 8080 and for one I have changed jmx port to 9099. Issuse is when I try to call another app using httpget HttpGet httpGet = new HttpGet(http://localhost:8080/b-app); from the a-app, http request never hitting http://localhost:8080/b-app. Do I need any specific configuration in intelliJ for it?
Thanks for the help
i wrote a gwt project that works already. the only problem i have is, that i can not connect to the server with my self programmed android app. i can start my gwt page at http://127.0.0.1:8888 with the browser, but when i try to connect to a servlet that maps to http://127.0.0.1:8888/ip/ i get a HttpHostConnectException connection refused exception. i can access http://127.0.0.1:8888/ip/ easily with the browser easily but not with my android app. here is the android code where i try to connect to the server
try{
HttpClient httpclient = new DefaultHttpClient();
ArrayList<NameValuePair> postParameters;
httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://127.0.0.1:8888/ip/");
...
execute = httpclient.execute(httpPost);
catch (Exception e) {
Log.e(TAG, e.getMessage(), e); // connection refused
}
the doPost() method of that servlet (mapped to /ip/) never gets called when i try to post to it with my android app.
the same structure worked with my vaadin and jquery projects perfectly. just gwt is creating this problem.
the problem existed only locally (most probably because of the super develop mode). after i replaced the ip in the bindaddress in the intellij idea debug configuration from 127.0.0.1 to the device ip, the problem was solved
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.
My java program is hitting "http://url:port" kind of url to fetch some data. On my local windows machine deployed on tomcat 6, it is working fine. But on production which is a linux machine having tomcat 6 on it, it gives me connection timeout.
Ironically, if I hit the URL without port number, it will successfully bring me the output but not with port. Not finding any clue, please help.
The snippet of code I am using to connect and fetch data is:
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("59.162.167.36:80/api/…");
httpget.setHeader("User-Agent", "UserAgent: Mozilla/5.0");
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
One obvious possibility is that a firewall in front of your production machine is blocking access to that port. Check the firewall.
The answer is straightforward: On production you don't have that port opened, contact the administrator, or the hosting and issue your problem. Of course they will confirm my thesis.
Almost certainly your hosting provider implements a firewall of some description in the data center. This is common practice. Send them a message asking if port X is blocked, and if so can they open it.