Salut tout le monde :
SVP, help
Le pb est que le fichier récuperé par le web service est erroné
je n'arrive pas à lire correctement le fichier reçu
ci-dessous les différentes étapes que j'ai suivi
Environnement,
Eclipse 3.4, jdk1.6, tomcat6 et axis2
1- creation d'un service web :
package com.test.business;
import java.io.Serializable;
import javax.activation.DataHandler;
import javax.xml.namespace.QName;
import org.apache.axiom.attachments.Attachments;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
public class AddInOutlookWS implements Serializable{
private static final long serialVersionUID = 1L;
private static IMiddleAddInOutlookWS middleAddInOutlookWS;
public boolean verifyUserByEMail(String email){
return middleAddInOutlookWS.verifyUserByEMail(email);
}
public int addInSafeDoc(AddInOutlook addInOutlook)throws Exception{
return middleAddInOutlookWS.addInSafeDoc(addInOutlook);
}
public static void setMiddleAddInOutlookWS(IMiddleAddInOutlookWS middleAddInOutlookWS) {
AddInOutlookWS.middleAddInOutlookWS = middleAddInOutlookWS;
}
public void uploadAttachment(OMElement omEle) throws AxisFault {
OMElement child = (OMElement) omEle.getFirstOMChild();
OMAttribute attr = child.getAttribute(new QName("href"));
//Content ID processing
String contentID = attr.getAttributeValue();
contentID = contentID.trim();
if (contentID.substring(0, 3).equalsIgnoreCase("cid")) {
contentID = contentID.substring(4);
}
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
Attachments attachment = msgCtx.getAttachmentMap();
DataHandler dataHandler = attachment.getDataHandler(contentID);
//traitement ....
}
}
2- création d'un objet :
public class AddInOutlook implements Serializable{
private static final long serialVersionUID = 1L;
private long id;
private String comment;
private Map<String,String> inputs;
//private File file;
private String fileFileName;
private String fileContentType;
private byte content[] = (byte[])null;
public AddInOutlook() {
}
// ......... getters / setters
}
3- Géneration de web service avec le plugin axis2 d'eclipse
4- déploiment du web service et géneration du WSDL : http://localhost:8080/sad/services/AddInOutlookWS?wsdl
<?xml version="1.0" encoding="UTF-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://business.bdocinteractive.bdoc.com" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:ax23="http://util.java/xsd" xmlns:ax21="http://business.bdocinteractive.bdoc.com/xsd" xmlnss="http://www.w3.org/2001/XMLSchema" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://business.bdocinteractive.bdoc.com">
<wsdl:documentation>Please Type your service description here</wsdl:documentation>
- <wsdl:types>
- <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://util.java/xsd">
- <xs:complexType name="Map">
- <xs:sequence>
<xs:element minOccurs="0" name="empty" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema xmlns:ax24="http://util.java/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://business.test.com/xsd">
<xs:import namespace="http://util.java/xsd" />
- <xs:complexType name="IMiddleAddInOutlookWS">
<xs:sequence />
</xs:complexType>
- <xs:complexType name="AddInOutlook">
- <xs:sequence>
<xs:element minOccurs="0" name="comment" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="content" nillable="true" type="xs:base64Binary" />
<xs:element minOccurs="0" name="fileContentType" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="fileFileName" nillable="true" type="xs:string" />
<xs:element minOccurs="0" name="id" type="xs:long" />
<xs:element minOccurs="0" name="inputs" nillable="true" type="ax24:Map" />
</xs:sequence>
</xs:complexType>
</xs:schema>
- <xs:schema xmlns:ax22="http://business.test.com/xsd" attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://business.test.com">
<xs:import namespace="http://business.test.com/xsd" />
- <xs:element name="verifyUserByEMail">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="email" nillable="true" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="verifyUserByEMailResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:complexType name="Exception">
- <xs:sequence>
<xs:element minOccurs="0" name="Exception" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
- <xs:element name="uploadAttachment">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="omEle" nillable="true" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="setMiddleAddInOutlookWS">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="middleAddInOutlookWS" nillable="true" type="ax22:IMiddleAddInOutlookWS" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="Exception">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="Exception" nillable="true" type="ns:Exception" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="addInSafeDoc">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="addInOutlook" nillable="true" type="ax22:AddInOutlook" />
</xs:sequence>
</xs:complexType>
</xs:element>
- <xs:element name="addInSafeDocResponse">
- <xs:complexType>
- <xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
</wsdl:types>
- <wsdl:message name="setMiddleAddInOutlookWSRequest">
<wsdl:part name="parameters" element="ns:setMiddleAddInOutlookWS" />
</wsdl:message>
- <wsdl:message name="verifyUserByEMailRequest">
<wsdl:part name="parameters" element="ns:verifyUserByEMail" />
</wsdl:message>
- <wsdl:message name="verifyUserByEMailResponse">
<wsdl:part name="parameters" element="ns:verifyUserByEMailResponse" />
</wsdl:message>
- <wsdl:message name="uploadAttachmentRequest">
<wsdl:part name="parameters" element="ns:uploadAttachment" />
</wsdl:message>
- <wsdl:message name="addInSafeDocRequest">
<wsdl:part name="parameters" element="ns:addInSafeDoc" />
</wsdl:message>
- <wsdl:message name="addInSafeDocResponse">
<wsdl:part name="parameters" element="ns:addInSafeDocResponse" />
</wsdl:message>
- <wsdl:message name="Exception">
<wsdl:part name="parameters" element="ns:Exception" />
</wsdl:message>
- <wsdl:portType name="AddInOutlookWSPortType">
- <wsdl:operation name="setMiddleAddInOutlookWS">
<wsdl:input message="ns:setMiddleAddInOutlookWSRequest" wsaw:Action="urn:setMiddleAddInOutlookWS" />
</wsdl:operation>
- <wsdl:operation name="verifyUserByEMail">
<wsdl:input message="ns:verifyUserByEMailRequest" wsaw:Action="urn:verifyUserByEMail" />
<wsdl:output message="ns:verifyUserByEMailResponse" wsaw:Action="urn:verifyUserByEMailResponse" />
</wsdl:operation>
- <wsdl:operation name="uploadAttachment">
<wsdl:input message="ns:uploadAttachmentRequest" wsaw:Action="urn:uploadAttachment" />
</wsdl:operation>
- <wsdl:operation name="addInSafeDoc">
<wsdl:input message="ns:addInSafeDocRequest" wsaw:Action="urn:addInSafeDoc" />
<wsdl:output message="ns:addInSafeDocResponse" wsaw:Action="urn:addInSafeDocResponse" />
<wsdl:fault message="ns:Exception" name="Exception" wsaw:Action="urn:addInSafeDocException" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="AddInOutlookWSSoap11Binding" type="ns:AddInOutlookWSPortType">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="setMiddleAddInOutlookWS">
<soap:operation soapAction="urn:setMiddleAddInOutlookWS" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="uploadAttachment">
<soap:operation soapAction="urn:uploadAttachment" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="verifyUserByEMail">
<soap:operation soapAction="urn:verifyUserByEMail" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="addInSafeDoc">
<soap:operation soapAction="urn:addInSafeDoc" style="document" />
- <wsdl:input>
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap:body use="literal" />
</wsdl:output>
- <wsdl:fault name="Exception">
<soap:fault use="literal" name="Exception" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="AddInOutlookWSSoap12Binding" type="ns:AddInOutlookWSPortType">
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <wsdl:operation name="setMiddleAddInOutlookWS">
<soap12:operation soapAction="urn:setMiddleAddInOutlookWS" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="uploadAttachment">
<soap12:operation soapAction="urn:uploadAttachment" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="verifyUserByEMail">
<soap12:operation soapAction="urn:verifyUserByEMail" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="addInSafeDoc">
<soap12:operation soapAction="urn:addInSafeDoc" style="document" />
- <wsdl:input>
<soap12:body use="literal" />
</wsdl:input>
- <wsdl:output>
<soap12:body use="literal" />
</wsdl:output>
- <wsdl:fault name="Exception">
<soap12:fault use="literal" name="Exception" />
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
- <wsdl:binding name="AddInOutlookWSHttpBinding" type="ns:AddInOutlookWSPortType">
<http:binding verb="POST" />
- <wsdl:operation name="setMiddleAddInOutlookWS">
<http:operation location="AddInOutlookWS/setMiddleAddInOutlookWS" />
- <wsdl:input>
<mime:content type="text/xml" part="setMiddleAddInOutlookWS" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="uploadAttachment">
<http:operation location="AddInOutlookWS/uploadAttachment" />
- <wsdl:input>
<mime:content type="text/xml" part="uploadAttachment" />
</wsdl:input>
</wsdl:operation>
- <wsdl:operation name="verifyUserByEMail">
<http:operation location="AddInOutlookWS/verifyUserByEMail" />
- <wsdl:input>
<mime:content type="text/xml" part="verifyUserByEMail" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="verifyUserByEMail" />
</wsdl:output>
</wsdl:operation>
- <wsdl:operation name="addInSafeDoc">
<http:operation location="AddInOutlookWS/addInSafeDoc" />
- <wsdl:input>
<mime:content type="text/xml" part="addInSafeDoc" />
</wsdl:input>
- <wsdl:output>
<mime:content type="text/xml" part="addInSafeDoc" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="AddInOutlookWS">
- <wsdl:port name="AddInOutlookWSHttpSoap11Endpoint" binding="ns:AddInOutlookWSSoap11Binding">
<soap:address location="http://localhost:8080/sad/services/AddInOutlookWS.AddInOutlookWSHttpSoap11Endpoint/" />
</wsdl:port>
- <wsdl:port name="AddInOutlookWSHttpSoap12Endpoint" binding="ns:AddInOutlookWSSoap12Binding">
<soap12:address location="http://localhost:8080/sad/services/AddInOutlookWS.AddInOutlookWSHttpSoap12Endpoint/" />
</wsdl:port>
- <wsdl:port name="AddInOutlookWSHttpEndpoint" binding="ns:AddInOutlookWSHttpBinding">
<http:address location="http://localhost:8080/sad/services/AddInOutlookWS.AddInOutlookWSHttpEndpoint/" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
5- géneration du stub avec la commande WSDL2JAVA
6- création du client :
public static void main(String[] args) throws Exception, ExceptionException {
AddInSafeDoc addInSafeDoc0 = new AddInSafeDoc();
AddInOutlookWSStub stub = new AddInOutlookWSStub();
AddInOutlook param = new AddInOutlook();
File file = new File("c:\\testWS.doc");
DataSource ds = new FileDataSource(file);
DataHandler dataHandler = new DataHandler(ds);
param.setContent(dataHandler );
param.setComment("commentaire ws ");
param.setFileContentType("application/msword");
param.setFileFileName("test ws .doc");
param.setId(1);
addInSafeDoc0.setAddInOutlook(param );
AddInSafeDocResponse resp = stub.addInSafeDoc(addInSafeDoc0 );
int i =resp.get_return();
System.out.println(i);
}
Partager