-------------------------------------------------------------------------

작성자: 김인태 (http://blog.naver.com/inking007)

제목: Axis WebService 설치및 테스트

참고 : http://www.javaworld.com/javaworld/jw-04-2003/jw-0411-axis_p.html

-------------------------------------------------------------------------

 

Axis 설치

 

1) Apache Tomcat 설치

   버전 4.1  이상 Full 버전으로 설치해야만 한다.

 

2) JDK 설치

   버전 1.3 이상으로 설치 해야만 한다.

 

3) Axis 다운로드 후 CLASSPATH를 설정한다.

 

c:\axis에 설치했다고 가정하면 다음과 같이 설정해 준다.

set AXIS_HOME=c:\axis
set AXIS_LIB=%AXIS_HOME%\lib
set AXISCLASSPATH=%AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar;
    %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar;%AXIS_LIB%\saaj.jar;
    %AXIS_LIB%\log4j-1.2.8.jar;%AXIS_LIB%\xml-apis.jar;%AXIS_LIB%\xercesImpl.jar;%AXIS_LIB%\wsdl4j.jar

set CLASSPATH=%CLASSPATH%;%AXISCLASSPATH%

 

CLASSPATH에 있는 xml-apis.jar 파일과 xercesImpl.jar 파일은 http://xml.apache.org/xerces2-j/ 에 접속해서 다운로드 받으면 된다.

 

4) c\axis\webapps\axis 디렉토리를 tomcat의 webapps에 복사한다.

 

5) 톰켓 실행

 

6) 테스트

 

> 연결 테스트

http://localhost:8080/axis

 

> 라이브러리 테스트

http;//localhost:8080/axis/happyaxis.jsp

 

> SOAP 테스트

http://localhost:8080/axis/services/Version?method=getVersion

다음과 같이 출력되어야 한다. (build date와 version등은 다를수 있다.)

  <?xml version="1.0" encoding="UTF-8" ?>
  <soapenv:Envelope
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
   <getVersionResponse
    soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <getVersionReturn
     xsi:type="xsd:string">
     Apache Axis version: 1.1 Built on Apr 04, 2003 (01:30:37 PST)
    </getVersionReturn>
   </getVersionResponse>
   </soapenv:Body>
  </soapenv:Envelope>

 

> AdminClient 테스트

cd c:\axis\stock 

java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

ClassNotFoundException 오류가 발생한경우 CLASSPATH를 확인해 볼것

 

deploy가 성공했는지 확인한다.

http://localhost:8080/axis/servlet/AxisServlet

다음과 같이 웹서비스가 설치되었는지 확인해 본다.

  urn:xmltoday-delayed-quotes (wsdl) 
        test 
        getQuote

 

> 클라이언트 수행 테스트

java -cp .;%AXISCLASSPATH% samples.stock.GetQuote -lhttp://localhost:8080/axis/servlet/AxisServlet  -uuser1 -wpass1 XXX

 

실행결과가 55.25가 출력된 경우.. 성공!!

 

 

웹서비스를 알려면 SOAP, WSDL, WSDD 대해서 꼭 알아야 한다.

 

자세한 내용은 추후에 설명하도록 한다.

 

SOAP (Simple Object Access Protocol)

WSDL (Web Service Description Langauge)

WSDD (Web Service Deployment Descriptor)

 

프로그램을 작성하는 순서

 

1. 서버 Interface와 구현 Class를 작성한후 컴파일 한다.

 

2. 구현 클래스로 부터 WSDL 파일을 생성한다.

 

3. WSDL 파일로 부터 deploy.wsdd 파일을 생성한다.

 

4. deploy.wsdd 파일을 이용해서 웹서비스를 deploy하고 server-config.wsdd 파일을 생성 수정한다.

 

5. 구현클래스로 부터 client-side 클래스를 생성한다.

 

 

프로그램 작성 플로우

 

 

   

 

1) 자바 Interface와 자바 Implement 클래스 작성

//begin - HelloIF.java

package webservice.hello;

public interface HelloIF extends java.rmi.Remote {
    public String hello(java.lang.String name) throws java.rmi.RemoteException;
}
//end - HelloIF.java

 

//begin - HelloImpl.java

package webservice.hello;

public class HelloImpl implements HelloIF {
    public HelloImpl() {
    }

    public String hello(String name) {
        System.out.println(name);
        return "hi " + name;
    }
}

//end - HelloImpl.java

 

컴파일

javac -d . HelloImpl.java

컴파일 후 webservice/hello 디렉토리밑에 HelloImpl.class 와 HelloIF.class가 생성되었는지 확인한다.

 

생성된 class파일을 C:\lecture\Tomcat 4.1\webapps\axis\WEB-INF\classes 디렉토리에 패키지 디렉토리를 포함해서 복사한다.

 

