I've been using rpclib to auto-generate a WSDL and implement it in Python.
Then I wanted to call a web-service* that has this WSDL using JavaEE, so I simply used the Web Service from WSDL option in the creation wizard in Eclipse (Indigo 3.7.1 with OEPE), but then the Ant build failed with the exception (in short):
weblogic.wsee.tools.WsBuildException Error running JAX-WS wsdlc
Caused by java.lang.NoSuchMethodException: javax.xml.bind.annotation.XmlElementRef.required()
What should I do? How can I call the web-service using JavaEE?
* The web service is configured with: Apache HTTP Server 2.2.2 + mod_wsgi 3.3 + Python 2.6.5 + rpclib 2.6.1.
Ok, stumbled upon your post the second time, so I'll elaborate my comment given before :).
First I recapitulate your set-up:
You have a working webservice and an URL pointing to the corresponding WSDL
You'll try to invoke the WS methods from a different Java EE project on a different machine
General options for invoking a WS:
Use Dependency Injection to inject the WS reference
Create your own WS stubs
The first option won't work in your set-up because DI will only work in an container-managed-environment (see my comment). That means that the WS class and the executing class have to be in the same container (e.g. the same server).
So what is left is to generate your WS stubs manually. Therefore you can use the wsimport tool mentioned in your own answer. There are several different ways to use this tool. Lets have a look in the CLI use:
navigate in your projekt folder of the WS client used by your IDE : %IDE_WORKSPACE%/your project/src
crate a new folder, e.g. stub
open a command window in this directory
execute the follwing command : wsimport -keep <http://yourwsdl?wsdl>
After a refresh you should see several created files
Back in your IDE:
Now you're able to use your generated stub-files to connect to the WS by getting a port from the generated service-file
public class WsClient {
public static void main(String[] args) {
//Create Service
'GeneratedFile'Service service = new 'GeneratedFile'Service();
//create proxy
'GeneratedFile' proxy = service.get'GeneratedFile'Port();
//invoke
System.out.println(proxy.yourMethod(yourParam));
}
}
Last hints:
For portabilty purpose check the generated files. In their annotations sometimes the WSDL file is linked to a local copy. Just change this back to your WSDL-URL.
AFAIK there is an option in the wsimport tool to set this directly in the import routine.
There is a plugin for Eclipse called soapUI which allows you to use the wsimport tool in a GUI out of Eclipse. Once set up it should accelerate your work.
I've also found a quick start guide in developing WS clients with eclipse.
Hope this helped, have Fun!
EDIT: Just to clarify:
After you used the wsimport tool you should have a directory containing files like shown in the image. To make this example clear you'll need to get a Service from the RequestFileService (this is my WS operation) like RequestFileService service = new RequestFileService(); and after this you'll need a Port on this service like RequestFile proxy = service.getRequestFilePort();.
After this you can invoke your method calls by using the port proxy.yourMethod(yourParam);
Related
in Java there is a rest-assured framework to make the API requests and validate the responses with various ways.
Is there any alternative in Python?
Or I should use the requests library to make the API calls and validate the responses e.g using JsonPath, XmlPath and other libraries.
Thanks in advance.
In order to simulate the same functionality as in Java's rest-assured, you can use:
Option 1
requests module along with pytest
Option 2
Use an available module pyhttptest
Here you just need to define your test-cases and request in a json file and run all your test cases using command line
And Last
My favorite and recommended one is pyresttest
pyresttest is tool for testing RESTful HTTP requests. It’s written in Python (hence the py prefix) but unless you intend to write extensions this does not require any Python programming. It will work just fine in a Ruby, Go, Node, or PHP project.
As a command line tool it works by specifying a root URL (host) address and then the path to a YAML configuration file. The configuration file enumerates a list of URLs to request and tests against the expected status code.
Cheers!!
I am creating a Slack Bot, I have successfully installed it, although I am not 100% sure what does ngrok do to run it when I have node server running locally. I have followed this guide.
I have a python script that:
Connects to a database
Downloads the entire table and creates a pandas dataframe
In the script, I have declared many variables which takes specific information from the dataframe.
For example:
monday_sales = sum((df['sale_event_time']>=week) & (df['sale_event_time']<=today_real) & ((df['sale_event_time'].apply(lambda x:x.isoweekday()))==1))
Which simply returns how many sales I had on Monday from the dataframe.
My goal is to connect slack bot to my python script, basically being able to run /monday_sales in slack which would print the number that monday_sales variable holds.
I haven't used much of node or js, so linking everything together I find a bit difficult.
First I run ngrok like so:
./ngrok http 4390
Then I run node server locally(?)
var http = require('http');
const PORT=4390;
function handleRequest(request, response){
response.end('My bot is ALIIIIIIVEEEEE');
}
var server = http.createServer(handleRequest);
server.listen(PORT, function(){
console.log("Server listening on: http://localhost:%s", PORT);
});
And when I run /ngrok in slack it prints out 'My bot is ALIIIIIIVEEEEE, although only visible to me.
So the question could be split in to few:
Why do I need ngrok and node.js server running locally?
How can I trigger python functions / variables from slack bot.
Is there a better way of having slack bot only ran by python without node, ngrok?
Thank you very much for your suggestions.
I think your best bet is to ditch this tutorial and Node, as it seems you're only using it as a ngrok wrapper. Instead, since the rest of your bot is in Python, just use pyngrok (full disclosure, I am the developer), which is a Python wrapper for ngrok. It gives you programmatic access to the tunnels and everything else.
If this solves your use case, you can check out the docs here.
I understand that I can set the database location by changing the following line in /conf/neo4j-server.properties
org.neo4j.server.database.location=data/graph.db
Is it possible to do this within a python instance? For example, I'm using neo4jrestclient
neo4j_login = {
"username" : "neo4j",
"password" : "supersecret",
"url" : "http://localhost:7474"
}
from neo4jrestclient.client import GraphDatabase
gdb = GraphDatabase(**neo4j_login)
Can I somehow set the location of the database I'd like to open to a local directory?
If you're using the REST client, then you're not talking to a local directory, so no - in any case you'll be using a local endpoint. Via that REST client, I believe your only option is to point the server to a directory and then point the REST client to the same place you would have anyway.
Now, if this were java, you could use the neo4j-shell or other tools to open up any directory on your disk as a neo4j database; I don't believe that's an option with present python implementations but if I'm wrong about that someone else please jump in and indicate so.
I like to develop a simple HTTP in Python3 which basically should support 3 different behaviors:
Load local files by their relative path to the root folder e.g. myhost/static/index.html
Mirror remote URL and map them to local urls e.g. myhost/google/* => google.com/* (with HTTP/HTTPS, header support and optional local caching)
Support dynamic results on specific routes e.g. myhost/javascript/mymodule.js (compresses mymodule.js via e.g. Uglify and returns the result)
Thinking about using Tornado or CheeryPy but no luck yet regarding what's the easiest way to implement the proxy part without doing it all on my own.
Suggestions are highly appreciated.
I'm using the suds library as a SOAP client in some project.
I would like to know if there was a way to generate Python code according to the WSDL file.
For example, consider the following line to be from the WSDL file:
<operation name="GetLastTradePrice">
Then, I want to get in some .py file the auto-generated function
def GetLastTradePrice...
The purpose of that is to be able to know what are my possible functions and properties when I have a client. That means that if I will write:
from suds.client import Client
client = Client(SOME_URL)
Then, after typing the folloewing
client.service.
I will get the option of auto-completion GetLastTradePrice.
Ye olde ZSI library can generate Python code from a WSDL definition but, compared to suds, it's quite painful to use and requires another really old module called PyXML. I'd stick to suds, auto-completion isn't worth all that.
There are many SOAP server implementations for python, some more usable than others, search for packages related to SOAP at PyPI or take a look at the wiki page about web services at python.org. There are essentially two types of SOAP servers for python:
Servers that can generate server stubs from WSDL files (like ZSI)
Servers that can produce WSDL from the service class methods directly (like soaplib, ladon)