I am trying to generate the client code from a WSDL.
I need to work on the Jdeveloper 10g IDE.
I generated client code from WSDL using the inbuilt tool Oracle JAX-WS 2.1.5.
For a particular WSDL this tool is generating around 122 java classes that does not include the Locator class. While running the code, I get a class not found exception for WebServiceLocator class.
However, when I am using Apache Axis 1.4 ( Eclipse IDE ), it is generating 63 java classes and it also includes the WebServiceLocator class, but this is not generating all the required methods that are needed for authentication, though ,Oracle JAX-WS 2.1.5. is generating those methods.
I tried merging the java classes generated from Eclipse into Jdeveloper, but then I am getting a lot of errors related to method signatures.
Is there some particular reason why these two different tools are generating different client codes, and none of them complete?
This is probably a bit late, but for those running into the same issues, this might be helpful.
If you really want to use Axis 1.x authentication is done on your client class as follows:
MyLocator bindingService = new MyLocator();
bindingService .setPortEndPointAddress(myEndpoint);
MyPort port= bindingService.getMyPort();
((Stub)port)._setProperty(Stub.USERNAME_PROPERTY, myUsername);
((Stub)port)._setProperty(Stub.PASSWORD_PROPERTY, mPassword);
//Perform your query here
I would personally use JAX-WS. Use wsimport to generate the stubs (SOAPUI has a nice plug-in to simplify this). For authentication on a JAX-WS client its easiest to save the wsdl locally and export it as part of the jar then load it in the client. This removes the need for HTTP authorization required to access the wsdl in the first place.
URL myWsdlUrl = getClass().getClassLoader().getResource("wsdl/myWsdlFile.wsdl");
MyService service = new MyService(myWsdlUrl , new QName("uri", "localpart"));
myPort port= service .getPort();
BindingProvider bp= ((BindingProvider)vPort);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, myEndPoint);
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, myUsername);
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, myPassword);
//Perform query here
Related
I have WSDL and XSD schemas. I generate java classes and service interface from it with CXF.
I create SOAP endpoint with CXF:
#Bean
Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(bus, myEndpoint);
endpoint.publish(path);
return endpoint;
}
When I open service URl I get generated WSDL but I need Original WSDl.
How can I return original WSDL and not generated?
AFAIK, it seems not doable (or not quite easy) as Apache CXF publishes a WS endpoint based on its implementation (and/or relevant generated sources for XML schemas). CXF does not directly used the WSDL and XSDs, and therefore, the endpoint's WSDL might be a tad different from the original WSDL.
I have used cxf-codegen-plugin to generate Java code from WSDL+XSD, then implemented the business logics of each service and publish them using Apache CXF <jax-ws>. The generated code are well annotated so that it seems JAX-WS can use these annotations to produce very close results. The published WSDLs are only slightly different from the original WSDLs but hard to notice if not expert. You can find the project's source here: https://github.com/htr3n/loan-approval-portal.
Perhaps, the closest you might have is using Spring WS with <static-wsdl>.
Last year I made JAX-WS client for a web service in this link
This webservice use a STS service to get SAML token and use it to access main webservice. I use wsdl2java of apache cxf to generate JAX-WS client for this webservice. Everything was just fine.
Recently they have updated their STS service endpoint. This new STS service endpoint. Which has different signature and digest algorithm. It has some extra element in request body.
I tried to modify current code so that it support new STS service. But my code is sending same RequestSecurityToken request.I mean it does not adopt for new requirement. I tried to adopt this but I could not do that.
New STS service required http://www.w3.org/2001/04/xmldsig-more#rsa-sha256 as new signature method and http://www.w3.org/2001/04/xmlenc#sha256 as new digest algorithm. Plus it required following element in request body:
<tr:ActAs xmlns:tr="http://docs.oasis-open.org/ws-sx/ws-trust/200802">
<v13:RelationshipToken xmlns:v13="http://vanguard.business.gov.au/2016/03" ID="1bc9a44e-dccd-49e2-8f29-40d7b1257325">
<v13:Relationship v13:Type="OSPfor">
<v13:Attribute v13:Name="SSID" v13:Value="1234567895"/>
</v13:Relationship>
<v13:FirstParty v13:Scheme="uri://abr.gov.au/ABN" v13:Value="27809366375"/>
<v13:SecondParty v13:Scheme="uri://abr.gov.au/ABN" v13:Value="89567587874"/>
</v13:RelationshipToken>
</tr:ActAs>
Plus there are minor differences here. I have two ways now I think:
If I can change old code to STS client send request with those value. which I tried and not succeeded.
They provide some code which support fetching SAML assertion token and proof token from STS client. If I can put SAML assertion token into my JAX-WS client directly then this problem is also solved.
Any help or suggestion will be appreciated to us
The SHA-256 digest algorithm is normally set by using an AlgorithmSuite policy that requires it (e.g. Basic256Sha256). I see in the policy they are still using "Basic256" however. CXF allows you to configure RSA-SHA256 via some configuration properties (see for example 'ws-security.asymmetric.signature.algorithm' here http://cxf.apache.org/docs/ws-securitypolicy.html). You can set ActAs Object/Element on the STSClient directly.
I was receiving "An error occurred when verifying security for the message". Two changes that I had to make to resolve this while using Metro 2.3.1 -
In the STS wsdl, need to mention the signature algorithm like this ---
sp:AlgorithmSuite signatureAlgorithm="SHA256withRSA"
In the USI wsdl, need to change the AlgorithmSuite to Basic256 from Basic256Sha256Rsa15
From a colleague I have received a WSDL file that describes the web service he is offering, and which I am supposed to call from my code. I would now like to do two things:
1) Implement the client
2) Have a stub server that I can use for testing, until I have access to the real server.
What I tried is the following:
wsimport -clientjar foo.jar foo.wsdl
This gives me a jar file that contains the Datatype that will contain the data to be posted to the web service, and also an ObjectFactory. I guess I will have to use it as follows:
TestDataType testDataType = new TestDataType();
testDataType.setFoo("foo");
testDataType.setBar("bar");
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<TestDatatype> request = objectFactory.createTestRequest(testDatatype);
Now how do I send this request?
Also a class TestDemoService annotated with #WebServiceClient has been generated. How do I run this class?
Any advice is highly appreciated.
You've created the client. To use this client you need to set the endpoint(if not already set) and call the service using the generated api.
This site should be a good reference.
Using wsimport
I'm using CXF to to communicate with a WSDL made in WCF. The WCF side of things was created following a tutorial. The Java code has been generated using a Maven script.
I have gotten things working using HTTPS for encryption. I have gotten authentication working. However, I would like to have the WSDL metadata turned off on the WCF side and still be able to use the Java side to talk to the service.
Currently, I can access the service with metadata publishing on from the Java side using this code:
URL wsdlLocation = new URL("https://server.com:7010/Hservice?wsdl");
HttpsURLConnection connection = (HttpsURLConnection) wsdlLocation.openConnection();
HService service = new HService(wsdlLocation);
HAdminService calc = service.getHAdminService();
... (authentication using WSS4JOutInterceptor code and unrelated code here)
System.out.println(calc.add(new Double(5), new Double(5)));
However, when I turn off metadata publishing on the WCF side I get this error:
Exception in thread "main" javax.xml.ws.WebServiceException:
org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.jaxws.ServiceImpl.<init>(ServiceImpl.java:149)
at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:90)
at javax.xml.ws.Service.<init>(Service.java:56)
at com.blah.hservice.v_1_0.HService.<init>(HService.java:49)
at Main.main(Main.java:85)`
The page the wsdl is on displays this with metadata publishing turned off (this is an excerpt):
This is a Windows© Communication Foundation service.
Metadata publishing for this service is currently disabled.
If you have access to the service, you can enable metadata publishing by completing the following steps to modify your web or application configuration file:
I expected to be able to search "CXF metadata unpublished" and see lots of people doing this...but have not found anything. How do I communicate with this service without the WSDL being published?
You really have two options:
Copy the wsdl locally and point the client at the local wsdl. This is likely the "best" option as it makes sure all the information in the wsdl (like policies and such) is used.
Use "null" for the wsdl location (note: not JAX-WS portable). You will need to call service.addPort(....) after creating the service and before calling getHAdminService to add the port with the appropriate binding and endpoint address. CXF can work most of the time without the WSDL (will internally generate what is needed from the annotations). However, if things like policies are defined in the WSDL, then it cannot.
I got this to work with Client code I generated using CXF 2.6.5
Make sure the QName(first argument) matches the QName the getHAdminService() method references. The bindingId(second argument) should be one of the constants defined in SOAPBinding Interface (javax.xml.ws.soap.SOAPBinding).
I am looking for a way to easily generate SOAP requests from a wsdl file. for example, something like this:
WSDLObject myWsdl = new WSDLObject("http://www.whatever.com/myService?wsdl");
SOAPRequest myRequest = myWsdl.generateSOAPRequest();
Is there anything like that?
I am trying to do it dynamically via another application, so tools like WSDL2Java dont work for me (at least I think). I need to be able to generate these requests from user input, and then work with them from there.
any help is appreciated.
Please see this answer: How to get response from SOAP endpoint?
What you basically want to do is use the wsimport tool that ships with the JDK. So long as Java is on your system's classpath, you should be able to go to any terminal or console and do:
wsimport http://www.whatever.com/myService?wsdl -p com.company.whateveruwant -d . -keep
With a choice of options (-d specifies the directory to output the generated code). This being done, you'll be able to invoke the web service with the auto-generated code quite simply, such as like:
CustomInterface soap = new CustomEndpoint().getCustomInterface();
System.out.println(soap.getAnswerFromWs("ParamValue"));
You can with WSDL2Java, the unique change is that you work with Java proxy objects and set the attributes of this objects to generate the SOAP request. Other way is use SOAPUI, for example to generate the SOAP message, and directly construct your SOAP message as StringBuffer and use directly a socket to call the service composing the complete HTTP/SOAP message from scratch.