kagamihogeの日記

kagamihogeの日記です。

Eclipse + Payara + SOAP Web Service

検証用の適当なSOAP Web Serviceが必要になったので試しにPayaraで作成した時のメモ。

事前準備

各種ソフトウェアのダウンロード。

各種手順

EclipseのPayara設定

EclipseのHelp -> Eclipse Market PlaceでPayara Toolsをインストール。payaraで検索すれば出てくる。

Payaraのserver設定。Window -> Preferences -> Server -> Runtime EnvironmentsでAdd

Payaraを選択する。

Parayaのディレクトリを選択する。Javaも必要に応じてjdkのインストールディレクトリを選択する。

Paraya Serverが追加されればOK

Dynamic Web Projectを作る

File -> New -> Dynamic Web Projectを選ぶ。Project nameを適当にここではsample-payaraと入力、Target Runtimeには上で作成したPayara Serverを選ぶ。

Server設定

Serverビュー(無ければWindow -> Show View -> Serversで開く)のClick this links ...をクリックする。

Payaraを選ぶ。

上で作成したsample-payaraプロジェクトをAddする。

プロジェクトが追加されたらServerはこうなる。

Payara Server右クリック -> Startで起動。

http://localhost:8080/ でhelloページが開けばOK。

適当なWeb Service作成

https://tomee.apache.org/examples-trunk/simple-webservice/ソースコードを丸ごとコピーさせてもらう。

package sample;

import javax.jws.WebService;

@WebService(targetNamespace = "http://superbiz.org/wsdl")
public interface CalculatorWs {

  public int sum(int add1, int add2);

  public int multiply(int mul1, int mul2);
}
package sample;

import javax.ejb.Stateless;
import javax.jws.WebService;

@Stateless
@WebService(portName = "CalculatorPort", serviceName = "CalculatorService", targetNamespace = "http://superbiz.org/wsdl", endpointInterface = "sadfasdf.CalculatorWs")
public class Calculator implements CalculatorWs {
  public int sum(int add1, int add2) {
    return add1 + add2;
  }

  public int multiply(int mul1, int mul2) {
    return mul1 * mul2;
  }
}

http://localhost:8080/CalculatorService/Calculator?wsdlWSDLxmlが見られればOK。

動作確認

curl(実際にはpostmanを使用)で動作確認。

curl --location --request POST 'http://localhost:8080/CalculatorService/Calculator' \
--header 'Content-Type: text/xml' \
--data-raw '<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <ns1:sum xmlns:ns1="http://superbiz.org/wsdl">
      <arg0>4</arg0>
      <arg1>6</arg1>
    </ns1:sum>
  </soap:Body>
</soap:Envelope>'

下記のレスポンスが返ればOK。

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
        <ns2:sumResponse xmlns:ns2="http://superbiz.org/wsdl">
            <return>10</return>
        </ns2:sumResponse>
    </S:Body>
</S:Envelope>