解决方案 »

  1.   


    1.所有的接口都可以返回json的..
    restful,rpc方式的都可以...
    webservice 推荐返回string,,在函数里面转换成json字符串发送...2.错误异常处理也是一样,把异常转换成json字符串发出去。。
    接受到以后,转成json对象,判断是不是异常对象就可以了。。如果异常,在抛出或者其他处理这个是我在js里面判断java异常,然后转换成js异常抛出。。双方通信使用json字符串
    如果你是比如c#调用的java,如果返回异常,可以转换成c#的异常抛出就是了。。
    function processJavaEX(data){if(typeof data=="string")  data = eval(  "(" + data + ")"   );  if(data["@type"]!=null && data["@type"]=="java.lang.RuntimeException")  {  if(data.message!=null) logx(data.message); throw data.message;  }
      

  2.   

    看看用jaxrs标准(Jee6)写的代码吧
    @Path("/httpIntercept/v1/")
    @Consumes({ MediaType.APPLICATION_JSON })  //"application/json"
    @Produces({ MediaType.APPLICATION_JSON })   //"application/json"
    public class Service {
    @GET
    @Path("/rule/{id}")
    public String getRule(@PathParam("id") int id) {
            //处理逻辑
    return new Rule(……) .toJsonString();
    } @POST
    @Path("/rule/")
    public Response addRule(final Rule rule) { rule.setId(100);  //处理逻辑 return Response.status(Response.Status.CREATED)   //返回http状态
    .entity(rule.toJsonString()).build();      //返回数据
    }
    对象的json字符串生成 public String toJsonString() {
                         return Json.createObjectBuilder().add("id", this.id).
                           //其他赋值……
    add("lastUpdate", this.lastUpdate).build().toString();
    }客户端POST测试代码 public static void postRuleTest() {
    System.out.println("postRuleTest  "); try {
    URL url = new URL(
    "http://localhost:8080/……v1/rule/");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setDoOutput(true);
    conn.setRequestMethod("POST");
    conn.setRequestProperty("Content-Type", "application/json");
    String ruleJson = new Rule(1, "002", ……)).toJsonString(); OutputStream os = conn.getOutputStream();
    os.write(ruleJson.getBytes());
    os.flush(); System.out.println("ResponseCode  " + conn.getResponseCode());  //获得http状态码
    BufferedReader br = new BufferedReader(new InputStreamReader(
    conn.getInputStream()));
    String buffer;
    while ((buffer = br.readLine()) != null) {    //读取数据
    System.out.print(buffer);
    }
    conn.disconnect();
    System.out.println();
    } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } }
      

  3.   


    webservice-sercurity中的数字证书怎么回事?
    每次请求都会去授权中心获取吗?
    那客户端的怎么办?一个服务有多个客户端他们的证书需要很多个吗
      

  4.   

    https支持单向认证(客户端认证服务器)和双向认证被认证方,需要提供CA中心签发的证书,自己保留私钥文件,向其他各方公开自己的证书(含公钥)
    被认证方使用私钥对随机数签名,认证方使用证书(中的公钥)验证签名。认证方保存所有需要认证的认证方证书