2012-01-18 1 views
0

パラメータに到達し、3つの異なるパラメータを返す単純なWebサービスをコーディングしようとしています。複数の値を返すJAX-WS

私は以下のコードでこれを達成できます。しかし、問題は、setterメソッドもWebサービスに含まれていることです。たとえば、私は "setTransactionID"をwebserviceメソッドから除外して保護したいと思っています。コードを変更するにはどうすればよいですか?

package OKS; 

import javax.jws.WebMethod; 

import javax.jws.WebParam; 

import javax.jws.WebService; 

@WebService 

public class CheckCredit { 

@WebMethod 

public Result GetResult(@WebParam(name="username") String username,@WebParam(name="password") String password) { 

Result res= new Result(); 

    if ((username!=null)&&(password!=null)) { 

     if ((username.equals("xyz"))&&(password.equals("123"))) { 

      res.setResultType(1); 

      res.setTransactionID("tr12128"); 

      res.setCredit(1220); 

     } else { 

      res.setResultType(0); 

      res.setTransactionID("cr12128"); 

      res.setCredit(0); 

     } 

    } else { 

     res.setResultType(0); 

     res.setTransactionID("er12128"); 

     res.setCredit(0); 

    } 

    return res; 

} 

}

結果クラス

package OKS; 

public class Result { 

int resultType; 

String TransactionID; 

int Credit; 

public void setResultType(int resultType) { 

    this.resultType = resultType; 

} 

public void setTransactionID(String transactionID) { 

    TransactionID = transactionID; 

} 

public void setCredit(int credit) { 

    Credit = credit; 

} 

public int getResultType() { 

    return resultType; 

} 

public String getTransactionID() { 

    return TransactionID; 

} 

public int getCredit() { 

    return Credit; 

} 

}

このサービスは、コンパイルし、正常に動作します。しかし、WebServiceにはsetterメソッドも含まれています。 セッターメソッドを除外するにはどうすればよいですか?

+0

setTransactionID()の名前をsetTransactionID_please_dont_export_that_method()などの名前に変更できますか? –

+0

または単にsetTransactionID()パッケージをプライベートな仕事にすることはできますか? –

+0

Aaah、私はあなたが本当にインターフェイスについては気にしないと思ったが、セキュリティについては、そうだよね?その場合、ステートフルなBeanを探しているはずです。http://jax-ws.java.net/nonav/2.2.5/docs/statefulWebservice.htmlプレーンテキストのXMLデータを少しでも安全にすることはできませんあなたは今それをやろうとしています。 –

答えて

0

私はあなたが単にgetIdメソッドで@XmlTransient属性を使用するよりも、output.IfでTransactionIdを取得したくないと思います。