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

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.

Related

Not able to debug from one web app to another web app

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

CXF client NTLM authentication on weblogic

I am developing a sharepoint web service client with Apache CXF and I am having a lot of problems with the NTLM authentication when the client runs on the weblogic server.
If I run a simple test on Eclipse, the code works perfectly, but If I run the same code on a web application deployed on weblogic 10.3.6, the NTLM authentication fails and sends the following error:
org.apache.cxf.transport.http.HTTPException: HTTP response '401: Unauthorized' when communicating with http://win-server-2008/sitios /sitio_registro/_vti_bin/Lists.asmx
I don't know what could be the difference between running the same code on a test and on a web application deployed on weblogic. Any idea?
The authentication code snipet is:
Client client = ClientProxy.getClient(listsSoap);
HTTPConduit http = (HTTPConduit) client.getConduit();
if (http instanceof AsyncHTTPConduit) {
AsyncHTTPConduit conduit = (AsyncHTTPConduit) http;
DefaultHttpAsyncClient defaultHttpAsyncClient;
try {
defaultHttpAsyncClient = conduit.getHttpAsyncClient();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
Credentials credentials = new NTCredentials( conexionSharepointConfigVO.getUser(), conexionSharepointConfigVO.getPwd(), "", "" );
defaultHttpAsyncClient.getCredentialsProvider().setCredentials( AuthScope.ANY,credentials);
((BindingProvider) listsSoap).getRequestContext().put(Credentials.class.getName(), credentials);
}
UPDATE: I tested the same code in Tomcat 6.0.43 and it works ok.
You can either create a Windows service setting the service to run under the desired account or use the "Run as different user" option when opening the command prompt so WebLogic will start from the command line as the desired user.

Java HTTPGET request to (Web SSO) server using the current user's credentials

Description - There is an intranet web application hosted on a WebSSO server. When I manually type in the URL in a browser, the server recognizes me as a valid user and lets me into the website. The authentication is automatically done by using my Windows credentials. I do not have to fill out a login form or anything like that.
Problem - I am trying to make a HTTP GET request to the same URL. The server does not recognize me as a valid user and I get a 401 error.I am trying to do what is described here
My research so far - Looks like my Java session is not the same as my browser session. I looked at my browser's request headers. These headers automatically have a CTSession in the cookie when I manually navigate to the URL(CTSession is unique for every login and is generated dynamically). How do I make the server recognize my Java session as a valid one. What kind of headers do I need in my HTTP GET request? I have already tried the following and it did not work. I get the 401 error
1- con.setRequestProperty("Authorization", new String(Base64.encodeBase64(("username" + ":" + "password").getBytes());
2- Opening a connection to a URL of the below format.
url = "https://fullPath/j_security_check?j_username=username&j_password=pwd

Image getting 403 forbidden when deployed to server

Background:
I am using Spring web MVC along with JSP and HTML/JavaScript to write a website. I have added a search function, which sends a query to imdbapi.org and receives a JSON object containing movie/tv show information (via AJAX). The JSON object contains a "poster" field for each result, which is a URL to an image (on imdb server). The results are then displayed showing the poster if available, using jQuery..
someDiv.append($("<img src='"+results[i].poster+"'></img'").addClass("resultImg"));
Problem:
This works absolutely fine when running on STS built-in server and accessing locally eg.
http://localhost:8080/myWebPage.whatever
I have a ubuntu server box with Tomcat 7 installed, when deploying to the server I get a 403 error for each image. Example from chrome console:
GET http://ia.media-imdb.com/images/M/MV5BMTY2NDY4NDA0OV5BMl5BanBnXkFtZTcwNTI4MzUyMQ##._V1._SY317_CR5,0,214,317_.jpg 403 (Forbidden)
More Info:
Have tested in chrome and firefox with same results.
If I cannot fix then one solution would be to download to a temp folder on the server I think...
Is this a configuration problem on my box with the tomcat server?
Is this a configuration problem on my box with the tomcat server?
No, Not at all, Your server configuration has nothing to do with the external resource accessibility,If you are getting #._V1._SY317_CR5,0,214,317_.jpg 403 (Forbidden) - this clearly mean's that the server is refusing your request.
And it seem's many people's have these kind of problem with IMDB - see this
I have "made it work", it is not a direct solution to the question but a workaround. Using a local proxy on my server I download the image into memory in java and then return to the web page...
Java (server side)
#RequestMapping(value="/pages/proxyImg")
public ResponseEntity<byte[]> proxyImage(String url) {
log.info("Image Proxy server: " + url);
try {
final HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.IMAGE_JPEG);
return new ResponseEntity<byte[]>(IOUtils.toByteArray(new URL(url).openConnection().getInputStream()), headers, HttpStatus.CREATED);
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
Javascript
someDiv.append($("<img src='"+"proxyImg.htm?url="+results[i].poster+"'></img'"));

Proxy Issue while Accessing two Webservice HTTPS and other HTTP

I have a web app which consumes two webservice
• The 1st Webservice connects to external websserver over HHTPS
(https://abc.com/int/obj)
• The 2nd Webservice connects to internal websserver over HHTP
`(http://10.14.250.69:7250/uiu/ohg)
If i use
System.setProperty("https.proxyHost", "xxx.xxx.xx.xxx"); //proxy server
System.setProperty("https.proxyPort", "3128"); //proxy port
Then my application is able to connect successfully with the external website and fetch data, but when it invokes the 2nd Webservice the request are routed to the proxy Server which should not happen
All I want when it connects to this internal Webservice it should call it directly and not via proxy. How can I acheive that.Hoe can I bypass when the proxy server when it invkoes the interna Webservice
It is good to know that you are using Axis WS client. So instead of using the System properties that apply to both web services, can you set proxy setting at individual WS client stub level? Here is the sample code
MyServiceStub myService = new MyServiceStub("https://www.foo.com/abc/xyz.asmx");
HttpTransportProperties.ProxyProperties proxyProperties = new HttpTransportProperties.ProxyProperties();
proxyProperties.setDomain("mydomain");
proxyProperties.setProxyName("xx.xxx.xx.xxx");
proxyProperties.setProxyPort(80);
proxyProperties.setUserName("myusername");
proxyProperties.setPassWord("mypassword");
myService._getServiceClient().getOptions().setProperty(HTTPConstants.PROXY, proxyProperties);
Configure http.nonProxyHosts - a list of hosts or domains to connect to directly, separated by the "pipe" character | by adding 10.14.250.69 to the list.

Categories

Resources