playframework - Calling webservice from within Play 2.0 -


am having trouble calling webservice within play 2.0 application. here how code looks

future<object> promise = ws.url("http://myurl").get().map(testfunc1, null);  function1 testfunc1 = new function1(){     public void $init$() {}     public object apply(object v1) {         system.out.println("apply");         return "";     }     public function1 andthen(function1 g) { return null; }     public function1 compose(function1 g) {return null;} }; 

but ide throwing me compile time exception saying

error: <anonymous myclass$1> not abstract , not override abstract method andthen$mcvj$sp(function1) in function1      function1 testfunc1 = new function1(){ 

i have these packages imported

import play.api.libs.ws.ws; import scala.function1; import scala.concurrent.future; 

clearly seem missing here. can tell me it. or need map promise object function1?

thanks karthik

your code looks java use scala libraries. package play.api scala api.

use

import play.libs.ws; import play.libs.f.function 

instead of

import play.api.libs.ws.ws; import scala.function1; 

example

//checkout https://github.com/schleichardt/stackoverflow-answers/tree/so18491305 package controllers;  import play.libs.f.function; import play.libs.f.promise; import play.mvc.*; import play.libs.ws;  public class application extends controller {     /**      * action serves proxy google start page      */     public static result index() {         //phase 1 promise of webservice request         final promise<ws.response> responsepromise = ws.url("http://google.de").get();         //phase 2 extract usable data response         final promise<string> bodypromise = responsepromise.map(new function<ws.response, string>() {             @override             public string apply(ws.response response) throws throwable {                 final int statuscode = response.getstatus();                 return response.getbody();//assumed checked response code 200             }         });         //phase 3 transform promise result/http answer         return async(                 bodypromise.map(                         new function<string,result>() {                             public result apply(string s) {                                 return ok(s).as("text/html");                             }                         }                 )         );     } } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -