2013-11-21 2 views
3

Worklight 서버에 어댑터를 배포했는데 외부에서 Worklight Adapter를 나머지 Serverice로 호출해야하는 몇 가지 요구 사항이 있습니다. 제대로 작동하고 필요에 따라 데이터를 반환하지만 json 출력을 제공하는 대신 그것은 HTML을 제공합니다외부 응용 프로그램에서 Worklight 어댑터 호출

<!DOCTYPE html><html><head><meta charset="UTF-8" /><title>Invoke Procedure Result</title><script src="/secure/console/js/jquery-1.6.min.js"></script><style> textarea {  width: 100%; } .textwrapper {  margin: 5px 0;  padding: 3px; }</style></head><body onload="attachEvent();"><div><span id="invRes">Invocation Result of procedure: 'Authentication' from the Worklight Server</span>: </div><div id="target"><textarea rows="20">{ 
    "RESPONSE": { 

     "USER_ID": "292265" 
    }, 
    "errors": [ 
    ], 
    "info": [ 
    ], 
    "isSuccessful": true, 
    "responseHeaders": { 
     "Content-Length": "1195", 
     "Content-Type": "text\/xml;charset=ISO-8859-1", 
     "Date": "Thu, 21 Nov 2013 10:10:13 GMT", 
     "Server": "Oracle GlassFish Server 3.1.2.2", 
     "X-Powered-By": "Servlet\/3.0 JSP\/2.2 (Oracle GlassFish Server 3.1.2.2 Java\/Oracle Corporation\/1.7)" 
    }, 
    "responseTime": 4234, 
    "statusCode": 200, 
    "statusReason": "OK", 
    "totalTime": 4235, 
    "warnings": [ 
    ] 
}</textarea></div><script>function attachEvent() {$('#target').ajaxError(function(e, xhr, ajaxOptions, thrownError){$(this).text("Error: Please ensure that the XML input and XSL transformation are valid and try again.");});}function run_xslt() {var xml = $('#originalXML').val();var xsl = $('#originalXSL').val();$.post('/secure/dev/xslt',{'xml':xml,'xsl':xsl},function(data, textStatus, XMLHttpRequest){$('#target').empty();json = $("<textarea></textarea>");json.attr("rows",25);json.text(data);$('#target').append(json);$('#invRes').text('Result of Local XSL Transformation');},'text');}</script></body></html> 

코드에서 나는 다시 HTML에서 파싱하고 문자열에 json을 저장하고 있습니다. 그럼 나는 그것을 사용할 수 있습니다. 이것은 worklight 문서에 따라 어댑터를 외부 적으로 호출하기 위해 아래에 주어진 URL입니다.

http://WorklightServer.com/secure/dev/invoke?adapter=Reports&procedure=Authentication&parameters=%5B%5D

+0

당신이 어댑터 과정에서 구현 한 내용에 대한 자세한 정보를 제공 할 수 있습니다 당신이 그것을 – Srik

+0

에서 반환하는 내가 작업등 6 버전에 어댑터를 구현하고 형식을 반환 어댑터에 xml입니다. 내가 프로 시저 호출 프로 시저 메서드에 의해 작업 표시 줄에서 어댑터를 실행하는 경우 json 출력을 제공하지만 위의 json 대신 json을 포함하는 HTML을 반환하는 url에서 액세스합니다. –

+0

@vishal_g이 주제를 설명하는 작업 영역 문서 링크를 제공해 주시겠습니까? –

답변

4

제거는/dev/URL과 구성 요소, 그것은 개발 용이성 목적으로 만 사용됩니다. 그것없이 JSON을 얻을 수 있습니다.

+0

예,/dev를 제거한 후에 json을주고 있지만/* - secure- jsonData * /를 추가하고 있습니다. 그리고 아약스 전화를 할 때, 나는 돌아 오지 않는다. 브라우저에서/* - secure jsondata * /를 사용하여 json 데이터를 표시합니다. 이 –

+1

으로 도와 주시면 항상 JSON을/* secure * /에 넣을 수 있습니다. 이것은 XSS 공격을 위해 WL 서버 사용을 막기위한 것입니다. – Anton

1

나는 Anton의 답변을 읽은 후 Ajax 호출의 "dataType"을 "text"로 설정 한 다음/* - secure- 및 * /를 제거하기 위해 응답을 편집 한 다음 문자열을 구문 분석합니다 얻을 JSON "JSON.parse (theString)"

$.ajax({ 
      type: 'POST', 
      url: ajaxURL,    
      async: true, 
      cache: true, 
      timeout: 5, 
      dataType: "text", 
      success: function(data){      
       data = data.replace("/*-secure-",""); 
       data = data.replace("*/","");     
       var dataJSON = JSON.parse(data);      
       //Do success     
      }, 
      error: function(data, statusCode){ 
       //Do error     
      } 
     }); 
관련 문제