Java soap client to wsdl url - java

i want to call soap function with a few parameters. I did it python but how can i do it on java ?
my code on python :
url = 'http://78.188.50.246:8086/iskultur?singleWsdl'
client = Client(url)
d = dict(UserId='a', UserPass='b', Barkod=str(value))
result = client.service.Stok(**d)
return int(result)
how can i do it on java ?
Thanks for all

First you need to generate proxy classes. You can do that using wsimport (it's a Java SE tool):
wsimport -keep http://78.188.50.246:8086/iskultur?singleWsdl
This will generate classes (in packages) and place the results in the current directory. I tested your URL and it generated two package hierarchies (one starting in 'org' and the other in 'com'). The command above will keep the source code, so you can move those directories to your Java project source path (later you should include this code generation step in your build process).
with the generated classes in your classpath, you now create a Service instance from your WSDL (passing the URL and the namespace qualified name of your service). I got that information from the WSDL.
URL wsdlLocation = new URL("http://78.188.50.246:8086/iskultur?singleWsdl");
QName serviceName = new QName("http://tempuri.org/", "EbWCFtoLogo");
Service service = Service.create(wsdlLocation, serviceName);
Then you get a proxy where you can call your SOAP methods with Service.getPort() passing the interface of the port (IEbWCFtoLogo). Now you have a reference where you can call your remote SOAP methods.
IEbWCFtoLogo proxy = service.getPort(IEbWCFtoLogo.class);
The wsimport tool generated a stok() method that receives 3 parameters. I called with some of the values you used and it returned -1.0 in the code below:
double value = proxy.stok("a", "b", "code");
System.out.println("Result: " + value);

Related

Generate Java class (Pojo) for parameters using WSDL url

I have a wsdl url using which I have to create a template file which has the list of the parameters for a particular API and create a pojo file for that request. I tried using soapui-api but I was unable to do so because of unable to fulfill the dependencies (Followed all the stackoverflow help to resolve the jar issues but it did not work):
Code:
WsdlProject project = new WsdlProject();
WsdlInterface[] wsdls = WsdlImporter.importWsdl(project, "http://XXXXX?wsdl");
WsdlInterface wsdl = wsdls[0];
for (com.eviware.soapui.model.iface.Operation operation : wsdl.getOperationList()) {
WsdlOperation wsdlOperation = (WsdlOperation) operation;
System.out.println("OP:"+wsdlOperation.getName());
System.out.println("Request:");
System.out.println(wsdlOperation.createRequest(true));
System.out.println("Response:"); System.out.println(wsdlOperation.createResponse(true));
}
Another approach in which I tried to parse the wsdl url using parser and get the list of names of the possible requests. I was able to get the request list but not the parameters required to create that request.
WSDLParser parser = new WSDLParser();
Definitions wsdl = parser.parse("http://XXXX?wsdl");
String str = wsdl.getLocalBindings().toString();
for(Message msg : wsdl.getMessages()) {
for (Part part : msg.getParts()) {
System.out.println(part.getElement());
}
}
Please help me on how to get the list of parameters from a wsdl url by either of the one approach.
well there are various stranded approach available for this , try and search for WS-import tool which is one of tools to do this .
This is the simple and best example here
WS_Import_tool
one more way of doing this is -
Apache_CFX
If you want to generate them using eclipse - that is also possible .
Check it out -
How do you convert WSDLs to Java classes using Eclipse?
What errors you are facing for SOAP UI
You can reffer this link for trouble shooting
Generate_java_from_Wsdl

How to conevrt soap xml to custom obect

String example =
"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"><soapenv:Header /><soapenv:Body><ns2:farm xmlns:ns2=\"http://adamish.com/example/farm\"><horse height=\"123\" name=\"glue factory\"/></ns2:farm></soapenv:Body></soapenv:Envelope>";
Here is my soap xml in string format how i need to form it in a Farm object .Farm is my custom class,Any library is readly available
After Using This Code m getting the exception
SOAPMessage message = MessageFactory.newInstance().createMessage(null,
new ByteArrayInputStream(example.getBytes()));
Unmarshaller unmarshaller = JAXBContext.newInstance(Farm.class).createUnmarshaller();
SubscribeProductReq farm = (Farm)unmarshaller.unmarshal(message.getSOAPBody().extractContentAsDocument());
unexpected element (uri:"http://yyyyyy.yyyyy*********", local:"farm"). Expected elements are <{}farm>
You don't need to do much:
There are two ways to generate Client side java code for SOAP:
1) You must be getting this xml from some URL. So, Maven plugin gives you control over to generate jar from URL for SOAP.
2) You can diretly place SOAP xml into a file and put that file path in maven pom. Maven will generate client jar using Apache CXF.
Visit https://www.jetbrains.com/help/idea/generate-java-code-from-wsdl-or-wadl-dialog.html
visit https://objectpartners.com/2010/11/25/leveraging-apache-cxf-and-maven-to-generate-client-side-web-service-bindings/

