wsdl2java output produces only the package name - wsdl

i have used a sample wsdl in my java code. when i try to print the output it returns only the package name like:
com.holidaywebservice.holidayservice_v2.CountryCode#6b6478
This happens only when the output was a list.
Part of my code:
HolidayService2 hs1= new HolidayService2();
HolidayService2Soap hss1= hs1.getHolidayService2Soap();
ArrayOfCountryCode acc = hss1.getCountriesAvailable();
system.out.println(acc.getCountryCode());
wsdl url:http://holidaywebservice.com/HolidayService_v2/HolidayService2.asmx?WSDL

With this com.holidaywebservice.holidayservice_v2.CountryCode#6b6478 you're trying to print the ArrayOfCountryCode object. Your code instead should be:
package com.holidaywebservice.holidayservice_v2.clientsample;
import com.holidaywebservice.holidayservice_v2.*;
public class ClientSample {
public static void main(String[] args) {
//Create Web Service Client..."
HolidayService2 service1 = new HolidayService2();
//Create Web Service...
HolidayService2HttpGet port1 = service1.getHolidayService2HttpGet();
//call WS
ArrayOfCountryCode acc = port1.getCountriesAvailable();
for(CountryCode cc : acc.getCountryCode()){
System.out.println("Country code is: " + cc.getCode());
System.out.println("Country code Description is: " + cc.getDescription());
}
}
}
Update Try just adding the below
for(CountryCode cc : acc.getCountryCode()){
System.out.println("Country code is: " + cc.getCode());
System.out.println("Country code Description is: " + cc.getDescription());
}
After the line ArrayOfCountryCode acc = hss1.getCountriesAvailable(); in your current code. But you see the gist of it, acc is an array of country codes.

Related

how to get uri req res body from a yaml by swagger parser

I want to get uri, request, response body, response code from a swagger yaml file.
Then I can put them into my own database.
Like this:
I tried to do something by adding io.swagger.parser.SwaggerParser in a java program. I think the way swagger codegen does it is the right solution. But I can't get anything from the source code of codegen.
This question is about parsing the yaml file and get the structure.
Next question: How to get request body and response body in JSON from a Swagger yaml
The easiest way is to use a parser to parse the specification file.
Then you can iterate over the elements you are interested in and do what ever you want.
If your specification input is in the Swagger 2.0 format (json or yaml), you can use this parser:
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-parser</artifactId>
<version>1.0.34</version>
</dependency>
Here an example method:
import java.util.Map;
import io.swagger.models.HttpMethod;
import io.swagger.models.Operation;
import io.swagger.models.Path;
import io.swagger.models.Response;
import io.swagger.models.Swagger;
import io.swagger.models.parameters.Parameter;
import io.swagger.parser.SwaggerParser;
public class UseParserExample {
public static void main(String[] args) {
Swagger swagger = new SwaggerParser().read("<path to your specification>");
Map<String, Path> paths = swagger.getPaths();
for (Map.Entry<String, Path> p : paths.entrySet()) {
Path path = p.getValue();
Map<HttpMethod, Operation> operations = path.getOperationMap();
for (Entry<HttpMethod, Operation> o : operations.entrySet()) {
System.out.println("===");
System.out.println("PATH:" + p.getKey());
System.out.println("Http method:" + o.getKey());
System.out.println("Summary:" + o.getValue().getSummary());
System.out.println("Parameters number: " + o.getValue().getParameters().size());
for (Parameter parameter : o.getValue().getParameters()) {
System.out.println(" - " + parameter.getName());
}
System.out.println("Responses:");
for (Map.Entry<String, Response> r : o.getValue().getResponses().entrySet()) {
System.out.println(" - " + r.getKey() + ": " + r.getValue().getDescription());
}
System.out.println("");
}
}
}
}
Here an ouput example:
PATH: /user/{username}
Http method: PUT
Summary: Updated user
Parameters number: 2
- username
- body
Responses:
- 400: Invalid user supplied
- 404: User not found
===
PATH: /user/{username}
Http method: DELETE
Summary: Delete user
Parameters number: 1
- username
Responses:
- 400: Invalid username supplied
- 404: User not found