2) 구현 클래스로부터 WSDL 작성

java org.apache.axis.wsdl.Java2WSDL -o c:\javaprogram\webservice\hello\Hello.wsdl -l http://localhost:8080/axis/services/Hello -n http://hello.webservice -pwebservice.hello http://hello.webservice webservice.hello.HelloIF

 

Java2WSDL 인자 (http://ws.apache.org/axis/java/reference.html)

인자

의미

-o 파일경로

wsdl 생성 위치

-l URL

client가 접속할 URL

-n  네임스페이스

WSDL의 타켓 네임스페이스

-p패키지 네임스페이스

네임스페이스와 네임스페이스 매핑

Target

인터페이스 이름

 

 

생성된 wsdl 파일

 

 

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="
http://hello.webservice" xmlns:impl="http://hello.webservice" xmlns:intf="http://hello.webservice" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<!--WSDL created by Apache Axis version: 1.2alpha
Built on Dec 01, 2003 (04:33:24 EST)-->

   <wsdl:message name="helloResponse">

      <wsdl:part name="helloReturn" type="xsd:string"/>

   </wsdl:message>

   <wsdl:message name="helloRequest">

      <wsdl:part name="in0" type="xsd:string"/>

   </wsdl:message>

   <wsdl:portType name="HelloIF">

      <wsdl:operation name="hello" parameterOrder="in0">

         <wsdl:input name="helloRequest" message="impl:helloRequest"/>

         <wsdl:output name="helloResponse" message="impl:helloResponse"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="HelloSoapBinding" type="impl:HelloIF">

      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="hello">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="helloRequest">

            <wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://hello.webservice"/>

         </wsdl:input>

         <wsdl:output name="helloResponse">

            <wsdlsoap:body use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://hello.webservice"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="HelloIFService">

      <wsdl:port name="Hello" binding="impl:HelloSoapBinding">

         <wsdlsoap:address location="http://localhost:8080/axis/services/Hello"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

 

 

 

3), 4)  WSDL 파일로 부터 deploy.wsdd 파일 생성 및 client-side 자바 클래스 생성

 

java org.apache.axis.wsdl.WSDL2Java -o c:\javaprogram\webservice\hello\ -d Application -s c:\javaprogram\webservice\hello\Hello.wsdl

 

c:\javaprogram\webservice\hello 디렉토리 하위에 webservice/hello 새로운 디렉토리가 생성된것을 확인 할수 있다.

그 디렉토리에 deploy.wsdd 파일과 새롭게 생성된 자바 파일이 존재해야 한다.

 

WSDL2Java 인자

인자

의미

-o 디렉토리경로

wsdd 파일과 클래스파일이 생길 디렉토리

-d  scope

설치 영역 Application, Request , Session

-s

wsdd 파일 생성

Target

wsdl 파일 경로

 

deploy.wsdd 파일 수정

 

wsdd 파일은 wsdl 파일만 가지고 생성되었기 때문에 실제 구현클래스가 무엇인지 제대로 설정이 안되어 있으므로 그부분을 수정해 주어야한다.

 

 

<deployment

    xmlns="http://xml.apache.org/axis/wsdd/"

    xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

 

  <!-- Services from HelloIFService WSDL service -->

 

  <service name="Hello" provider="java:RPC" style="rpc" use="encoded">

      <parameter name="wsdlTargetNamespace" value="http://hello.webservice"/>

      <parameter name="wsdlServiceElement" value="HelloIFService"/>

      <parameter name="wsdlServicePort" value="Hello"/>

      <parameter name="className" value="webservice.hello.HelloImpl"/>

      <parameter name="wsdlPortType" value="HelloIF"/>

      <operation name="hello" qname="operNS:hello" xmlns:operNS="http://hello.webservice" returnQName="helloReturn" returnType="rtns:string" xmlns:rtns="http://www.w3.org/2001/XMLSchema" >

        <parameter name="in0" type="tns:string" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>

      </operation>

      <parameter name="allowedMethods" value="hello"/>

      <parameter name="scope" value="Application"/>

 

  </service>

</deployment>

 

 

서비스 디플로이먼트

java org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService deploy.wsdd

 

디플로이먼트 확인하기

http://localhost:8080/axis/servlet/AxisServlet

'Hello' 라는 서비스가 설치된것을 확인할 수 있다.

 

서비스 테스트하기

 

'web' 카테고리의 다른 글

Trust in E-commerce  (0) 2006.07.20
FTP의 passive, active mode 설명  (0) 2006.02.20
[펌] web.xml 사용법  (0) 2005.07.23
Tomcat 4.1.12 버전에서 서블릿 접근  (0) 2005.02.08
web.xml 설명.  (0) 2005.02.04
Posted by '김용환'
,