- - PR -
AXIS DIMEによる添付ファイルの送信
投稿者 | 投稿内容 | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
投稿日時: 2004-08-18 00:48
中込です。
クライアント側から、以下のようにwrapped型のリクエストを送信しています。
しかし、サーバでは目的のサービスをrpc型として配備しています。
サーバはリクエストのオペレーションをrpc型として解釈しようとするため、 javaメソッドにマップできないのです。
| ||||||||||||
|
投稿日時: 2004-08-30 10:41
お世話になります。
中込さん、大変参考になるコメント ありがとうございます。 クライアント(Axis)⇔サーバ(Axis)の環境で、 サーバ側のパラメータにDataHandler型を使用しないで ファイルを添付する方法を実現できました。 ##### クライアント側 ###### mport org.apache.axis.attachments.AttachmentPart; import org.apache.axis.client.Call; import org.apache.axis.client.Service; import org.apache.axis.encoding.XMLType; import javax.xml.rpc.ParameterMode; import javax.xml.namespace.QName; import java.net.URL; import javax.activation.DataHandler; import javax.activation.FileDataSource; public class DimeClientTest { public static void main(String[] args) { Service service = null; Call call = null; String fileName = args[1]; try { service = new Service(); call = (Call)service.createCall(); call.setTargetEndpointAddress(new URL(args[0])); call.setOperationName(new QName("DimeService ", "hello")); call.addParameter("msg", XMLType.XSD_STRING, ParameterMode.IN); call.setReturnType(XMLType.XSD_BOOLEAN); /* SOAPメッセージに添付ファイルを付加しているところ */ call.setProperty(Call.ATTACHMENT_ENCAPSULATION_FORMAT, Call.ATTACHMENT_ENCAPSULATION_FORMAT_MIME); AttachmentPart ap = new AttachmentPart(new DataHandler (new FileDataSource(fileName))); ap.setContentType("image"); call.addAttachmentPart(ap); Object ret = call.invoke(new Object[]{fileName}); } catch (Exception e) { e.printStackTrace(); } } } ##### サーバ側 ###### import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import javax.xml.soap.SOAPException; import org.apache.axis.Message; import org.apache.axis.MessageContext; import org.apache.axis.attachments.AttachmentPart; public class DimeService { String filePass = "C:\\Files\\"; public boolean hello(String fileName){ MessageContext ctx = MessageContext.getCurrentContext(); Message message = ctx.getRequestMessage(); AttachmentPart part = (AttachmentPart)message.getAttachments().next(); FileOutputStream fs = null; try { fs = new FileOutputStream(filePass + fileName); part.getDataHandler().writeTo(fs); fs.close(); return true; } } ##### WSDDファイル ###### <?xml version='1.0' encoding='utf-8'?> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java" xmlns:ns1="DimeService " > <service name="DimeService " provider="java:RPC" > <parameter name="className" value="simpleAttachments.DimeService "/> <parameter name="allowedMethods" value="hello"/> <typeMapping languageSpecificType="java:javax.activation.DataHandler" qname="ns1:DataHandler" deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory" serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> </service> </deployment> |