Google Machine Learning API Issue

I'm trying to use the Google Machine Learning API and I'm facing two problems.
In the API explorer I put the correct information and I get a response error:
Code 200
"error": "Missing \"instances\" field in request body: {\n \"httpBody\": \n
{\n \"data\": \"\\"instances\\" : \\"teste\\"\",\n
\"contentType\": \"application/json\"\n }\n}"
The request find my model (if I change the value in field name I get another error) but don't understand my json. That's the json:
{"instances" : [{"key":"0", "image_bytes": {"b64": "mybase64"} }]}
When I do the predict on the command line using gcloud, I get no errors and everything seems ok. The Json that I was create for gcloud is a little bit different:
{"key":"0", "image_bytes": {"b64": "mybase64"} }
I already tryied that one in the API explorer and no success.
So, I decided to use the .Net Api to try the predict and I get other situation: The Response is Empty (???).
Here is my code:
'get the service credential that I created
Dim credential = Await GetCredential()
Dim myService As New CloudMachineLearningEngineService(New BaseClientService.Initializer() With {
.ApplicationName = "my Project Name (Is That It???)",
.ApiKey = "my API Key",
.HttpClientInitializer = credential
})
Dim myBase64 As String = GetBase64("my image path to convert into a base64 String")
Dim myJsonRequest As String = "{""instances"" : [{""key"":""0"", ""image_bytes"": {""b64"": """ + myBase64 + """}}]}"
Dim myRequest = New GoogleCloudMlV1PredictRequest With {
.HttpBody = New GoogleApiHttpBody With {.Data = myJsonRequest,
.ContentType = "application/json"
}
}
'If I change the model name I get error
Dim myPredictRequest = myService.Projects.Predict(myRequest, "projects/myProject/models/myModel/versions/v1")
myPredictRequest.AccessToken = credential.Token.AccessToken
myPredictRequest.OauthToken = credential.Token.AccessToken
myPredictRequest.Key = "my API Key
'Execute the request
Dim myResponse = myPredictRequest.Execute()
'at this point, myResponse is Empty (myResponse.ContentType Is Nothing, myResponse.Data Is Nothing And myResponse.ETag Is Nothing)
If I change the model name I get a error informing that my model was not found, so my credentials are right.
I don't know what I'm doing wrong. Someboby can help with any of this issues?
Thanks!
UPDATE: --------------------------
I changed this Execute Command:
Dim myResponse = myPredictRequest.Execute()
To This One:
Dim s = StreamToString(myPredictRequest.ExecuteAsStream())
and Now I can get the same error with .Net API and google developers interface (Missing instances field...).
So If someboby just Know what is wrong with my Json request, It will help a lot.
The JSON you put in the API explorer is indeed correct (assuming, of course, your model has inputs key and image_bytes). This appears to be a bug with the explorer I will report.
The reason you are getting the error you are in the .NET code is because you are using an .HttpBody field. This code:
Dim myJsonRequest As String = "{""instances"" : [{""key"":""0"", ""image_bytes"": {""b64"": """ + myBase64 + """}}]}"
Dim myRequest = New GoogleCloudMlV1PredictRequest With {
.HttpBody = New GoogleApiHttpBody With {.Data = myJsonRequest,
.ContentType = "application/json"
}
}
Will produce a JSON request that looks like this:
{
"httpBody": {
"data": "{\"instances\" : [{\"key\":\"0\", \"image_bytes\": {\"b64\": \"mybase64\"} }]}",
"contentType": "application\/json"
}
}
When what you really need is:
{"instances" : [{"key":"0", "image_bytes": {"b64": "mybase64"} }]}
Hence the error message you see.
I don't know how to generate the correct response using the .NET library; based on the Python example in the docs, I would guess:
Dim myJsonRequest As String = "{""instances"" : [{""key"":""0"", ""image_bytes"": {""b64"": """ + myBase64 + """}}]}"
Dim myPredictRequest = myService.Projects.Predict(myJsonRequest, "projects/myProject/models/myModel/versions/v1")
But I don't have a good way of testing that. For reference, the Python equivalent is:
response = service.projects().predict(
name=name,
body=myJsonRequest
).execute()
I solved the problem with .Net API.
I created two new classes Inherits the Google API's classes.
Something like that:
Imports Google.Apis.CloudMachineLearningEngine.v1.Data
Imports Newtonsoft.Json
Public Class myGoogleCloudMlV1PredictRequest
Inherits GoogleCloudMlV1PredictRequest
<JsonProperty("instances")>
Public Property MyHttpBody As List(Of myGoogleApiHttpBody)
End Class
Imports Google.Apis.CloudMachineLearningEngine.v1.Data
Imports Newtonsoft.Json
Public Class myGoogleApiHttpBody
Inherits GoogleApiHttpBody
<JsonProperty("image_bytes")>
Public Property MyData As image_byte
<JsonProperty("key")>
Public Property key As String
End Class
So, in my original code I change this part:
Dim myBase64 As String = GetBase64("my_image_path_to_convert_into_a _base64_String")
Dim myJsonRequest As String = "{""instances"" : [{""key"":""0"", ""image_bytes"": {""b64"": """ + myBase64 + """}}]}"
Dim myRequest = New GoogleCloudMlV1PredictRequest With {
.HttpBody = New GoogleApiHttpBody With {.Data = myJsonRequest,
.ContentType = "application/json"
}
}
For this one:
Dim myBase64 As String = GetBase64("my_image_path_to_convert_into_a _base64_String")
Dim myRequest = New myGoogleCloudMlV1PredictRequest With {
.MyHttpBody = New List(Of myGoogleApiHttpBody)()
}
Dim item As myGoogleApiHttpBody = New myGoogleApiHttpBody With {
.key = "0",
.MyData = New image_byte With {
.b64 = myBase64
}
}
myRequest.MyHttpBody.Add(item)
And voilá, It's working!
Thanks for everyone!!
Github issue #1068 shows two work-arounds for this problem.
In summary, use service.ModifyRequest to insert the raw JSON content.
Or use service.HttpClient.PostAsync(...) directly.

Invoking Adapter from Java - Worklight 6.2

Below is the java sample code from worklight to invoke adapter.
public static void testAdapterCall(){
try{
DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
String paramArray = "[5, 3,]";
ProcedureQName procedureQname = new ProcedureQName("CalculatorAdapter", "addTwoIntegers");
InvocationResult result = service.invokeProcedure(procedureQname, paramArray);
}
catch(Exception e)
{
e.printStackTrace();
}
}
I'm getting a Null Pointer exception, when it goes to line
DataAccessService service = WorklightBundles.getInstance().getDataAccessService();
Log is as below:
java.lang.NullPointerException
at com.worklight.customcode.Calculator1.testAdapterCall(Calculator1.java:38)
at com.worklight.customcode.Calculator1.main(Calculator1.java:53)
Versions:
Java 1.7
Worklight 6.2
The Adapter is deployed, and the server is also running locally.
I saw this question in other sites also, but it is not answered.
Any help is highly appreciated.
See the documentation in the following PDF document, starting page #13.
public void callProcedure() {
DataAccessService service = worklightBundles.getInstance().getDataAccessService();
String paramArray = "['param1', 'param2', 'param3']";
ProcedureQName procedureQName = new ProcedureQName("adapterName",
"procedureName");
InvocationResult result = service.invokeProcedure(ProcedureQName,
paramArray);
JSONObject jsonObject = result.toJSON();
String value = (String)jsonObject.get("key");
}
Be sure to add any missing includes once you enter the code into a Java IDE, such as Eclipse.

Vaadin 7 and applet

0.7 and I want to Call an Applet for use a Token.
I did various tests:
1) Use of AppletIntegration 1.2.9 but when I call applet there's an Exception "ClassNotFoundException PaintTarget"
2) Download Legacy 1.2.10 by https://github.com/Haulmont/AppletIntegration/releases but when I cal the page I have the Exception ""Widgetset does not contain implementation for org.vaadin.applet.AppletIntegration. Check its #ClientWidget mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions. Unrendered UIDL:
org.vaadin.applet.AppletIntegration(NO CLIENT IMPLEMENTATION FOUND)"
3) I create a class AppletCustom
public class AppletCustom extends CustomComponent {
public AppletCustom(String codebase,
String archive,
String code,
String width,
String height,
Map<String, String> params) {
setCompositionRoot(new Label("<div id='appletDiv'></div>", ContentMode.HTML));
StringBuilder sb = new StringBuilder();
/* create the applet */
sb.append("var obj = document.createElement('object');");
sb.append("obj.setAttribute('type','application/x-java-applet');");
sb.append("obj.setAttribute('width','" + width + "');");
sb.append("obj.setAttribute('height','" + height + "');");
sb.append("var codeParam = document.createElement('param');");
sb.append("codeParam.setAttribute('name', 'code');");
sb.append("codeParam.setAttribute('value', '" + code + "');");
sb.append("obj.appendChild(codeParam);");
sb.append("var archiveParam = document.createElement('param');");
sb.append("archiveParam.setAttribute('name', 'archive');");
sb.append("archiveParam.setAttribute('value','" + archive + "');");
sb.append("obj.appendChild(archiveParam);");
sb.append("var param = document.createElement('param');");
sb.append("param.setAttribute('name', 'codebase');");
sb.append("param.setAttribute('value','" + codebase + "');");
sb.append("obj.appendChild(param);");
/* add params to the applet if you like */
if(params != null && !params.isEmpty()){
Iterator<Entry<String, String>> it =
params.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String> pairs = (Map.Entry<String, String>) it.next();
sb.append("param = document.createElement('param');");
sb.append("param.setAttribute('name', '" + pairs.getKey() + "');");
sb.append("param.setAttribute('value','" + pairs.getValue() + "');");
sb.append("obj.appendChild(param);");
}
}
sb.append("document.getElementById('appletDiv').appendChild(obj);");
JavaScript.getCurrent().execute(sb.toString());
}
}
and i Call it in the page. The applet is seen correctly but i must to return a value using the method
vaadinUpdateVariable("docName", docName + SIGNED_FILE_SUFFIX, true);
How can i resolve my problem?
you might have have run into one of two Maven GWT plugin bugs: [MGWT-147][1] or [MGWT-148][2] just like [Henri Sara][3] said .
i recommended this blog for you : Vaadin addons and maven and eclipse.
please read this also : Using Vaadin with Maven 2
to help you getting your add-on work . if still n't fixed i refer using [Embedded][6] ui component and avoid the hard coding html tag's.
i wish if i helped you if n't i'm sorry that all i know about Vaadin+applets.
1# jira.codehaus(.)org/browse/MGWT-147
2#jira.codehaus(.)org/browse/MGWT-148
3#vaadin(.)com/c/my_sites/view?groupId=13199&privateLayout=0
4# vaadin(.)com/download/prerelease/7.0/7.0.0/7.0.0.rc2/docs/api/com/vaadin/ui/Embedded.html

Parse REST Request in SOAPUI Mock Service

I am trying to achieve a very simple goal in soapui
I have created a mock rest service in soapui that I can return static content from if the last resource matches a file name. problem is:
I use Spring RESTTemplate to make a REST call ala:
http://www.sample.com/user/group/{1}/status
where {1} is the only variable (it will be a number like 1111 or 2323)
In the OnRequest script section I should be able to write something simple that allows me to extract this resource from the full url and then craft a return of a static file of the same name ie:
ref = value.at.specified.location.{1}.in.url
return file(ref.xml)
any help translating these 2 pseudo code lines to actual working code would be helpful
this works:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
path = groovyUtils.getProjectPath() + "/docroot/" + mockRequest.getPath().tokenize('/')[4] + ".xml";
try
{
mockRunner.returnFile(mockRequest.httpResponse, new File(path));
mockRequest.httpResponse.status = 201
}
catch (Exception e)
{
mockRequest.httpResponse.status = 403
}
return new com.eviware.soapui.impl.wsdl.mock.WsdlMockResult(mockRequest);

Resources