WSO2 API Manager 1.8.0 fails to import Swagger definition - wso2

I'm trying to import Swagger definition in WSO2 AM 1.8.0 while creating new API. But, the import fails with the exceptions in logs as below,
ERROR {JAGGERY.site.blocks.item-design.ajax.import:jag} - org.mozilla.javascript.WrappedException: Wrapped com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected EOF at line 1 column 27 (/publisher/site/blocks/item-design/ajax/import.jag#25)
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected EOF at line 1 column 27
Caused by: com.google.gson.stream.MalformedJsonException: Expected EOF at line 1 column 27
I'm using below configurations:
Swagger-core_2.11-1.3.12
Swagger-jersey2-jaxrs_2.11-1.3.12
Swagger-annotations-1.3.12
Tomcat 7
JDK 1.7
WSO2 API Manager 1.8.0
I create two simple restful services and add Swagger annotations to them. I can see doc in Swagger UI and can invoke them as well. I verify generated JSON for listing and resources and find it valid. But, when I try to import that definition in WSO2AM, it fails to do so.
What Swagger specification does WSO2 AM 1.8.0 support?
Any help is highly appreciated. Thanks.

I'm able to overcome this problem. The file wso2am-1.8.0\repository\deployment\server\jaggeryapps\publisher\site\blocks\ite‌​m-design\ajax\import.jag has code which sends http requests and fetches json data in loop.
var xhr = new XMLHttpRequest();
for(var i = 0; i < swaggerJson.apis.length; i++){
xhr.open("GET", url + swaggerJson.apis[i].path);
For some reason, it's unable to reuse XMLHttpRequest instance to send subsequent requests. I moved XMLHttpRequest instance creation statement in a for loop and it worked.
//var xhr = new XMLHttpRequest();
for(var i = 0; i < swaggerJson.apis.length; i++){
var xhr = new XMLHttpRequest(); // moved instance creation here
xhr.open("GET", url + swaggerJson.apis[i].path);

Related

How do you remove the "XMLHttpRequest error" in Flutter? (Django backend, Flutter frontend)

I'm having trouble connecting my Django backend to my Flutter frontend on web.I have not tested on Android or iOS yet.
I want to be able to do an API call and have it return a response that I can convert to a json. However it's been throwing errors no matter what I've tried. I've tried converting it into an https request with no avail.
If anyone needs anything on the Django side please let me know
This is what the error looks like:
Error: XMLHttpRequest error.
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28 get current
packages/http/src/browser_client.dart 71:22 <fn>
dart-sdk/lib/async/zone.dart 1613:54 runUnary
dart-sdk/lib/async/future_impl.dart 155:18 handleValue
dart-sdk/lib/async/future_impl.dart 707:44 handleValueCallback
dart-sdk/lib/async/future_impl.dart 736:13 _propagateToListeners
dart-sdk/lib/async/future_impl.dart 533:7 [_complete]
dart-sdk/lib/async/stream_pipe.dart 61:11 _cancelAndValue
dart-sdk/lib/async/stream.dart 1219:7
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14 _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39 dcall
dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58
at Object.createErrorWithStack (http://localhost:63593/dart_sdk.js:5362:12)
at Object._rethrow (http://localhost:63593/dart_sdk.js:39509:16)
at async._AsyncCallbackEntry.new.callback (http://localhost:63593/dart_sdk.js:39503:13)
at Object._microtaskLoop (http://localhost:63593/dart_sdk.js:39335:13)
at _startMicrotaskLoop (http://localhost:63593/dart_sdk.js:39341:13)
at http://localhost:63593/dart_sdk.js:34848:9
And this is a code snippet
import 'package:http/http.dart' as http;
var url2 = 'https://0.0.0.0:8809/test/';
try{
response = await http.get(Uri.parse(url2));
print(response.body);
}
catch(exception){
print('could not access');
response = await http.get(Uri.parse(url2));
}
},
I had it print out the error.
It might be caused because CORS is not enabled in your backend. It happens because your server and frontend are present on different IPs (Even if you are doing your work on localhost, the port is still different).
To solve this you you just have to add parameters to enable CORS in your response header. There are packages available for that acts as a middleware so you wont have to add it in every response. Refer the below question :
How can I enable CORS on Django REST Framework

WSO2 Api manager- Respose body data is null using API SDK

I've created an API using WSO2 Api Manager and gave a backend application URL as a production URL. I'm getting 200 response code and Json responce body in web console of the API but when I use JAVA SDK of that API using client. I'm not able to get the response data even though I'm getting 200 response code.
The below mention java code I'm using to consume the API.
Thanks in Advance!
DefaultApi defaultApiTest = new DefaultApi();
ApiClient apiClient = defaultApi.getApiClient();
apiClient.addDefaultHeader("Accept", "application/json");
apiClient.addDefaultHeader("authorization", "Bearer " + "e88aa28a-4e0e-34a1-aec1-55616bf1e7a1");
apiClient.setBasePath("<Production URL of the API>");
defaultApiTest.setApiClient(apiClient);
ApiResponse<?> response = defaultApiTest.getWithHttpInfo();
if(null != response){
JSON data = apiClient.getJSON();
String value = data.toString();
System.out.println(value);
}

Getting HTTP 401 Error calling MS CRM 365 USING SOAP UI

I am trying to call MSCRM 365 web services using SOAPUI, this is what i have done so far
Downloaded Organization WSDL from my cRM instance
Uploaded in SOAPUI
Added three header parameters - Content-Type, SOAPAction and Accept
Added Username and Password in Request Properties
Whenever I send a request to MSCRM, I get "HTTP ERROR 401 - Unauthorized: Access is denied"
Anyone have any ideas?
Thanks,
Nitesh
Since this is Dynamics 365 it does not authenticate using Username / Password. Instead you will need to use OAuth as shown in the link
https://msdn.microsoft.com/en-us/library/gg327838.aspx
// TODO Substitute your correct CRM root service address,
string resource = "https://mydomain.crm.dynamics.com";
// TODO Substitute your app registration values that can be obtained after you
// register the app in Active Directory on the Microsoft Azure portal.
string clientId = "e5cf0024-a66a-4f16-85ce-99ba97a24bb2";
string redirectUrl = "http://localhost/SdkSample";
// Authenticate the registered application with Azure Active Directory.
AuthenticationContext authContext =
new AuthenticationContext("https://login.windows.net/common", false);
AuthenticationResult result = authContext.AcquireToken(resource, clientId, new
Uri(redirectUrl));
Use the access token in message requests:
using (HttpClient httpClient = new HttpClient())
{
httpClient.Timeout = new TimeSpan(0, 2, 0); // 2 minutes
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", result.AccessToken);
Another options would be to shift from Xrm.Client to Xrm.Tools.Connection. See the example in this site.
https://msdn.microsoft.com/en-us/library/jj602970.aspx

How to add security (username, password) to grails cxf web service

I created two grails project, one for server side cxf web service and other for cxf client for calling web service..
Everything works fine.
I can call web service from client code and get result.
Now I want to add security, then what will be the changes to server and client grails code?
I tried applying security as said by Christian Oestreich in his post.
http://www.christianoestreich.com/2012/04/grails-cxf-interceptor-injection/
(Grails Cxf Interceptor Injection 2.4.x-2.5.x)
and client code for applying security is as follows
ExampleService exampleService = new ExampleService()
def port = exampleService.exampleServicePort
Map ctx = ((BindingProvider)port).getRequestContext();
ctx.put("ws-security.username", "pankaj");
ctx.put("ws-security.password", "pankaj");
println ".......... " + port.sayHello("pankaj")
But I am getting error as follows
Error |
2014-11-06 18:33:15,411 [http-bio-8088-exec-4] ERROR errors.GrailsExceptionResolver - SoapFault occurred when processing request: [GET] /WSDLDemoClient/wsdldemo/index
An error was discovered processing the <wsse:Security> header.. Stacktrace follows:
Message: An error was discovered processing the <wsse:Security> header.
Line | Method
->> 75 | unmarshalFault in org.apache.cxf.binding.soap.interceptor.Soap11FaultInInterceptor
Instead of above mentioned client code, use following code to get it working.
Map<String, Object> req_ctx = ((BindingProvider)hello).getRequestContext();
req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
Map<String, List<String>> headers = new HashMap<String, List<String>>();
headers.put("Username", Collections.singletonList("pankaj"));
headers.put("Password", Collections.singletonList("pankaj"));
req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);

Error when accessing ESB Proxy with Jaggery WSStub

I created a web service and was able to send requests to it from a serverside Jaggery.js script with no problem. Then I created a WSDL Proxy Service inside WSO2 ESB and tested it using the "Try it!" feature.
After I redirected my serverside script from the original web service to its proxy inside ESB, I got the error in System Logs:
The endpoint reference (EPR) for the Operation not found is /services/BpmAdderProcessProxy.BpmAdderProcessProxyHttpSoap11Endpoint and the WSA Action = urn:anonOutInOpResponse. If this EPR was previously reachable, please contact the server administrator.
To see in detail what was happening I activated the "SOAP Message Tracer" of the ESB. Suddenly my serverside script could access the webservice via my ESB proxy. Then I deactivated the "SOAP Message Tracer" and the error message was back again. Is my serverside script correct? Or does the debugging tool modify behavior of debugged code?
I'm a JavaScript developer. Actually Jaggery and UES are targeted at people like me. I'm not supposed to look inside Java code, am I? Is there a forum where JavaScript developers discuss WSO2 UES and Jaggery?
My serverside code is as follows:
<%
var x = request.getParameter("x");
var y = request.getParameter("y");
//var sum = parseInt(x) + parseInt(y);
var sum = add(parseInt(x), parseInt(y));
response.content = {
success: true,
data: {
result: sum
}
};
function add(x, y) {
var ws = require('ws');
var stub = new ws.WSStub("http://02-128:8280/services/BpmAdderProcessProxy?wsdl");
var process = stub.services["BpmAdderProcessProxy"].operations["process"];
var payloadTemplate = process.payloadXML();
var payload = replaceQuestionMarks(payloadTemplate, arguments);
var resultXml = process.request(payload);
var resultValue = resultXml.children().text();
return parseInt(resultValue);
}
function replaceQuestionMarks(template, values) {
var i = 0;
return template.replace(
/\?/g,
function() {
return values[i++];
}
);
}
%>
In ESB v4.8.1, pass-through transport is enabled by default and it does not support SOAP body based dispatching (it does not build the message so it can't acces the body's first element to find the operation)
You can append the operation name to the endpoint url : http://host:8280/services/BpmAdderProcessProxy/OperationName
You can add this parameter in your proxy conf (BpmAdderProcessProxy) in WSO2 ESB : <parameter name="disableOperationValidation" locked="false">true</parameter>
You can edit wso2esb/repository/conf/axis2/axis2.xml and replace <handler class="org.apache.axis2.dispatchers.SOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>
with
<handler class="org.apache.synapse.core.axis2.SynapseSOAPMessageBodyBasedDispatcher" name="SOAPMessageBodyBasedDispatcher"/>