Java Spring作为基于Akka的REST HTTP调用的客户端 [英] Java Spring as a client for Akka based REST HTTP call

查看:99
本文介绍了Java Spring作为基于Akka的REST HTTP调用的客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从 java-spring 中调用 scala-akka 项目中编写的REST服务。

i have to call this REST service written in scala-akka project from java-spring.

我的scala REST服务就像

my scala REST service is like

val route =
    post {
        path("notification" / "signUp"){
            headerValueByName("App_Key") { app_key => {
              handleWith {
                requestParameters: RequestParameters =>
                  //application specific implementation

              }
            }
            }
        }

其中包含json格式的 App_Key和标题内容类型以及请求参数

which contains App_Key and Content-Type in header and request parameters in json format.

请求参数如下:

case class RequestParameters (
     var name: String,
     var email: String,
     var password: String,
     var hashKey: String
   )

因此我必须从 java spring 中调用此 REST 服务。我在java中调用 http:// ipadress:port / notification / signUp 时苦苦挣扎。

so i have to call this REST service from java spring. I an struggling while calling http://ipadress:port/notification/signUp from java .

推荐答案

你可以通过这个来调用它。实施后:

U can call this via. Following Implementation :

try {

            Client client = Client.create();

            WebResource webResource = client.resource(http://ipadress:port/notification/signUp);

            JSONObject formData=new JSONObject();
            formData.put("name", UserName);
            formData.put("email", EmailId);
            formData.put("password", Password);
            formData.put("urlHash",HashKey);

            ClientResponse response = webResource.header("App_Key",xxxxxxxxxxxxxxxxxxxxxxxxxx).type(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, formData);

        } catch (Exception e) {

            e.printStackTrace();
        }

这篇关于Java Spring作为基于Akka的REST HTTP调用的客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