2012-03-19 2 views
0

私はScalaを使って安心してサービスを書いています。サーバー側ではサーバ用に定義された同じインタフェースを使用して安心してクライアントを書く方法

、それはインターフェースを持っています

trait ICustomerService { 
    @GET 
    @Path("/{id}") 
    @Produces(Array("application/xml")) 
    def getCustomer(@PathParam("id") id: Int): StreamingOutput 
} 

サービスが正常に動作し、私は、Webブラウザを使用してそれをテストしました。

ここで、このインターフェイスに自動テストを書きたいと思います。ストリーミング出力のみが書き込みを許可するよう

class CustomerServiceProxy(url : String) { 
    RegisterBuiltin.register(ResteasyProviderFactory.getInstance()); 
    val proxy = ProxyFactory.create(classOf[ICustomerService], url) 

    def getCustomer(id: Int): Customer = { 
    val streamingOutput = proxy.getCustomer(id) 
    <Problem here> 
    } 
} 

は、このコードは動作しません:私が行う必要がある方法は、同じインタフェースを使用してRESTEasyのクライアントを書くことです。

サーバーがクライアント側からストリーミング出力に書き込むものを取得できるように、このテストクラスを作成するにはどうすればよいですか?

感謝

答えて

1

はStreamingOutputは書き込み、それ行い書き込みを許可していません。

/** 
* Re-buffers data from a JAXRS StreamingOutput into a new InputStream 
*/ 
def rebuffer(so: StreamingOutput): InputStream = { 
    val os = new ByteArrayOutputStream 
    so.write(os) 
    new ByteArrayInputStream(os.toByteArray()) 
} 


def getCustomer(id: Int): Customer = { 
    val streamingOutput = proxy.getCustomer(id) 
    val inputStream = rebuffer(streamingOutput) 
    inputStream.read() // or pass it to an XML parser or whatever 
} 

これが役立つことを望むだけです。

関連する問題