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/
Related
I'm trying to create API resources containing External file reference in parameters and responses and try to get these references resolved using swagger. (Support importing OpenAPI definitions with external references).
For that, I am getting the YAML files as file archive and there will be a master main.YAML file and from that other files are referenced.
OpenAPIV3Parser openAPIV3Parser = new OpenAPIV3Parser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPI openAPI = openAPIV3Parser.read(extractedLocation + "/main.yaml", null, options);
String openAPIContent = Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsString(openAPI);
APIDefinitionValidationResponse apiDefinitionValidationResponse = new APIDefinitionValidationResponse ();
apiDefinitionValidationResponse = OASParserUtil.validateAPIDefinition(openAPIContent, returnContent);
I tried with this code snippet but the apiDefinitionValidationResponse is throwing an error when there is $ref in the YAML file. If there's no $ref then apiDefinitionValidationResponse is a success and api is created.
So i doubt there is a problem in giving the data to OASParserUtil.validateAPIDefinition method (validateAPIDefinition method has no issues and it has been validated and tested)
Could someone help me with this?
The generated YAML file has extensions{} lines all over it
Error messages in debug logs:
attribute info.license.extensions is unexpected
attribute info.extensions is unexpected
attribute components.schemas.ErrorListItem.extensions is unexpected
attribute components.schemas.MenuItem.extensions is unexpected
attribute components.schemas.Order.extensions is unexpected
What i can tell from the error message and your result yaml is, that the transformation step adds some extensions: {} lines into the final yaml.
Having an extensions attribute at those places it complains about is not allowed by the OpenAPI specification.
Looks like your yaml serialization is to simple. Looking at the SerializerUtils from the openapi-generator they have a bit more configuration.
The extra module takes care of serializing only the interesting part of the OpenAPI object.
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
Im trying to redefine the body of a soap xsd with elements from another xsd. The problem Im getting is about the schemas contained in the soap xsd. When I try to load everything in Java in schemaFactory.newSchema, I get this exception:
Failed to read schema document '/soap.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .
The question is: how can I use redefine of a xsd containing other schemas ? It seems I cannot load them properly.
(Im using xsd:redefine tag)
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);
I have the following Java code running on a RESTEasy web service, to get a schema file to validate xml against (note: The project folder is called "MyWebService"):
String classDir = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath();
String myWebServiceDir = classDir.substring(0, classDir.lastIndexOf("MyWebService"));
String instanceXSDPath = myWebServiceDir + SCHEMAS_FOLDER + xsdFile;
System.out.println("Streamsource file location: " + instanceXSDPath);
File file = new File(instanceXSDPath);
//StreamSource streamSource = new StreamSource(file);
// Note: Using StreamSource or File seems to make no difference to the issue
Schema schema = factory.newSchema(file);
When I run the above code on my local machine, everything works great. However, when I run the above code on my development server, I get the following error:
2013-11-20 12:47:48,275 INFO [STDOUT] (ajp-127.0.0.1-8009-4)
Streamsource file location:
file:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd
2013-11-20 12:47:48,275 ERROR
[com.mywebservice.dao.validate]
(ajp-127.0.0.1-8009-4) Could not parse the given object for schema
validation: org.xml.sax.SAXParseException: schema_reference.4: Failed
to read schema document
'file:/Y:/jboss/jboss-as/bin/file:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd',
because 1) could not find the document; 2) the document could not be
read; 3) the root element of the document is not . at
org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
I don't understand why on the server EAP logs the above code is trying to read in instance.xsd from a path that looks like this:
'file:/Y:/jboss/jboss-as/bin/file:/Y:/jboss/jboss-as/server/default/deploy/DEVELOPER_DEPLOY/Schemas/Extensions/1/instance.xsd'
... because on my localhost EAP logs it is reading instance.xsd from a location that looks like this:
'location:
/C:/Users/chen/workspace/.metadata/.plugins/org.jboss.ide.eclipse.as.core/JBoss_5.1_Runtime_Server1382499548190/deploy/Schemas/Extensions/1/instance.xsd'
Does anyone have any ideas as to why? Why is the print message saying 'file' on the server, but 'location' on my locahost in the server logs of each respectively? Perhaps that has something to do with the issue.
The answer was to use StreamSource and set the System Id of the StreamSource to it's original path like so:
StreamSource streamSource = new StreamSource(file);
System.out.println("Stream source system id: " + streamSource.getSystemId());
streamSource.setSystemId(xsltPath);
Schema schema = factory.newSchema(streamSource); // change for each artefact type
This worked, to prevent the mashing of two 'file:' locations, since it hardwired the System Id to be just one. I have no idea why the server was mixing two 'file:' locations into the System Id, but who cares, problem solved!