Docsity

JAX-RPC and Attachments: A Guide by Ye Wu - Prof. Ye Wu, Study notes of Engineering

Toggle sidebar
bg1
1
Advanced JAXRPC
Ye Wu
http://www.ise.gmu.edu/~wuye
SWE 645
Component-based Software Development
sources: Java Web Service Architecture, James McGoven and etc.,
Morgan Kaufmann, Ch 4, 10, 11 (8 and 9 are supporting chapters)
2007-4-17 © Dr. Ye Wu 2
Attachment in JAX-RPC
• How to transfer binary data through JAX-RPC?
– Base64-encoding
• Translate binary to text
• Increase the size by nearly 33%
– SOAP with attachments
2007-4-17 © Dr. Ye Wu 3
SOAP Message – With Attachment
Content-type:text/xml
<?xml verion=1.0>
<SOAP:Envelope>
……
</SOAP:Envelope>
HTTP Message
--MIME_boundary
--MIME_boundary
Content-type:image/jpg
…Image file…
--MIME_boundary
2007-4-17 © Dr. Ye Wu 4
Attachment in SOAP
Javax.xml.transform.source
Javax.mail.internet.MimeMultipart
Java.lang.string
Java.awt.image
Java.awt.image
Text/xml
Multipart/*
Text/plain
Image/jpg
Image/gif
•Javax.activation.DataHandler is automatically sent
As attachment.
•MIME types and Java class mapping.
2007-4-17 © Dr. Ye Wu 5
Developing the Axis service
public class ATServer{
public ATServer() { }
public String UpLoadFile(javax.activation.DataHandler att) {
try {
att.writeTo(new FileOutputStream("ABC"));
} catch (Exception e) {
e.printStackTrace();
return "Error";
}
return "OK";
}
}
2007-4-17 © Dr. Ye Wu 6
Developing the Axis service
QName qn = new QName("YW","DataHandler");
call.registerTypeMapping(DataHandler.class, qn,
org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class,
org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class);
call.addParameter("inputfile", qn, ParameterMode.IN );
FileDataSource ds = new FileDataSource("ABC");
DataHandler handler = new DataHandler(ds);
call.setReturnType(XMLType.XSD_STRING);
String rts = (String)call.invoke(new Object[]{handler});
pf2

Partial preview of the text

Download JAX-RPC and Attachments: A Guide by Ye Wu - Prof. Ye Wu and more Study notes Engineering in PDF only on Docsity!

Advanced JAXRPC

Ye Wu

http://www.ise.gmu.edu/~wuye

SWE 645

Component-based Software Development

sources: Java Web Service Architecture, James McGoven and etc., Morgan Kaufmann, Ch 4, 10, 11 (8 and 9 are supporting chapters) 2007-4-17 © Dr. Ye Wu 2

Attachment in JAX-RPC

• How to transfer binary data through JAX-RPC?

  • Base64-encoding
    • Translate binary to text
    • Increase the size by nearly 33%
  • SOAP with attachments

2007-4-17 © Dr. Ye Wu 3

SOAP Message – With Attachment

Content-type:text/xml

… …

HTTP Message

--MIME_boundary

--MIME_boundary

Content-type:image/jpg …Image file…

--MIME_boundary

2007-4-17 © Dr. Ye Wu 4

Attachment in SOAP

Javax.xml.transform.source

Javax.mail.internet.MimeMultipart

Java.lang.string

Java.awt.image

Java.awt.image

Text/xml

Multipart/*

Text/plain

Image/jpg

Image/gif

•Javax.activation.DataHandler is automatically sent

As attachment.

•MIME types and Java class mapping.

2007-4-17 © Dr. Ye Wu 5

Developing the Axis service

public class ATServer{ public ATServer() { } public String UpLoadFile(javax.activation.DataHandler att) { try { att.writeTo(new FileOutputStream("ABC")); } catch (Exception e) { e.printStackTrace(); return "Error"; } return "OK"; } }

2007-4-17 © Dr. Ye Wu 6

Developing the Axis service

QName qn = new QName("YW","DataHandler"); call.registerTypeMapping(DataHandler.class, qn, org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory.class, org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory.class); call.addParameter("inputfile", qn, ParameterMode.IN );

FileDataSource ds = new FileDataSource("ABC"); DataHandler handler = new DataHandler(ds); call.setReturnType(XMLType.XSD_STRING);

String rts = (String)call.invoke(new Object[]{handler});

2007-4-17 © Dr. Ye Wu 7

Prepare Deployment Descriptor

2007-4-17 © Dr. Ye Wu 8

Message Handler and Handler Chain

  • SOAP message handler is a Java class that provides a

filtering mechanism for preprocessing and postprocessing

the SOAP message.

Client

handleRequest handleRequest

Server

handleResponse handleResponse

M

U

U

M

SOAP

SOAP

2007-4-17 © Dr. Ye Wu 9

Message Handler and Handler Chain

• Advantages

  • Introducing security
  • Processing metadata
  • Validating data
  • Handling data content
  • Optimizing and improving performance
  • Implementing intermediaries

• Disadvantages

  • Affect interoperability
  • Degrade performance 2007-4-17 © Dr. Ye Wu 10

Holder Classes

• JAX-RPC passes parameters by value.

• CORBA convention

• Holder classes enable the mapping to preserve the

intended WSDL signature and parameter-passing

semantics

2007-4-17 © Dr. Ye Wu 11

Advanced SOAP Programming

public class MyclassHolder implements javax.xml.rpc.holders.Holder { // Order's object public Myclass value = null;

// default constructor public void MyclassHolder () { }

// constructor, which takes value as a parameter public void MyclassHolder (Myclass value) { this.value=value; } } 2007-4-17 © Dr. Ye Wu 12

JAX-RPC, SAAJ and JAXM

  • SAAJ (SOAP Attachment API for Java)
  • JAXM(Java API for XML messaging)
  • SAAJ is used to be part of JAXM. Now, SAAJ is a part

that are shared by JAX-RPC and JAXM

  • SAAJ can be used by itself to write SOAP client.
    • Lower level than JAX-RPC and JAXM
    • More flexibility
  • JAXM supports asynchronous and guaranteed messing.

(similar to JMS)