You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Jim Collins <ja...@blueyonder.co.uk> on 2006/05/21 11:57:55 UTC
SWA Interoperability problem
Hi All,
I am hoping someone can help me with a problem that is driving me mad. I wrote a simple Webservice for uploading and retrieving files from a content management system. This worked fine with Java clients but when .NET users tried to use it they had problems generating a proxy from the WSDL. I have looked at the WS-I documentation and based on a WSDL example I found I ran WSDL to Java. Below is the WSDL file I used:
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:types="http://example.com/mimetypes"
xmlns:ref="http://ws-i.org/profiles/basic/1.1/xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
targetNamespace="http://example.com/mimewsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://example.com/mimewsdl">
<wsdl:types>
<xsd:schema targetNamespace="http://example.com/mimetypes"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://ws-i.org/profiles/basic/1.1/xsd" />
<xsd:element name="ClaimDetail" type="types:ClaimDetailType"/>
<simpleType name="swaRef">
<xsd:restriction base="xsd:anyURI" />
</simpleType>
<xsd:complexType name="ClaimDetailType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="ClaimPhoto" type="types:swaRef"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ClaimRefNo" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ClaimIn">
<wsdl:part name="body" element="types:ClaimDetail"/>
</wsdl:message>
<wsdl:message name="ClaimOut">
<wsdl:part name="out" element="types:ClaimRefNo"/>
</wsdl:message>
<wsdl:portType name="ClaimPortType">
<wsdl:operation name="SendClaim">
<wsdl:input message="tns:ClaimIn"/>
<wsdl:output message="tns:ClaimOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ClaimBinding" type="tns:ClaimPortType">
<soapbind:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SendClaim">
<soapbind:operation soapAction="http://example.com/soapaction"/>
<wsdl:input>
<mime:multipartRelated>
<mime:part>
<soapbind:body parts="body" use="literal"/>
</mime:part>
</mime:multipartRelated>
</wsdl:input>
<wsdl:output>
<soapbind:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ClaimSvc">
<wsdl:port name="ClaimPort" binding="tns:ClaimBinding">
<soap12:address location="http://localhost:9090/axis/services/claimSvc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This generated the following classes for the types I use:
/**
* ClaimDetailType.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimetypes;
public class ClaimDetailType implements java.io.Serializable {
private java.lang.String name;
private com.example.mimetypes.SwaRef claimPhoto;
public ClaimDetailType() {
}
public ClaimDetailType(
java.lang.String name,
com.example.mimetypes.SwaRef claimPhoto) {
this.name = name;
this.claimPhoto = claimPhoto;
}
/**
* Gets the name value for this ClaimDetailType.
*
* @return name
*/
public java.lang.String getName() {
return name;
}
/**
* Sets the name value for this ClaimDetailType.
*
* @param name
*/
public void setName(java.lang.String name) {
this.name = name;
}
/**
* Gets the claimPhoto value for this ClaimDetailType.
*
* @return claimPhoto
*/
public com.example.mimetypes.SwaRef getClaimPhoto() {
return claimPhoto;
}
/**
* Sets the claimPhoto value for this ClaimDetailType.
*
* @param claimPhoto
*/
public void setClaimPhoto(com.example.mimetypes.SwaRef claimPhoto) {
this.claimPhoto = claimPhoto;
}
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof ClaimDetailType)) return false;
ClaimDetailType other = (ClaimDetailType) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true &&
((this.name==null && other.getName()==null) ||
(this.name!=null &&
this.name.equals(other.getName()))) &&
((this.claimPhoto==null && other.getClaimPhoto()==null) ||
(this.claimPhoto!=null &&
this.claimPhoto.equals(other.getClaimPhoto())));
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
if (getName() != null) {
_hashCode += getName().hashCode();
}
if (getClaimPhoto() != null) {
_hashCode += getClaimPhoto().hashCode();
}
__hashCodeCalc = false;
return _hashCode;
}
// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
new org.apache.axis.description.TypeDesc(ClaimDetailType.class, true);
static {
typeDesc.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes", "ClaimDetailType"));
org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("name");
elemField.setXmlName(new javax.xml.namespace.QName("", "Name"));
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
elemField.setNillable(false);
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("claimPhoto");
elemField.setXmlName(new javax.xml.namespace.QName("", "ClaimPhoto"));
elemField.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes", "swaRef"));
elemField.setNillable(false);
typeDesc.addFieldDesc(elemField);
}
/**
* Return type metadata object
*/
public static org.apache.axis.description.TypeDesc getTypeDesc() {
return typeDesc;
}
/**
* Get Custom Serializer
*/
public static org.apache.axis.encoding.Serializer getSerializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanSerializer(
_javaType, _xmlType, typeDesc);
}
/**
* Get Custom Deserializer
*/
public static org.apache.axis.encoding.Deserializer getDeserializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanDeserializer(
_javaType, _xmlType, typeDesc);
}
}
/**
* SwaRef.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimetypes;
public class SwaRef implements java.io.Serializable {
public SwaRef() {
}
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof SwaRef)) return false;
SwaRef other = (SwaRef) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true;
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
__hashCodeCalc = false;
return _hashCode;
}
// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
new org.apache.axis.description.TypeDesc(SwaRef.class, true);
static {
typeDesc.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes", "swaRef"));
}
/**
* Return type metadata object
*/
public static org.apache.axis.description.TypeDesc getTypeDesc() {
return typeDesc;
}
/**
* Get Custom Serializer
*/
public static org.apache.axis.encoding.Serializer getSerializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanSerializer(
_javaType, _xmlType, typeDesc);
}
/**
* Get Custom Deserializer
*/
public static org.apache.axis.encoding.Deserializer getDeserializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanDeserializer(
_javaType, _xmlType, typeDesc);
}
}
The server side implementation that WSDL2Java generates is:
/**
* ClaimBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimewsdl;
public class ClaimBindingImpl implements com.example.mimewsdl.ClaimPortType{
public java.lang.String sendClaim(com.example.mimetypes.ClaimDetailType body) throws java.rmi.RemoteException {
return null;
}
}
The problem I have is that I do not have a clue how to use the SwaRef.java class. I have written a test client that can send files to the service the code is below:
package samples.swa;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
import org.apache.axis.SOAPPart;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPHeader;
import org.apache.axis.soap.SOAPFactoryImpl;
import org.apache.axis.soap.MessageFactoryImpl;
import org.soapinterop.mtom_test.AttachmentsPortType;
import org.soapinterop.mtom_test.MtomTestDocSvcLocator;
import org.soapinterop.mtom_test.types.Data;
import org.soapinterop.mtom_test.types.PO;
import com.example.mimetypes.ClaimDetailType;
import com.example.mimetypes.SwaRef;
import com.example.mimewsdl.ClaimPortType;
import com.example.mimewsdl.ClaimSvcLocator;
/**
* Class Tester
*
*/
public class Tester {
/** Field HEADER_CONTENT_TYPE */
public static final String HEADER_CONTENT_TYPE = "Content-Type";
/** Field HEADER_CONTENT_TRANSFER_ENCODING */
public static final String HEADER_CONTENT_TRANSFER_ENCODING =
"Content-Transfer-Encoding";
/** Field address */
private static final java.lang.String address =
"http://localhost:9090/axis/services/ClaimPort";
/**
* Method main
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
java.net.URL endpoint;
try {
endpoint = new java.net.URL(address);
} catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
}
SOAPConnectionFactory factory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection = factory.createConnection();
SOAPMessage request = null;
MessageFactoryImpl mf = new MessageFactoryImpl();
request = mf.createMessage();
SOAPPart soapPart = (SOAPPart) request.getSOAPPart();
SOAPEnvelope envelope = (SOAPEnvelope) soapPart.getEnvelope();
SOAPHeader header = (SOAPHeader) envelope.getHeader();
SOAPBody body = envelope.getBody();
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
Name bodyName = soapFactory.createName("ClaimDetail",
"m", "http://example.com/mimetypes");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("Name");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("Bobby Test");
Name photo = soapFactory.createName("ClaimPhoto");
symbol = bodyElement.addChildElement(photo);
symbol.addTextNode("thephoto");
URL url = new URL("file:///myDoc.doc");
javax.xml.soap.AttachmentPart att = request.createAttachmentPart();
att.setDataHandler(dataHandler);
att.setContentId("thephoto");
att.setContentType("application/octet-stream");
javax.xml.soap.AttachmentPart att2 = request.createAttachmentPart();
att2.setContentId("thephoto");
byte[] data = getBytesFromFile(new File("C:/WebtopIssues.doc"));
att2.setContent(new ByteArrayInputStream(data), "application/octet-stream");
request.addAttachmentPart(att2);
SOAPMessage response = connection.call(request, endpoint);
connection.close();
}
// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
}
I had problems using a DataHandler it threw exceptions and I was not sure how to use the generated Port type. I realise that this is a long message but would appreciate any help.
Many thanks
Jim
Re: SWA Interoperability problem
Posted by Jim Collins <ja...@blueyonder.co.uk>.
Hi Anne,
Thanks for the feedback. Just out of interest do you know how I would use SwaRef class from a Java client. Also do you have any examples of a WSDL file for a MTOM service. I deployed the MTOM example from Axis2 and it does not generate a WSDL file. I have had a look around the net but could not find any examples. I have tried the WSDL2Java ant task with Axis2 but I get a com.bea.xml.stream.MXParserFactory error even though this class is in a jar file on the classpath.
Regards
Jim
----- Original Message -----
From: Anne Thomas Manes
To: axis-user@ws.apache.org
Sent: Monday, May 22, 2006 1:47 PM
Subject: Re: SWA Interoperability problem
.NET does not support SOAP with Attachments. You must use either DIME (Axis1 and WSE 3.0) or MTOM (Axis2 and WSE 3.0 or WCF).
Anne
On 5/21/06, Jim Collins <ja...@blueyonder.co.uk> wrote:
Hi All,
I am hoping someone can help me with a problem that is driving me mad. I wrote a simple Webservice for uploading and retrieving files from a content management system. This worked fine with Java clients but when .NET users tried to use it they had problems generating a proxy from the WSDL. I have looked at the WS-I documentation and based on a WSDL example I found I ran WSDL to Java. Below is the WSDL file I used:
<?xml version="1.0" encoding="utf-8" ?>
<wsdl:definitions xmlns:types="http://example.com/mimetypes "
xmlns:ref="http://ws-i.org/profiles/basic/1.1/xsd "
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/ "
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/ "
targetNamespace="http://example.com/mimewsdl"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:tns="http://example.com/mimewsdl">
<wsdl:types>
<xsd:schema targetNamespace="http://example.com/mimetypes"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://ws-i.org/profiles/basic/1.1/xsd" />
<xsd:element name="ClaimDetail" type="types:ClaimDetailType"/>
<simpleType name="swaRef">
<xsd:restriction base="xsd:anyURI" />
</simpleType>
<xsd:complexType name="ClaimDetailType">
<xsd:sequence>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="ClaimPhoto" type="types:swaRef"/>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="ClaimRefNo" type="xsd:string"/>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ClaimIn">
<wsdl:part name="body" element="types:ClaimDetail"/>
</wsdl:message>
<wsdl:message name="ClaimOut">
<wsdl:part name="out" element="types:ClaimRefNo"/>
</wsdl:message>
<wsdl:portType name="ClaimPortType">
<wsdl:operation name="SendClaim">
<wsdl:input message="tns:ClaimIn"/>
<wsdl:output message="tns:ClaimOut"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ClaimBinding" type="tns:ClaimPortType">
<soapbind:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="SendClaim">
<soapbind:operation soapAction="http://example.com/soapaction"/>
<wsdl:input>
<mime:multipartRelated>
<mime:part>
<soapbind:body parts="body" use="literal"/>
</mime:part>
</mime:multipartRelated>
</wsdl:input>
<wsdl:output>
<soapbind:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ClaimSvc">
<wsdl:port name="ClaimPort" binding="tns:ClaimBinding">
<soap12:address location="http://localhost:9090/axis/services/claimSvc" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
This generated the following classes for the types I use:
/**
* ClaimDetailType.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimetypes;
public class ClaimDetailType implements java.io.Serializable {
private java.lang.String name;
private com.example.mimetypes.SwaRef claimPhoto;
public ClaimDetailType() {
}
public ClaimDetailType(
java.lang.String name,
com.example.mimetypes.SwaRef claimPhoto) {
this.name = name;
this.claimPhoto = claimPhoto;
}
/**
* Gets the name value for this ClaimDetailType.
*
* @return name
*/
public java.lang.String getName() {
return name;
}
/**
* Sets the name value for this ClaimDetailType.
*
* @param name
*/
public void setName(java.lang.String name) {
this.name = name;
}
/**
* Gets the claimPhoto value for this ClaimDetailType.
*
* @return claimPhoto
*/
public com.example.mimetypes.SwaRef getClaimPhoto() {
return claimPhoto;
}
/**
* Sets the claimPhoto value for this ClaimDetailType.
*
* @param claimPhoto
*/
public void setClaimPhoto(com.example.mimetypes.SwaRef claimPhoto) {
this.claimPhoto = claimPhoto;
}
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof ClaimDetailType)) return false;
ClaimDetailType other = (ClaimDetailType) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true &&
((this.name==null && other.getName()==null) ||
(this.name!=null &&
this.name.equals(other.getName()))) &&
((this.claimPhoto==null && other.getClaimPhoto()==null) ||
(this.claimPhoto!=null &&
this.claimPhoto.equals(other.getClaimPhoto())));
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
if (getName() != null) {
_hashCode += getName().hashCode();
}
if (getClaimPhoto() != null) {
_hashCode += getClaimPhoto().hashCode();
}
__hashCodeCalc = false;
return _hashCode;
}
// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
new org.apache.axis.description.TypeDesc(ClaimDetailType.class, true);
static {
typeDesc.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes ", "ClaimDetailType"));
org.apache.axis.description.ElementDesc elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("name");
elemField.setXmlName(new javax.xml.namespace.QName("", "Name"));
elemField.setXmlType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema ", "string"));
elemField.setNillable(false);
typeDesc.addFieldDesc(elemField);
elemField = new org.apache.axis.description.ElementDesc();
elemField.setFieldName("claimPhoto");
elemField.setXmlName(new javax.xml.namespace.QName("", "ClaimPhoto"));
elemField.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes ", "swaRef"));
elemField.setNillable(false);
typeDesc.addFieldDesc(elemField);
}
/**
* Return type metadata object
*/
public static org.apache.axis.description.TypeDesc getTypeDesc() {
return typeDesc;
}
/**
* Get Custom Serializer
*/
public static org.apache.axis.encoding.Serializer getSerializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanSerializer(
_javaType, _xmlType, typeDesc);
}
/**
* Get Custom Deserializer
*/
public static org.apache.axis.encoding.Deserializer getDeserializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanDeserializer(
_javaType, _xmlType, typeDesc);
}
}
/**
* SwaRef.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimetypes;
public class SwaRef implements java.io.Serializable {
public SwaRef() {
}
private java.lang.Object __equalsCalc = null;
public synchronized boolean equals(java.lang.Object obj) {
if (!(obj instanceof SwaRef)) return false;
SwaRef other = (SwaRef) obj;
if (obj == null) return false;
if (this == obj) return true;
if (__equalsCalc != null) {
return (__equalsCalc == obj);
}
__equalsCalc = obj;
boolean _equals;
_equals = true;
__equalsCalc = null;
return _equals;
}
private boolean __hashCodeCalc = false;
public synchronized int hashCode() {
if (__hashCodeCalc) {
return 0;
}
__hashCodeCalc = true;
int _hashCode = 1;
__hashCodeCalc = false;
return _hashCode;
}
// Type metadata
private static org.apache.axis.description.TypeDesc typeDesc =
new org.apache.axis.description.TypeDesc(SwaRef.class, true);
static {
typeDesc.setXmlType(new javax.xml.namespace.QName("http://example.com/mimetypes ", "swaRef"));
}
/**
* Return type metadata object
*/
public static org.apache.axis.description.TypeDesc getTypeDesc() {
return typeDesc;
}
/**
* Get Custom Serializer
*/
public static org.apache.axis.encoding.Serializer getSerializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanSerializer(
_javaType, _xmlType, typeDesc);
}
/**
* Get Custom Deserializer
*/
public static org.apache.axis.encoding.Deserializer getDeserializer(
java.lang.String mechType,
java.lang.Class _javaType,
javax.xml.namespace.QName _xmlType) {
return
new org.apache.axis.encoding.ser.BeanDeserializer(
_javaType, _xmlType, typeDesc);
}
}
The server side implementation that WSDL2Java generates is:
/**
* ClaimBindingImpl.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
*/
package com.example.mimewsdl;
public class ClaimBindingImpl implements com.example.mimewsdl.ClaimPortType{
public java.lang.String sendClaim(com.example.mimetypes.ClaimDetailType body) throws java.rmi.RemoteException {
return null;
}
}
The problem I have is that I do not have a clue how to use the SwaRef.java class. I have written a test client that can send files to the service the code is below:
package samples.swa;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import javax.activation.DataHandler;
import javax.activation.FileDataSource;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.xml.soap.Name;
import javax.xml.soap.SOAPBody;
import javax.xml.soap.SOAPBodyElement;
import javax.xml.soap.SOAPConnection;
import javax.xml.soap.SOAPConnectionFactory;
import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPMessage;
import org.apache.axis.SOAPPart;
import org.apache.axis.attachments.AttachmentPart;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.message.SOAPHeader;
import org.apache.axis.soap.SOAPFactoryImpl;
import org.apache.axis.soap.MessageFactoryImpl;
import org.soapinterop.mtom_test.AttachmentsPortType;
import org.soapinterop.mtom_test.MtomTestDocSvcLocator;
import org.soapinterop.mtom_test.types.Data;
import org.soapinterop.mtom_test.types.PO;
import com.example.mimetypes.ClaimDetailType;
import com.example.mimetypes.SwaRef;
import com.example.mimewsdl.ClaimPortType;
import com.example.mimewsdl.ClaimSvcLocator;
/**
* Class Tester
*
*/
public class Tester {
/** Field HEADER_CONTENT_TYPE */
public static final String HEADER_CONTENT_TYPE = "Content-Type";
/** Field HEADER_CONTENT_TRANSFER_ENCODING */
public static final String HEADER_CONTENT_TRANSFER_ENCODING =
"Content-Transfer-Encoding";
/** Field address */
private static final java.lang.String address =
"http://localhost:9090/axis/services/ClaimPort ";
/**
* Method main
*
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
java.net.URL endpoint;
try {
endpoint = new java.net.URL(address);
} catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
}
SOAPConnectionFactory factory =
SOAPConnectionFactory.newInstance();
SOAPConnection connection = factory.createConnection();
SOAPMessage request = null;
MessageFactoryImpl mf = new MessageFactoryImpl();
request = mf.createMessage();
SOAPPart soapPart = (SOAPPart) request.getSOAPPart();
SOAPEnvelope envelope = (SOAPEnvelope) soapPart.getEnvelope();
SOAPHeader header = (SOAPHeader) envelope.getHeader();
SOAPBody body = envelope.getBody();
SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
Name bodyName = soapFactory.createName("ClaimDetail",
"m", "http://example.com/mimetypes ");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
Name name = soapFactory.createName("Name");
SOAPElement symbol = bodyElement.addChildElement(name);
symbol.addTextNode("Bobby Test");
Name photo = soapFactory.createName("ClaimPhoto");
symbol = bodyElement.addChildElement(photo);
symbol.addTextNode("thephoto");
URL url = new URL("file:///myDoc.doc");
javax.xml.soap.AttachmentPart att = request.createAttachmentPart();
att.setDataHandler(dataHandler);
att.setContentId("thephoto");
att.setContentType("application/octet-stream");
javax.xml.soap.AttachmentPart att2 = request.createAttachmentPart();
att2.setContentId("thephoto");
byte[] data = getBytesFromFile(new File("C:/WebtopIssues.doc"));
att2.setContent(new ByteArrayInputStream(data), "application/octet-stream");
request.addAttachmentPart(att2);
SOAPMessage response = connection.call(request, endpoint);
connection.close();
}
// Returns the contents of the file in a byte array.
public static byte[] getBytesFromFile(File file) throws IOException {
InputStream is = new FileInputStream(file);
// Get the size of the file
long length = file.length();
// You cannot create an array using a long type.
// It needs to be an int type.
// Before converting to an int type, check
// to ensure that file is not larger than Integer.MAX_VALUE.
if (length > Integer.MAX_VALUE) {
// File is too large
}
// Create the byte array to hold the data
byte[] bytes = new byte[(int)length];
// Read in the bytes
int offset = 0;
int numRead = 0;
while (offset < bytes.length
&& (numRead=is.read(bytes, offset, bytes.length-offset)) >= 0) {
offset += numRead;
}
// Ensure all the bytes have been read in
if (offset < bytes.length) {
throw new IOException("Could not completely read file "+file.getName());
}
// Close the input stream and return bytes
is.close();
return bytes;
}
}
I had problems using a DataHandler it threw exceptions and I was not sure how to use the generated Port type. I realise that this is a long message but would appreciate any help.
Many thanks
Jim
Re: SWA Interoperability problem
Posted by Anne Thomas Manes <at...@gmail.com>.
.NET does not support SOAP with Attachments. You must use either DIME (Axis1
and WSE 3.0) or MTOM (Axis2 and WSE 3.0 or WCF).
Anne
On 5/21/06, Jim Collins <ja...@blueyonder.co.uk> wrote:
>
> Hi All,
>
> I am hoping someone can help me with a problem that is driving me mad. I
> wrote a simple Webservice for uploading and retrieving files from a content
> management system. This worked fine with Java clients but when .NET users
> tried to use it they had problems generating a proxy from the WSDL. I have
> looked at the WS-I documentation and based on a WSDL example I found I ran
> WSDL to Java. Below is the WSDL file I used:
>
>
> *<?xml version="1.0" encoding="utf-8" ?>*
>
> *<wsdl:definitions xmlns:types="http://example.com/mimetypes"*
>
> * xmlns:ref="http://ws-i.org/profiles/basic/1.1/xsd"*
>
> * xmlns:xsd="http://www.w3.org/2001/XMLSchema"*
>
> * xmlns:soapbind="http://schemas.xmlsoap.org/wsdl/soap/"*
>
> * xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"*
>
> * xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"*
>
> * targetNamespace="http://example.com/mimewsdl"*
>
> * xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" *
>
> * xmlns:tns="http://example.com/mimewsdl">*
>
> * <wsdl:types>*
>
> * <xsd:schema targetNamespace="http://example.com/mimetypes"*
>
> * xmlns:xsd="http://www.w3.org/2001/XMLSchema">*
>
> * <xsd:import namespace="http://ws-i.org/profiles/basic/1.1/xsd" />
> *
>
> * <xsd:element name="ClaimDetail" type="types:ClaimDetailType"/>*
>
> **
>
> * <simpleType name="swaRef">*
>
> * <xsd:restriction base="xsd:anyURI" /> *
>
> * </simpleType>*
>
> **
>
> **
>
> * <xsd:complexType name="ClaimDetailType">*
>
> * <xsd:sequence>*
>
> * <xsd:element name="Name" type="xsd:string"/>*
>
> * <xsd:element name="ClaimPhoto" type="types:swaRef"/>*
>
> * </xsd:sequence>*
>
> * </xsd:complexType>*
>
> * <xsd:element name="ClaimRefNo" type="xsd:string"/>*
>
> * </xsd:schema>*
>
> * </wsdl:types>*
>
> * <wsdl:message name="ClaimIn">*
>
> * <wsdl:part name="body" element="types:ClaimDetail"/>*
>
> * </wsdl:message>*
>
> * <wsdl:message name="ClaimOut">*
>
> * <wsdl:part name="out" element="types:ClaimRefNo"/>*
>
> * </wsdl:message>*
>
> * <wsdl:portType name="ClaimPortType">*
>
> * <wsdl:operation name="SendClaim">*
>
> * <wsdl:input message="tns:ClaimIn"/>*
>
> * <wsdl:output message="tns:ClaimOut"/>*
>
> * </wsdl:operation>*
>
> * </wsdl:portType>*
>
> * <wsdl:binding name="ClaimBinding" type="tns:ClaimPortType">*
>
> * <soapbind:binding style="document"*
>
> * transport="http://schemas.xmlsoap.org/soap/http"/>*
>
> * <wsdl:operation name="SendClaim">*
>
> * <soapbind:operation soapAction="http://example.com/soapaction
> "/>*
>
> * <wsdl:input>*
>
> * <mime:multipartRelated>*
>
> * <mime:part>*
>
> * <soapbind:body parts="body" use="literal"/>*
>
> * </mime:part>*
>
> * </mime:multipartRelated>*
>
> * </wsdl:input>*
>
> * <wsdl:output>*
>
> * <soapbind:body use="literal" />*
>
> * </wsdl:output>*
>
> * </wsdl:operation>*
>
> * </wsdl:binding>*
>
> **
>
> * <wsdl:service name="ClaimSvc">*
>
> * <wsdl:port name="ClaimPort" binding="tns:ClaimBinding">*
>
> * <soap12:address location="
> http://localhost:9090/axis/services/claimSvc" /> *
>
> * </wsdl:port>*
>
> * </wsdl:service>*
>
> **
>
> **
>
> *</wsdl:definitions>*
>
> This generated the following classes for the types I use:
>
>
>
> */**
> * ClaimDetailType.java
> *
> * This file was auto-generated from WSDL
> * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
> */*
>
> *package com.example.mimetypes;*
>
> *public class ClaimDetailType implements java.io.Serializable {
> private java.lang.String name;*
>
> * private com.example.mimetypes.SwaRef claimPhoto;*
>
> * public ClaimDetailType() {
> }*
>
> * public ClaimDetailType(
> java.lang.String name,
> com.example.mimetypes.SwaRef claimPhoto) {
> this.name = name;
> this.claimPhoto = claimPhoto;
> }*
>
>
> * /**
> * Gets the name value for this ClaimDetailType.
> *
> * @return name
> */
> public java.lang.String getName() {
> return name;
> }*
>
>
> * /**
> * Sets the name value for this ClaimDetailType.
> *
> * @param name
> */
> public void setName(java.lang.String name) {
> this.name = name;
> }*
>
>
> * /**
> * Gets the claimPhoto value for this ClaimDetailType.
> *
> * @return claimPhoto
> */
> public com.example.mimetypes.SwaRef getClaimPhoto() {
> return claimPhoto;
> }*
>
>
> * /**
> * Sets the claimPhoto value for this ClaimDetailType.
> *
> * @param claimPhoto
> */
> public void setClaimPhoto(com.example.mimetypes.SwaRef claimPhoto) {
> this.claimPhoto = claimPhoto;
> }*
>
> * private java.lang.Object __equalsCalc = null;
> public synchronized boolean equals(java.lang.Object obj) {
> if (!(obj instanceof ClaimDetailType)) return false;
> ClaimDetailType other = (ClaimDetailType) obj;
> if (obj == null) return false;
> if (this == obj) return true;
> if (__equalsCalc != null) {
> return (__equalsCalc == obj);
> }
> __equalsCalc = obj;
> boolean _equals;
> _equals = true &&
> ((this.name==null && other.getName()==null) ||
> (this.name!=null &&
> this.name.equals(other.getName()))) &&
> ((this.claimPhoto==null && other.getClaimPhoto()==null) ||
> (this.claimPhoto!=null &&
> this.claimPhoto.equals(other.getClaimPhoto())));
> __equalsCalc = null;
> return _equals;
> }*
>
> * private boolean __hashCodeCalc = false;
> public synchronized int hashCode() {
> if (__hashCodeCalc) {
> return 0;
> }
> __hashCodeCalc = true;
> int _hashCode = 1;
> if (getName() != null) {
> _hashCode += getName().hashCode();
> }
> if (getClaimPhoto() != null) {
> _hashCode += getClaimPhoto().hashCode();
> }
> __hashCodeCalc = false;
> return _hashCode;
> }*
>
> * // Type metadata
> private static org.apache.axis.description.TypeDesc typeDesc =
> new org.apache.axis.description.TypeDesc(ClaimDetailType.class,
> true);*
>
> * static {
> typeDesc.setXmlType(new javax.xml.namespace.QName("**
> http://example.com/mimetypes* <http://example.com/mimetypes>*",
> "ClaimDetailType"));
> org.apache.axis.description.ElementDesc elemField = new
> org.apache.axis.description.ElementDesc();
> elemField.setFieldName("name");
> elemField.setXmlName(new javax.xml.namespace.QName("", "Name"));
> elemField.setXmlType(new javax.xml.namespace.QName("**
> http://www.w3.org/2001/XMLSchema* <http://www.w3.org/2001/XMLSchema>*",
> "string"));
> elemField.setNillable(false);
> typeDesc.addFieldDesc(elemField);
> elemField = new org.apache.axis.description.ElementDesc();
> elemField.setFieldName("claimPhoto");
> elemField.setXmlName(new javax.xml.namespace.QName("",
> "ClaimPhoto"));
> elemField.setXmlType(new javax.xml.namespace.QName("**
> http://example.com/mimetypes* <http://example.com/mimetypes>*",
> "swaRef"));
> elemField.setNillable(false);
> typeDesc.addFieldDesc(elemField);
> }*
>
> * /**
> * Return type metadata object
> */
> public static org.apache.axis.description.TypeDesc getTypeDesc() {
> return typeDesc;
> }*
>
> * /**
> * Get Custom Serializer
> */
> public static org.apache.axis.encoding.Serializer getSerializer(
> java.lang.String mechType,
> java.lang.Class _javaType,
> javax.xml.namespace.QName _xmlType) {
> return
> new org.apache.axis.encoding.ser.BeanSerializer(
> _javaType, _xmlType, typeDesc);
> }*
>
> * /**
> * Get Custom Deserializer
> */
> public static org.apache.axis.encoding.Deserializer getDeserializer(
> java.lang.String mechType,
> java.lang.Class _javaType,
> javax.xml.namespace.QName _xmlType) {
> return
> new org.apache.axis.encoding.ser.BeanDeserializer(
> _javaType, _xmlType, typeDesc);
> }*
>
> *}
> *
>
> */**
> * SwaRef.java
> *
> * This file was auto-generated from WSDL
> * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
> */*
>
> *package com.example.mimetypes;*
>
> *public class SwaRef implements java.io.Serializable {
> public SwaRef() {
> }*
>
> * private java.lang.Object __equalsCalc = null;
> public synchronized boolean equals(java.lang.Object obj) {
> if (!(obj instanceof SwaRef)) return false;
> SwaRef other = (SwaRef) obj;
> if (obj == null) return false;
> if (this == obj) return true;
> if (__equalsCalc != null) {
> return (__equalsCalc == obj);
> }
> __equalsCalc = obj;
> boolean _equals;
> _equals = true;
> __equalsCalc = null;
> return _equals;
> }*
>
> * private boolean __hashCodeCalc = false;
> public synchronized int hashCode() {
> if (__hashCodeCalc) {
> return 0;
> }
> __hashCodeCalc = true;
> int _hashCode = 1;
> __hashCodeCalc = false;
> return _hashCode;
> }*
>
> * // Type metadata
> private static org.apache.axis.description.TypeDesc typeDesc =
> new org.apache.axis.description.TypeDesc(SwaRef.class, true);*
>
> * static {
> typeDesc.setXmlType(new javax.xml.namespace.QName("**
> http://example.com/mimetypes* <http://example.com/mimetypes>*",
> "swaRef"));
> }*
>
> * /**
> * Return type metadata object
> */
> public static org.apache.axis.description.TypeDesc getTypeDesc() {
> return typeDesc;
> }*
>
> * /**
> * Get Custom Serializer
> */
> public static org.apache.axis.encoding.Serializer getSerializer(
> java.lang.String mechType,
> java.lang.Class _javaType,
> javax.xml.namespace.QName _xmlType) {
> return
> new org.apache.axis.encoding.ser.BeanSerializer(
> _javaType, _xmlType, typeDesc);
> }*
>
> * /**
> * Get Custom Deserializer
> */
> public static org.apache.axis.encoding.Deserializer getDeserializer(
> java.lang.String mechType,
> java.lang.Class _javaType,
> javax.xml.namespace.QName _xmlType) {
> return
> new org.apache.axis.encoding.ser.BeanDeserializer(
> _javaType, _xmlType, typeDesc);
> }*
>
> *}
> *
>
> The server side implementation that WSDL2Java generates is:
>
> */**
> * ClaimBindingImpl.java
> *
> * This file was auto-generated from WSDL
> * by the Apache Axis 1.3 Oct 05, 2005 (05:23:37 EDT) WSDL2Java emitter.
> */*
>
> *package com.example.mimewsdl;*
>
> *public class ClaimBindingImpl implements
> com.example.mimewsdl.ClaimPortType{
> public java.lang.String sendClaim(
> com.example.mimetypes.ClaimDetailType body) throws
> java.rmi.RemoteException {
> return null;
> }*
>
> *}
> *
>
> The problem I have is that I do not have a clue how to use the SwaRef.javaclass. I have written a test client that can send files to the service the
> code is below:
>
> *package samples.swa;*
>
> *import java.io.ByteArrayInputStream;
> import java.io.File;
> import java.io.FileInputStream;
> import java.io.IOException;
> import java.io.InputStream;
> import java.net.URL;*
>
> *import javax.activation.DataHandler;
> import javax.activation.FileDataSource;
> import javax.mail.internet.MimeBodyPart;
> import javax.mail.internet.MimeMultipart;
> import javax.xml.soap.Name;
> import javax.xml.soap.SOAPBody;
> import javax.xml.soap.SOAPBodyElement;
> import javax.xml.soap.SOAPConnection;
> import javax.xml.soap.SOAPConnectionFactory;
> import javax.xml.soap.SOAPElement;
> import javax.xml.soap.SOAPMessage;*
>
> **
>
> *import org.apache.axis.SOAPPart;
> import org.apache.axis.attachments.AttachmentPart;
> import org.apache.axis.client.Call;
> import org.apache.axis.client.Service;
> import org.apache.axis.message.SOAPEnvelope;
> import org.apache.axis.message.SOAPHeader;
> import org.apache.axis.soap.SOAPFactoryImpl;*
>
> *import org.apache.axis.soap.MessageFactoryImpl;
> import org.soapinterop.mtom_test.AttachmentsPortType;
> import org.soapinterop.mtom_test.MtomTestDocSvcLocator;
> import org.soapinterop.mtom_test.types.Data;
> import org.soapinterop.mtom_test.types.PO;*
>
> *import com.example.mimetypes.ClaimDetailType;
> import com.example.mimetypes.SwaRef;
> import com.example.mimewsdl.ClaimPortType;
> import com.example.mimewsdl.ClaimSvcLocator;*
>
> */**
> * Class Tester
> *
> */
> public class Tester {*
>
> * /** Field HEADER_CONTENT_TYPE */
> public static final String HEADER_CONTENT_TYPE = "Content-Type";*
>
> * /** Field HEADER_CONTENT_TRANSFER_ENCODING */
> public static final String HEADER_CONTENT_TRANSFER_ENCODING =
> "Content-Transfer-Encoding";*
>
> * /** Field address */
> private static final java.lang.String address =
> "**http://localhost:9090/axis/services/ClaimPort*<http://localhost:9090/axis/services/ClaimPort>
> *";*
>
> * /**
> * Method main
> *
> * @param args
> * @throws Exception
> */
> public static void main(String[] args) throws Exception {*
>
> * java.net.URL endpoint;
> try {
> endpoint = new java.net.URL(address);
> } catch (java.net.MalformedURLException e) {
> throw new javax.xml.rpc.ServiceException(e);
> }
>
> SOAPConnectionFactory factory =
> SOAPConnectionFactory.newInstance();
> SOAPConnection connection = factory.createConnection();
> SOAPMessage request = null;
> MessageFactoryImpl mf = new MessageFactoryImpl();
> request = mf.createMessage();
> SOAPPart soapPart = (SOAPPart) request.getSOAPPart();
> SOAPEnvelope envelope = (SOAPEnvelope) soapPart.getEnvelope();
>
> SOAPHeader header = (SOAPHeader) envelope.getHeader();
> SOAPBody body = envelope.getBody();
> SOAPFactoryImpl soapFactory = new SOAPFactoryImpl();
>
> Name bodyName = soapFactory.createName("ClaimDetail",
> "m", "**http://example.com/mimetypes*<http://example.com/mimetypes>
> *");
> SOAPBodyElement bodyElement = body.addBodyElement(bodyName); *
>
> * Name name = soapFactory.createName("Name");
> SOAPElement symbol = bodyElement.addChildElement(name);
> symbol.addTextNode("Bobby Test");
>
> Name photo = soapFactory.createName("ClaimPhoto");
> symbol = bodyElement.addChildElement(photo);
> symbol.addTextNode("thephoto");
>
> URL url = new URL("**file:///myDoc.doc**");
>
>
> javax.xml.soap.AttachmentPart att = request.createAttachmentPart
> ();
> att.setDataHandler(dataHandler);
>
> att.setContentId("thephoto");
> att.setContentType("application/octet-stream");
>
> javax.xml.soap.AttachmentPart att2 = request.createAttachmentPart
> ();
> att2.setContentId("thephoto");
> byte[] data = getBytesFromFile(new File("C:/WebtopIssues.doc"));
>
> att2.setContent(new ByteArrayInputStream(data),
> "application/octet-stream");
>
>
> *
>
> *
> request.addAttachmentPart(att2);
> *
>
> * SOAPMessage response = connection.call(request, endpoint);
> connection.close();
> }*
>
> *
>
> // Returns the contents of the file in a byte array.
> public static byte[] getBytesFromFile(File file) throws IOException {
> InputStream is = new FileInputStream(file);
>
> // Get the size of the file
> long length = file.length();
>
> // You cannot create an array using a long type.
> // It needs to be an int type.
> // Before converting to an int type, check
> // to ensure that file is not larger than Integer.MAX_VALUE.
> if (length > Integer.MAX_VALUE) {
> // File is too large
> }
>
> // Create the byte array to hold the data
> byte[] bytes = new byte[(int)length];
>
> // Read in the bytes
> int offset = 0;
> int numRead = 0;
> while (offset < bytes.length
> && (numRead=is.read(bytes, offset, bytes.length-offset)) >=
> 0) {
> offset += numRead;
> }
>
> // Ensure all the bytes have been read in
> if (offset < bytes.length) {
> throw new IOException("Could not completely read file
> "+file.getName());
> }
>
> // Close the input stream and return bytes
> is.close();
> return bytes;
> }*
>
> *}
> *
>
> I had problems using a DataHandler it threw exceptions and I was not sure
> how to use the generated Port type. I realise that this is a long message
> but would appreciate any help.
>
> Many thanks
>
> Jim
>
>
>