webservice flow, proxy and soap address - web-services

I am very new to SOAP webservice. Want to know few things..
1. There is an URL (say, A) by which we can access the WSDL, then what the "soap:address" is used for. I have found a new IP address (say B) as "soap:address location" mentioned in WSDL but this URL is totally different from A. My question is why B address is needed - is this some internal IP address of a machine that resides behind A and completely unaccessible from client. What is the flow?
Since A is not public, so the host have given the access permission to my WAN IP so that I can access A. Now I can access the A url (getting a WSDL content) from simple Java code
URL oracle = new URL(A);
URLConnection yc = oracle.openConnection(proxy);
as I am behind a proxy firewall. But I can access by
URLConnection yc = oracle.openConnection();
From this can I conlude that Java by default tries to connect any URL bypassing machine's default proxy configuraion?
I have generated the client stub from WSDL URL and found that it is annotated with A
#WebServiceClient(name = "BDCDataExchange", targetNamespace = "some url", wsdlLocation = "A"
But when I am running the code it is giving
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: Connection timed out: connect
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(Unknown Source)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(Unknown Source)
As I can access A from my simple java code, does this exception means that I can not access the internal soap:address B?
But the same client code is working if I generate the client using local WSDL path like
wsimport A //not working while executing, above exception comes
wsimport <a local path where I saved the WSDL file> //it works when I run

Related

SavonClient not able to access wsdl through proxy server

Context : I have to call an externalService, which lies outside the environments hosted by us on AWS-EC2. This externalService requires IP Addresses to be whitelisted before accessing it. Since EC2 hosts IPAddresses are not guaranteed to be same and can change while replacing hosts, we decided to route the API calls through a proxy-server.
We are doing the same for some other externalServices calls as well, but those are all REST based, so we have not faced any problems while calling their APIs using rest-client or net/http.
Now, this time it's a SOAP Service and we are using Savon to access it.
I am able to download the url using "curl" on proxy server host but if I access wsdl through proxy-server from SavonClient, it fails. It gives 403 forbidden error.
irb(main):102:0* client = Savon.client do |variable|
irb(main):103:1* variable.proxy 'http://172.31.50.91:3128'
irb(main):104:1> variable.wsdl 'https://<some_url_here>'
irb(main):105:1> end
=> #<Savon::Client:……>>>
irb(main):106:0>
irb(main):107:0* client.operations
Net::HTTPServerException: 403 "Forbidden"
For other services which do not require IP whitelisting SavonClient works, whether or not proxy-server address is provided.
Any help will be appreciated. I have been struck here for long.
Thanks,

Allowing REST URL within network, and blocking outside traffic

Assuming my REST API URL is
http://myshop.com/rest/api/product/1
I would like to have this return data only when calling it within the corporate network, everyone else should not get any result back.
Here are the use cases where they can/cannot be accessible
User accessing it from outside the network but using it via a JSF/CDI application deployed on JBoss Server. (Should be accessible)
User directly accessing the URL from inside the network (via rest client or directly typing the url in browser window) (Should be accessible)
User directly accessing the URL from outside the network (via rest client or directly typing the url in browser window) (Should NOT be accessible)
Thanks for taking a look.
I'd suggest to get an IP address from the request and then check it via permitted IP's or mask of a subnet. How to get an IP address if you're using JAX-RS API you can find here: How to find out incoming RESTful request's IP using JAX-RS on Heroku?
Another option it's of course to block incoming request by firewall or by server's setting.

GSOAP: Automatic Proxy configuration URL

How can I setup a GSOAP generated proxy client class to use an automatic HTTP proxy configuration URL?
I know I can configure the HTTP proxy address like this:
AnyWebServicePortBindingProxy _client;
_client.proxy_host = "192.168.0.x"; // A valid network address.
_client.proxy_port = 8080;
_client.proxy_userid = "user";
_client.proxy_passwd = "password";
But what to do if I want to point to an HTTP proxy script like "http://my_proxy/proxy_script.cfg"?
Thanks!
A proxy configuration script is actually a javascript code that returns the proxy server address based on his needs. This was meant to work with web browsers that implement the necessary logic to parse the FindProxyForURL response.
I don't think GSOAP is able to do the same thing without your interference.
You must check your proxy response by hand (in the beginning of the SOAP client, for example) resolve and update your gSOAP proxy configuration accordingly.

How to dynamic create service proxy with JAX-WS

I have common web service interface on each endpoint applications (server and client).
How can I create port on client side without connecting to server for "the same" wsdl?
I search something what present this pseudocode:
MagicProxyFactory proxy = MagicProxyFactory.newInstance(MyServiceInterface.class);
/* then bind service address like that
((BindingProvider)proxy).getRequestContext()
.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http address");
*/
MyServiceInterface port = (MyServiceInterface) proxy.getPort();
Steps include:
Create the Service instance using the Service.create method
for which you need to know wsdl location, service name, and name space URL of the service.
e.g.
URL wsdlLocation = new URL("http://example.org/my.wsdl");
QName serviceName = new QName("http://example.org/sample", "MyService");
Service s = Service.create(wsdlLocation, serviceName);
Get the service proxy (service port for connecting) using Service.getPort() method.
For this you need to know endpoint implemenattion class name.
e.g. MyService port = s.getPort(MyService.class);
you can now call methods through proxy.
Using Metro? You can't. You need the WSDL to create the proxy. Either bundle the WSDL with your client (preferred) or use a URL from where the WSDL can be downloaded during proxy creation.

Consuming a web service through an internet proxy server, using a WCF client in C#; providing proxy server authentication

I have a client program that consumes a web service. It works quite well in a number of installations. Now I have a situation where a new customer connects to the internet via a proxy server, and my program's attempt to access the web service gets the "HTTP status 407: Proxy authentication required" error.
I thought that all the configuring of internet access, including proxy server address, port number and authentication would be done in the Control Panel Internet Options, and that I wouldn't have to worry about that in the code, or even in the app.config, of the Web Service client.
Have I got it all wrong?
What I have done in the mean time is give the user the chance to configure the proxy user name and password, and then in my code I do the following:
webServiceClient.ClientCredentials.UserName.UserName = configuredUsername;
webServiceClient.ClientCredentials.UserName.Password = configuredPassword;
But I don't know that this is the right thing. Because it seems to me that the above ClientCredentials would refer to the web service binding/security, not to the internet proxy server.
I suppose I can try it at the customer, but I'd rather be sure of what I'm doing first.
I found out how to do this thing, with the help of a contributor to another forum which in the flurry of trying all sorts of things I've forgotten. So thank you to that now forgotten person.
Here's the code that worked in the end (suitably disguised, but gives the right idea):
BasicHttpBinding binding = new BasicHttpBinding("APISoap"); /* APISoap is the name of the binding element in the app.config */
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.Basic;
binding.UseDefaultWebProxy = false;
binding.ProxyAddress = new Uri(string.Format("http://{0}:{1}", proxyIpAddress, proxyPort));
EndpointAddress endpoint = new EndpointAddress("http://www.examplewebservice/api.asmx");
WebServiceClient client = new WebServiceClient(binding, endpoint);
client.ClientCredentials.UserName.UserName = proxyUserName;
client.ClientCredentials.UserName.Password = proxyPassword;