2013-06-04 2 views
0

WSO2 AS5.0에서 매시업을 만들려고합니다. 나는 단순한 HelloWorld 서비스를 성공적으로 만들었지 만, 다른 서비스를 통합하려고하면 오류가 발생합니다.WSO2 매시업 (인수가있는 외부 서비스 사용)

이 나의하여 HelloWorld 서비스입니다 :

this.documentation = "This is a test Hello World service"; 
system.include("HelloStub.js"); 

hello.documentation = "say hello" 
hello.inputTypes = {"user": "string"} 
hello.outputType = "string"; 
function hello(user){ 
    try{ 
     var response = services["admin/testmashup"].operations["sayMyName"](user); 
    }catch(e){ 
     return "Danger, Robinson! " + e.toString() 
    } 
    return "Hello, there! " + response; 
} 

function whoAreYou(){ 
    try{ 
     var response = services["admin/testmashup"].operations["toString"](); 
    }catch(e){ 
     return "Danger, Robinson! " + e.toString() 
    } 
    return "Hello! " + response;  
} 

그리고 이것은 admin/testmashup 서비스

this.serviceName = "testmashup"; 
this.documentation = "Test mashup service" ; 

toString.documentation = "say something" ; 
toString.inputTypes = { /* no arguments */ }; 
toString.outputType = "string"; 
function toString() 
{ 
    return "Hi, my name is testmashup"; 
} 

sayMyName.documentation = "Make me feel happy"; 
sayMyName.inputTypes = {"myName":"string"}; 
sayMyName.outputType = "string"; 
function sayMyName(myName){ 
    return "Your very beautiful name is " + myName; 
} 

나는 내가 admin/testmashup 서비스를 호출 할 때 예상대로 작동하는지주의해야합니다.

파일 HelloStub.js은 WSO2 Applicanton Server에서 생성 한 Javascript (E4X) 스텁입니다.

<ws:whoAreYouResponse xmlns:ws="http://services.mashup.wso2.org/helloWorld?xsd"> 
    <return xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:js="http://www.wso2.org/ns/jstype" js:type="string" xsi:type="xs:string">Hello! &lt;ws:toStringResponse xmlns:ws="http://services.mashup.wso2.org/testmashup?xsd"&gt;&lt;return&gt;Hi, my name is testmashup&lt;/return&gt;&lt;/ws:toStringResponse&gt;</return> 
</ws:whoAreYouResponse> 

내가 인코딩 된 응답 내의 텍스트 Hi, my name is testmashup을 볼 수

내가 인수가없는 작업 whoAreYou을 테스트

, 나는 다음과 같은 응답을 얻을. 그러나 나는 다음과 같은 XML을, hello를 호출 할 때 : 나는 지난 며칠이 작품을 만들기 위해 노력하고 모든 검색 한

<ws:helloResponse xmlns:ws="http://services.mashup.wso2.org/helloWorld?xsd"> 
    <return>Danger, Robinson! org.wso2.carbon.CarbonException: Invalid input for the payload in WSRequest Hostobject : John</return> 
</ws:helloResponse> 

: 나는 다음과 같은 오류가

<body> 
    <p:hello xmlns:p="http://services.mashup.wso2.org/helloWorld?xsd"> 
     <!--Exactly 1 occurrence--> 
     <user>John</user> 
    </p:hello> 
</body> 

대답을 얻기 위해 장소를 찾았지만 찾을 수없는 것 같습니다. official documentation에는 하나 이상의 인수가있는 작업이있는 외부 웹 서비스의 스텁을 사용하는 예제가 없습니다.

또한 가능한 경우 자바 스크립트 매시업에서 REST-JSON 서비스를 사용하는 방법을 알고 싶습니다.

아이디어가 있으십니까?

답변

0

공식 문서에는 중요한 정보가 누락되어 있습니다. 특히, 내 문제를 해결하기 위해 생성 된 스텁이 내부적으로 XML과 JSON 간의 변환을 수행하기 위해 BagderFish 표기법을 사용한다는 것을 아는 것이 중요합니다. 나는 스텁에 가서 조금 뛰어 내 sayMyName 방법에 직결 된이 코드 조각을 foud :

service.operations['sayMyName'] = function (request) { 
    var isAsync, response, resultValue; 
    var operation = service.operations['sayMyName']; 
    request = typeof request === "string" ? request : utils.bf2xml(request); 
    service.$._options = new Array(); 
    . 
    . 
    . 

기능 bf2xml는 XML에 BadgerFish 표기 JSON 변환합니다. 함수는 나중에 스텁에서 정의되며 here도 있습니다. BadgerFish 표기법에 대한 정보는 널리 사용 가능합니다.

HelloWorld 서비스를 제대로 작동 시키려면 XML이 포함 된 문자열 (이 경우 bf2xml 함수는 호출되지 않음) 또는 BadgerFish와 같은 올바른 표기법을 사용하는 JSON 객체를 전달할 수 있습니다.

var response = services["admin/testmashup"].operations["sayMyName"]({request : {myName:{$:user}}}); 
+0

을 그리고 난 내 자신의 질문에 대답 두 번째 시간입니다 ... 너무, 내가 게시 두 번째 질문이 아니었다면 전혀 이상하지 않을 것입니다 ... :

이 작동합니다 – chechopeefe

관련 문제