How to call a web service inside another webservice - java

I need to consume a secure webservice deployed in WSO2 AS from another web service develop in axis2 and deployed in apache tomcat.
I create a java project to test the secure webservice client and I work OK.
But when I move the client code inside the axis2 service I cannot access to some resources like in this cases:
System.setProperty("javax.net.ssl.trustStore", "keys\\store.jks");
in this case I have the keys folder in the root of the wb services
sc.engageModule("rampart");
and in this case I leave the code idem
Any idea about this?

Well getting a resource path from an archieve file whether it is a jar ,war or aar is a tedious problem. There are two options two choose from:
1- Since client application runs on a servers put jks file somewhere on the server path, its path retrieved dynamically via property. (Either system property, servers context etc.)
2- A customSSLFactory handling loading keystore from resources.
This SO thread mentions such solution, which i used it too to connect to server via SSL from a web service without touching system properties.

Related

Run a file locally in java (reach with 'localhost')

I've been requested at work to run a file (server app) locally (so I will have it in localhost) and then send http get requests as I desire.
(I'm using get requests in the form "wget ..... http://localhost:4567/XXXX"
XXXX contains the name of the item I'm trying to receive.
I'm not familiar with the term 'run a file locally'. Can anyone explain / direct me to a website that explains about it?
Suppose my server file name is 'server'. How do I run the file (locally) in java? (so I'll be able to send HTTP get requests as I've mentioned above)
Are you asking for running html files locally so that they can be accessed through a port? If this is the case you need to have a http server on your desktop/laptop and configure it to enable your html files. If it is complete J2EE/.Net/any other platform applications, we need to install appropriate web/application server and run the same.
You have to create webservices and define its path. Suppose if you create a method give it a #Path('someName'). Define what it should consume and what it should produce using #Consumes(MEDIA_TYPE.xxx) #Produces(MEDIA_TYPE.xxx). The whole project will have a base path like restApi. Run it using apache tomcat i desired port. Access the rest api with the url http://localhost:8080/restApi/someName. Refer java webservices for more details. Its very simple. Starting configuration may take some time. So start with a maven artifact for java webservises to have a head start.
If you only want to send some GET requests to check the responses I would use a simple REST client like Postman. Just enter your URL, choose the GET method and send the request.
To run something locally means that the server is installed locally. You would deploy your file/s (.war or .ear in the case of java) to this local server. After that you can access the deployed services via http://localhost:port/...

How do I know the working directory of my apache web service?

I have a python client (ubuntu) which calls the following web service:
http://xxx.xxx.xxx.xxx:8774/v2/8d118e773c6a44c88f64960c1177ede6/getNodes'
Both client and server are located on the same machine.
How can I find to which working directory this web service (which my client is calling) is pointing to?
(I don't know the source of the web Service. All I know that it is running on the same box and its url. How do I get to the source with these two clues?)
Since it is Ubuntu, you can find all the configured Apache hosts in /etc/apache/sites-enabled. One of the files in there will be your web service, and will specify its directory.

Programmatically changing haproxy configuration file

Is there any java program or api to change the content of the configuration file of the haproxy? for example to append/remove few configuration dynamically.
Run a thalassa server on the same machine as HAProxy and call its http api from your Java program. It defines restful POST and DELETE interfaces for registrations, which are dynamically configured backends.
append documentation
remove documentation
Inspired by the Answer of allonhadaya I tried out thalassa.
Pearson Eduction who are the main contributes build a complete stack around:
https://github.com/PearsonEducation
So in your example you would probably use three of their components
Thalassa (Service Directory Service)
Thalassa Http Client
Thalassa Aqueduct
The Service Directory is the central service manager. With the application itself (if it is a node application there are predefined compontens) or with the Thalassa HTTP Client you register your service (application) at the service directory. In your case with your existing java application, using the HTTP standalone client might be a good way to start.
Thalassa Aqueduct ist the bridge to the HA-Proxy. It connects the Service Directory with the HA-Proxy configuration. At the moment it has (only) some REST Methods to also configure the HA-Proxy Frontends and Backends. But a quite OK Webinterface to see how many connections are handled and balanced right now.

Downloading files from remote server Java

I am looking for suggestions on implementing this requirement:
The requirement is for users on a public website to be able to download files of any kind.
The webserver for the website resides on a DMZ, the server that stores the files is internal to our corporate network. The webserver would have to communicate with the file storage server to get the files. What would be the best way to implement this?
Map that file server as a network drive in the disk file system of the web server and then add another web application context to the servletcontainer configuration which references the network mapped path.
It's unclear what servletcontainer and platform you're running/targeting, so I can't give a more detailed answer. But if it were Tomcat, then it's a matter of adding the following <Context> element to Tomcat's /conf/server.xml, assuming that you've mapped the file server on /path/to/mount/share:
<Context path="/share" docBase="/path/to/mount/share" />
This way it's available by http://localhost:8080/share/
It looks like that you want a proxy-like component to serve backend files... Personally I wouldn't use an application server for such a task, instead use simply a webserver. Some options:
Network share: Create a network share just as BalusC proposed and configure your web server to use that share.
Reverse proxy: Deploy another web server on your file server and configure your front end to act as a reverse proxy (ie. to dispatch download requests to the internal web server)
That is to say I would rather use an (Apache, Nginx, etc.) web server based approach instead of a Java/J2EE based one. For me it seems a better fit... Hence I would consult my sysadmin:)

Web Service Client Deployment

I have a web service client (JAX-WS) and the stubs have been created using the wsimport tool.
Now once the client is packaged as an application, the location of the service (and only the location )changes.
Do I have to re run the whole ws-import tool once again to create new stubs for the new location.
Is it possible to move the WSDL location to a Config so that the application do not have to be built again! I am working with net beans 6.5.
I suppose DII is an option, but is there a solution to make the code independent of the WSDL location.
You may package the WSDL locally in your application (which is also reasonable for performance, since you're saving requests to the external file on runtime), see developing client application with locally packaged WSDL

Categories

Resources