繁体   English   中英

Java Spring作为基于Akka的REST HTTP调用的客户端

[英]Java Spring as a client for Akka based REST HTTP call

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

我的scala REST服务就像

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

              }
            }
            }
        }

在标头中包含App_Key和Content-Type,并在json格式中包含请求参数

请求参数如下:

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

所以我必须从java spring调用此REST服务。 我从java调用http://ipadress:port/notification/signUp

你可以通过 以下实施:

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();
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM