2014-03-05 39 views
2

我试图做的Clojure和JAX-WSClojure的SOAP服务器JAX-WS

(ns test-ws.routes.home 
(:import (javax.jws WebMethod WebService) 
     (javax.xml.ws Endpoint))) 

(defprotocol Calculator (add [this a b])) 

(deftype ^{WebService {:targetNamespace "test.seltzer" }} 
    CalcWeb [] Calculator (^{WebMethod []} add [this a b] (+ a b))) 

(def endpoint (Endpoint/publish "http://localhost:8080/calcWeb" (CalcWeb.))) 

一个简单的SOAP Web服务器是WSDL可在http://localhost:8080/calcWeb?wsdl后,但是当我试图从SOAP-UI叫它我: com.sun.org.apache.xerces.internal.dom.ElementNSImpl不能转换到java.lang.Number中

我的想法是,Clojure中不能映射SOAP请求号码,以便我加注释

(defprotocol Calculator (add [this ^Integer a ^Integer b])) 
(deftype ^{WebService {:targetNamespace "test.seltzer" }} 
    CalcWeb [] Calculator (^{WebMethod []} add [this ^Integer a ^Integer b] (+ a b))) 

现在在编译时我有以下错误:找不到匹配的方法:添加,关闭自动匹配提示。

我也试过这个

(defprotocol Calculator (add [this ^Integer a ^Integer b])) 

(deftype ^{WebService {:targetNamespace "test-ws.routes.home"}} 
    CalcWeb [] Calculator (^{WebMethod []} add [this 
           #^{WebParam {:name "param0"} :tag Integer} a 
           #^{WebParam {:name "param1"} :tag Integer} b] (+ a b))) 

我给了我同样的错误。

我错过了什么吗?

回答

1

我真的很接近解决问题。诀窍是使用接口而不是协议。 我希望这将是一个一些有用:

(ns wstest.core 
    (:import (javax.jws WebMethod WebService WebParam) 
     (javax.xml.ws Endpoint) 
     (wstest.java Person))) 

(definterface IFooService 
    (^int add [^int a ^int b]) 
    (^String sayHi [^String name]) 
    (^wstest.java.Person makePerson [^String firstName ^String lastName]) 
    (^String sayHiTo [^wstest.java.Person person])) 

(deftype ^{WebService {:targetNamespace "o.m.g"}} FooService [] 
    IFooService 
    (^int ^{WebMethod []} add [this ^int #^{WebParam {:name "a"}} a ^int #^{WebParam {:name "b"}} b] 
    (int (+ a b))) 
    (^String ^{WebMethod []} sayHi [this ^String #^{WebParam {:name "name"}} name] 
    (str "Hello, " name "!")) 
    (^wstest.java.Person ^{WebMethod []} makePerson [this ^String #^{WebParam {:name "firstName"}} firstName ^String #^{WebParam {:name "lastName"}} lastName] 
    (doto (wstest.java.Person.) 
     (.setFirstName firstName) 
     (.setLastName lastName))) 
    (^String ^{WebMethod []} sayHiTo [this ^wstest.java.Person #^{WebParam {:name "person"}} person] 
    (str "Hello, " (.getFirstName person) " " (.getLastName person) "!"))) 

(def endpoint (atom nil)) 

(do 
    (if-not (nil? @endpoint) 
    (.stop @endpoint)) 
    (reset! endpoint (Endpoint/publish "http://localhost:8080/fooService" (FooService.)))) 

Person.java:

package wstest.java; 

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlElement; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name = "Person") 
public class Person { 
@XmlElement 
protected String firstName; 
@XmlElement 
protected String lastName; 

public String getFirstName() { 
    return firstName; 
} 

public void setFirstName(String value) { 
    this.firstName = value; 
} 

public String getLastName() { 
    return lastName; 
} 

public void setLastName(String value) { 
    this.lastName = value; 
} 
} 
+0

这已经有一段时间,但有没有变化我可以从可能的话有些回购叉你的工作的例子吗?谢谢 :) –