Capture generated output file path and name using CSSDK

We are in the process of converting over to using the XSLT compiler for page generation. I have a Xalan Java extention to exploit the CSSDK and capture some meta data we have stored in the Extended Attributes for output to the page. No problems in getting the EA's rendered to the output file.
The problem is that I don't know how to dynamically capture the file path and name of the output file.
So just as POC, I have the CSVPath hard coded to the output file in my Java extension. Here's a code sample:
CSSimpleFile sourceFile = (CSSimpleFile)client.getFile(new CSVPath("/some-path-to-the-output.jsp"));
Can someone point me in the CSSDK to where I could capture the output file?
I found the answer.
First, get or create your CSClient. You can use the examples provided in the cssdk/samples. I tweaked one so that I captured the CSClient in the method getClientForCurrentUser(). Watch out for SOAP vs Java connections. In development, I was using a SOAP connection and for the make_toolkit build, the Java connection was required for our purposes.
Check the following snippet. The request CSClient is captured in the static variable client.
CSSimpleFile sourceFile = (CSSimpleFile)client.getFile(new CSVPath(XSLTExtensionContext.getContext().getOutputDirectory().toString() + "/" + XSLTExtensionContext.getContext().getOutputFileName()));

Reading request parameters in Google App Engine with Java [duplicate]

This question already has answers here:
GWT: Capturing URL parameters in GET request
(4 answers)
Closed 9 years ago.
I'm modifying the default project that Eclipse creates when you create a new project with Google Web Toolkit and Google App Engine. It is the GreetingService sample project.
How can I read a request parameter in the client's .java file?
For example, the current URL is http://127.0.0.1:8887/MyProj.html?gwt.codesvr=127.0.0.1&foo=bar and I want to use something like request.getParameter("foo") == "bar".
I saw that the documentation mentions the Request class for Python, but I couldn't find the equivalent for Java. It's listed as being in the google.appengine.ext.webapp package, but if I try importing that into my .java file (with a com. prefix), it says that it can't resolve the ext part.
Google App Engine uses the Java Servlet API.
GWT's RemoteServiceServlet provides access to the request through:
HttpServletRequest request = this.getThreadLocalRequest();
from which you can call either request.getQueryString(), and interpret the query string any way you desire, or you can call request.getParameter("foo")
I was able to get it to work using Window.Location via this answer:
import com.google.gwt.user.client.Window;
// ...
Window.Location.getParameter("foo") // == "bar"
Note that:
Location is a very simple wrapper, so not all browser quirks are hidden from the user.
Use java.net.URL to parse the URL and then String.split() to parse the query string.
URL url = new URL("http://127.0.0.1:8887/MyProj.html?gwt.codesvr=127.0.0.1&foo=bar");
String query[] = url.getQuery().split("&");
String foo = null;
for (String arg : query) {
String s[] = arg.split("=");
if (s[0].equals("foo"))
System.out.println(s[1]);
}
See http://ideone.com/Da4fY

Getting runtime class information from the web? Something like javap but at runtime on class loaded in memory

I am working with Websphere and complicated classloading issues. I want to be able to download or print information that would normally get printed by javap (the methods, etc).
I may also need to get the raw binary class data, to perform a binary diff.
How would you do this?
You could write a Servlet or JMX MBean that exposes the class to the your client.
Servlet:
String resourceParameter = ...;
OutputStream out = ...:
InputStream input = Thread.currentThread().getContextClassLoader()
.getResourceAsStream(resourceParameter)
write(input, out);
Client:
GET http://host/DiagnosticServlet?resource=your/ClassName.class
The resource parameter has to be your class file your.ClassName -> your/ClassName.class.
You can then save the file and use javap.
(I think the MBean has to encode your class file into a string (e.g. Base 64) as byte[] is not supported. But I'm not sure about that. The rest would be the same.)
If this will be deployed in production some form of authentication should be configured.

Categories