[메시지 스타일 서비스]
자바코드로의 매핑을 빼고 XML데이터 자체를 주고받는 서비스다.
D:/work>type MessageService.java
import org.w3c.dom.Element;
import javax.xml.soap.*;
public class MessageService{
public Element[] echoElements(Element[] elems){
return elems;
}
public void Process(SOAPEnvelope req, SOAPEnvelope res) throws javax.xml.soap.SOAPException{
SOAPBody body = res.getBody();
Name ns0 = res.createName("TestNS0", "ns0", http://aa.com);
Name ns1 = res.createName("TestNS1", "ns1", http://aa.com);
SOAPElement bodyElement = body.addBodyElement(ns0);
SOAPElement el = bodyElement.addChildElement(ns1);
el.addTextNode("TEST RESPONSE");
}
}
D:/work>javac MessageService.java
D:/work>copy MessageService.class "%CATALINA_HOME%/webapps/axis/WEB-INF/classes"
1개 파일이 복사되었습니다.
D:/work>type deploy.wsdd
<deployment name="test" xmlns=http://xml.apache.org/axis/wsdd/
xmlns:java=http://xml.apache.org/axis/wsdd/providers/java
xmlns:xsi="http://www.w3c.org/2000/10/XMLSchema-instance">
//주석 : note that either style="message" OR provider="java:MSG" both work
<service name="MessageService" style="message">
<parameter name="className" value="MessageService" />
<parameter name="allowedMethods" value="echoElements" />
</service>
<service name="MessageService2" style="message">
<parameter name="className" value="MessageService" />
<parameter name="allowedMethods" value="process" />
</service>
</deployment>
D:/work>type undeploy.wsdd
<undeploytment name="test" xmlns="http://xml.apache.org/axis/wsdd/">
<service name="MessageService" />
</undeployment>
D:/work>java org.apache.axis.client.AdminClient deploy.wsdd
log4j : WARN No appenders could be found for logger(org.apache.axis.i18n.ProjectResourceBundle).
log4j : WARN Please initialize the log4j system property.
Processing file deploy.wsdd
<Admin>Done processing</Admin>
D:/work>java org.apache.axis.client.AdminClient list
D:/work>jaba org.apache.axis.client.AdminClient list
log4j : WARN No appenders could be found for logger(org.apache.axis.i18n.ProjectResourceBundle).
log4j : WARN Please initialize the log4j system property.
<ns1:deployment xmlns=http://xml.apache.org/axis/wsdd/
xmlns:java=http://xml.apache.org/axis/wsdd/providers/java
xmlns:ns1="http://xml.apache.org/axis/wsdd/">
<ns1:globalConfiguration>
<ns1:parameter name="sendMultiRefs" value="true" />
<ns1:parameter name="disablePrettyXML" value="true" />
<ns1:parameter name="adminPassword" value="admin" />
<ns1:parameter name="attachments.Directory" value="E:/Program Files/Apache Software Foundation.Tomcat5.5/webapps/axis/WEB-INF/arrachments" />
<ns1:parameter name="dotNetSoapEncFix" value="true" />
<ns1:parameter name="enableNamespacePrefixOptimization" value="false" />
<ns1:parameter name="sendXsiTypes" value="true" />
<ns1:parameter name="attachments.implementation" value="org.apache.axis.attachments.AttachmentsImpl" />
<ns1:requestFlow>
<ns1:handler type="java:org.apache.axis.handlers.JWSHandler">
<ns1:parameter name="scope" value="session" />
</ns1:handler>
<ns1:handler type="java:org.apache.axis.handlers.JWSHandler">
<ns1:parameter name="scope" value="request" />
<ns1:parameter name="extension" value=".jwr" />
</ns1:handler>
</ns1:requestFlow>
</ns1:globalConfiguration>
<ns1:handler name="LocalResponder" type="java:org.apache.axis.transport.local.LocalResponder" />
<ns1:handler name="URLMapper" type="java:org.apache.axis.handlers.http.URLMapper" />
<ns1:handler name="Authenticate" type"java:org.apache.axis.handlers.SimpleAuthenticationHAndler" />
<ns1:service name="MessageService2" provider="java:MSG" style="message" use="literal">
<ns1:parameter name="allowedMethods" value="process" />
<ns1:parameter name="className" value="MessageService" />
<ns1:parameter name="sendXsiTypes" value="false" />
<ns1:parameter name="sendMultiRefs" value="false" />
</ns1:service>
<ns1:service name="MessageService" provider="java:MSG" style="message" use="literal">
<ns1:parameter name="allowedMethods" value="echoElements" />
<ns1:parameter name="className" value="MessageService" />
<ns1:parameter name="sendXsiTypes" value="false" />
<ns1:parameter name="sendMultiRefs" value="false" />
</ns1:service>
<ns1:service name="AdminService" provider="java:MSG">
<ns1:parameter name="allowedMethods" value="AdminService" />
<ns1:parameter name="enableRemoteAdmin" value="false" />
<ns1:parameter name="className" value="org.apache.axis.utils.Admin" />
<ns1:namespace>http://xml.apache.org/axis/wsdd/</ns1:namespace>
</ns1:service>
<ns1:service name="Version" provider="java:RPC">
<ns1:parameter name="allowedMethods" value="getVersion" />
<ns1:parameter name="className" value="org.apache.axis.Version" />
</ns1:service>
<ns1:transport name="http">
<ns1:requestFlow>
<ns1:handler type="URLMapper" />
<ns1:handler type="java:org.apache.axis.handlers.http.HTTPAuthHandler" />
</ns1:requestFlow>
<ns1:parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler" />
<ns1:parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" />
<ns1:parameter name="qs:list" value="org.apache.axis.transport.http.QSListHandler" />
<ns1:parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler" />
<ns1:parameter name="qs:method" value="org.apache.axis.transport.http.QSMethodHandler" />
<ns1:parameter name="qs:wsdl" value="org.apache.axis.transport.http.QSWSDLHandler" />
</ns1:transport>
<ns1:transport name="local">
<ns1:responseFlow>
<ns1:handler type="LocalResponder" />
</ns1:responseFlow>
</ns1:transport>
</ns1:deployment>
[클라이언트로 서비스 테스트]
D:/work>javac TestMsg.java
D:/work>java TestMsg
log4j : WARN No appenders could be found for logger(org.apache.axis.i18n.ProjectResourceBundle).
log4j : WARN Please initialize the log4j system property.
D:/work>type TestMsg.java
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.utils.Options;
import org.apache.axis.Utils.XMLUtils;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPEnvelope;
import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;
import java.io.ByteArrayInputStream;
import java.net.URL;
import java.util.Vector;
//주석 : Simple test driver for our message service.
public class TestMsg{
public String doit(String[] args) throws Exception{
Optionsopts = new Options(args);
opts.setDefaultURL(http://localhost:8080/axis/service/MessageService);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new URL(opts.getURL()));
SOAPBodyElement[] input = new SOAPBodyElement[3];
input[0] = new SOAPBodyElement(XMLUtils.,StringToElement("urn:foo", "e1", "Hello"));
input[1] = new SOAPBodyElement(XMLUtils.,StringToElement("urn:foo", "e1", "World"));
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocunebtBuilder();
Document doc = builder.newDocument();
Element cdataElem = doc.createElementNS("urn:foo", "e3");
CDATASection cdata = doc.createCDATASection("Text with/n/t Important <b> witespace</b> and tags!");
cdataElem.appendChild(cdata);
input[2] = new SOAPBodyElement(cdataElem);
Vector elems = (Cevtor)call.invoke(input);
SOAPBodyElement elem = null;
Element e = null;
elem = (SOAPBodyElement) elems.get(0);
e = elem.getAsDOM();
String srt = "Reselem[0]=" + XMLUtils.ElementToString(e);
elem = (SOAPBodyElement) elems.get(1);
e = elem.getAsDOM();
str = str + "Reselem[1]=" + XMLUtils.ElementToString(e);
e = elem.getAsDOM();
str = str + "Reselem[2]=" + XMLUtils.ElementToString(e);
return(str);
}
public void testEnvelope(String[] args) throws Exception{
String xmlString =
"<?xml version=/"1.0/" encoding=/"UTF-8/"?>/n"+
"<soapenv:Envelope xmlns:soapenv=/"http://schemas.xmlsoap.org/soap/envelope//"/n+
"xmlns:xsd=/"http://www.w3.org/2001/XMLSchema/"/n"+
"xmlns:xsi=/"http://www.w3.org/2001/XMLSchema-instance/">/n"+
"<soapenv:Header>/n"+
"<shw:Hello xmlns:shw=/"http://localhost:8080/axis/services/MessageService/">/n"+
"<shw:Myname>Tony</shw:Myname>/n"+
"</shw:Hello>/n"+
"</soapenv:Header>/n"+
"<soapenv:Body>/n"+
[출처] AXIS 설피 & 사용법 3/4|작성자 희열