Monday, July 25, 2011

Groovy.... Creating an XML file

import groovy.xml.MarkupBuilder
def valuefile = new File('TestData.xml')
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
Random random = new Random()
xml.records() {
for(int i=1; i<= 200; i++){ items{ id(i) orderId((1000+i)) price(random.nextInt(1000)+0.99) productId(random.nextInt(44)+1+'-' +(random.nextInt(999)+1)) productName('Appliances') quantity(random.nextInt(3)+1) shippingAddress('Some address') shippingCity('Some city') shippingName('UPS') shippingPhoneNumber('123456789') shippingState('PA') shippingZip('12345') } } } valuefile.append writer.toString() println writer.toString()

Monday, May 30, 2011

Spring security Kerberos Integration

Spring Security Kerberos Extension, authenticated the users against web application just by opening the URL. There is no need to enter a username/password and no need to install additional software.

To enable this integration we need the following steps,

1- Create a user in the active directory
i. server1
Set up the user password policy to non-expiring password

2- Create SPN for the user (Step 1- user)
The following command has to run to create spn for the above user
i. setspn –a username
ii. setspn -a HTTP/server1.domain.com@DOMAIN.COM server1

3- Create Key tab file
The following command has to run to create key tab file.
i. ktpass /out /mapuser /princ -kvno 0 /pass /ptype KRB5_NT_PRINCIPAL
ii. ktpass /out name.keytab /mapuser server1@domain.com /princ HTTP/server1.domain.com@DOMAIN.COM -kvno 0 /pass password /ptype KRB5_NT_PRINCIPAL

For spring configuration and more information please refer the following url

http://blog.springsource.com/2009/09/28/spring-security-kerberos/

Thursday, July 23, 2009

REST with CXF

REST with CXF

To understand more about rest with cxf please refer the following link
http://cwiki.apache.org/CXF20DOC/jax-rs.html#JAX-RS-Introduction

In this sample code I am using apache-cxf-2.2.2 version (http://cxf.apache.org/download.html )

Let’s create a simple Restful service using cxf and tomcat. This service will be used to get the connection information.

Following files are involved in this sample application.
ConnectionInfo.java
Connection.java
ConnectionDetails.java
ConnectionInfoImpl.java
cxf.xml
web.xml

connection.java & ConnectionDetails.java :- Represent the XML JAXB Object

ConnectionInfo.java and ConnectionInfoImple : Implementation of the RestFul service

cxf.xml : cxf configuration file for REST implementation

Before getting into the details of the application, we need to setup the web application in Tomcat.

• Copy the jar files under CXF lib folder to the lib folder under Tomcat
• Add the jars under lib folder of CXF to Java Build Path/Libraries of your project.


Connection.java

package com.javatch.rest;

import javax.xml.bind.annotation.XmlRootElement;


@XmlRootElement(name = "Connection")
public class Connection {

protected Integer officeId;
protected String districtId;
protected String regional_id;
protected String ipAddress;
protected String queueName;
protected String instanceName;


public Integer getOfficeId() {
return officeId;
}

public void setOfficeId(Integer officeId) {
this.officeId = officeId;
}

public String getIpAddress() {
return ipAddress;
}

public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}

public String getDistrictId() {
return districtId;
}

public void setDistrictId(String districtId) {
this.districtId = districtId;
}

public String getRegional_id() {
return regional_id;
}

public void setRegional_id(String regional_id) {
this.regional_id = regional_id;
}

public String getQueueName() {
return queueName;
}

public void setQueueName(String queueName) {
this.queueName = queueName;
}

public String getInstanceName() {
return instanceName;
}

public void setInstanceName(String instanceName) {
this.instanceName = instanceName;
}

}

ConnectionDetails.java

package com.javatch.rest;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "ConnectionDetails")
public class ConnectionDetails {

@XmlElement(name = "connection", required = true)
List <Connection> connection;

public List<Connection> getConnection() {
if (connection == null) {
connection = new ArrayList<Connection>();
}
return this.connection;
}

}



RestFul web service Implementation

Most of the JAX-RS annotations can be inherited from either an interface or a superclass. For example :

ConnectionInfo.java

package com.javatch.rest;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;


@Path("/Conn/")
public interface ConnectionInfo {

@GET
@Produces ("application/xml")
@Path("{officeId}")
public Connection getConnection(@PathParam ("officeId") int officeId);

@GET
@Produces ("application/xml")
@Path ("All")
public ConnectionDetails getAllConnections();
}



ConnectionInfoImpl.java

package com.javatch.rest;

import java.util.ArrayList;
import java.util.List;

public class ConnectionInfoImpl implements ConnectionInfo {

List <Connection> list = new ArrayList<Connection>();

ConnectionInfoImpl(){
Connection conn0 = new Connection();
conn0.setDistrictId("WA");
conn0.setInstanceName("instanceName");
conn0.setIpAddress("123.123.123.123");
conn0.setOfficeId(123);
conn0.setQueueName("Queue-Rest");
conn0.setRegional_id("WEST");
list.add(0, conn0);

Connection conn1 = new Connection();
conn1.setDistrictId("KS");
conn1.setInstanceName("instanceName");
conn1.setIpAddress("354.345.345.345");
conn1.setOfficeId(354);
conn1.setQueueName("Queue-Rest");
conn1.setRegional_id("CENTER");
list.add(1, conn1);
}

public Connection getConnection(int officeId) {
System.out.println("Inside the GetConnection...");
return list.get(0);
}

@Override
public ConnectionDetails getAllConnections() {
ConnectionDetails details = new ConnectionDetails();
for(Connection connection : list) {
details.getConnection().add(connection);
}
return details;
}

}


cxf.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.0.xsd
http://cxf.apache.org/jaxrs
http://cxf.apache.org/schemas/jaxrs.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-jaxrs-binding.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxrs:server id="connectionService" address="/">
<jaxrs:serviceBeans>
<ref bean="connection" />
</jaxrs:serviceBeans>
<jaxrs:extensionMappings>
<entry key="xml" value="application/xml" />
</jaxrs:extensionMappings>

</jaxrs:server>
<bean id="connection" class="com. javatch.rest.ConnectionInfoImpl" />
</beans>


Finally of course we need web.xml

Web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<display-name>RestWithCXF</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:com/javatch/rest/cxf.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>


Now it time to test this application, deploy this under tomcat.

Use the following url’s to test this operation

http://localhost:8080/<<Root>>/services/Conn/123

or

http://localhost:8080/<<Root>>/services/Conn/All



Let me know if you have any questions 

Thanks

Friday, June 12, 2009

ActiveMQ integration with mule using spring

ActiveMQ integration with mule using spring

There are different ways to integrate ActiveMQ with spring.

1) Run separate ActiveMQ instance
2) Embedded broker activeMQ instance or

Let’s starts with first option (Running separate ActiveMQ instance)

Here I am using mule 2.2, apache-activemq-5.2.0 and spring

Mule-config.xml

<mule xmlns="http://www.mulesource.org/schema/mule/core/2.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jms="http://www.mulesource.org/schema/mule/jms/2.2"
xmlns:amq="http://activemq.apache.org/schema/core" xmlns:cxf="http://www.mulesource.org/schema/mule/cxf/2.2"
xmlns:mule="http://www.mulesource.org/schema/mule/core/2.2"
xsi:schemaLocation="
http://www.mulesource.org/schema/mule/core/2.2 http://www.mulesource.org/schema/mule/core/2.2/mule.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.mulesource.org/schema/mule/jms/2.2 http://www.mulesource.org/schema/mule/jms/2.2/mule-jms.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd
http://www.mulesource.org/schema/mule/cxf/2.2 http://www.mulesource.org/schema/mule/cxf/2.2/mule-cxf.xsd">
<spring:beans>
<spring:bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<spring:property name="connectionFactory" ref="connectionFactory" />
</spring:bean>

<spring:bean id="queueFactory"
class="org.springframework.jndi.JndiObjectFactoryBean">
<spring:property name="jndiTemplate" ref="jndiTemplate" />
<spring:property name="jndiName" value="QueueConnectionFactory" />
</spring:bean>

<spring:bean id="jndiTemplate"
class="org.springframework.jndi.JndiTemplate">
<spring:property name="environment">
<spring:props>
<spring:prop key="java.naming.factory.initial">
org.apache.activemq.jndi.ActiveMQInitialContextFactory
</spring:prop>
<spring:prop key="java.naming.provider.url">
tcp://localhost:61616
</spring:prop>
</spring:props>
</spring:property>
</spring:bean>
</spring:beans>

<jms:jmsmessage-to-object-transformer name="JmsMessageToObject" />
<jms:object-to-jmsmessage-transformer name="ObjectToJmsMessage" />

<jms:connector name="AMQConnector"
numberOfConcurrentTransactedReceivers="2"
connectionFactory-ref="queueFactory"
persistentDelivery="true"
specification="1.1" maxRedelivery="2">

<receiver-threading-profile
maxBufferSize="5"
maxThreadsActive="5"
poolExhaustedAction="WAIT" threadWaitTimeout="50"
maxThreadsIdle="5"
threadTTL="55" />
<dispatcher-threading-profile
maxBufferSize="5"
maxThreadsActive="5"
poolExhaustedAction="WAIT"
threadWaitTimeout="55"
maxThreadsIdle="5"
threadTTL="5" />
<default-connector-exception-strategy>
<rollback-transaction exception-pattern="*" />
</default-connector-exception-strategy>
</jms:connector>

<model name="TestJMSModel">
<service name="TestJMSService">
<inbound>

<vm:inbound-endpoint address="vm://JavaTch.Entry.Q ">
<transformers>
<transformer ref="JmsMessageToObject" />
<transformer ref="JaxbXmlToObject" />
</transformers>
</vm:inbound-endpoint>
</inbound>
<outbound>
<pass-through-router>
<jms:outbound-endpoint address="jms:// JavaTch.Exit.Q"
connector-ref="AMQConnector">
<transformers>
<transformer ref="JaxbObjectToXml" />
<transformer ref="ObjectToJmsMessage" />
</transformers>
</jms:outbound-endpoint>
</pass-through-router>
</outbound>
</service>
</model>


Now we need to run this using Mule Client.

TestJMSMuleClient.java

import java.util.UUID;

import org.mule.api.MuleContext;
import org.mule.api.config.ConfigurationBuilder;
import org.mule.config.spring.SpringXmlConfigurationBuilder;
import org.mule.context.DefaultMuleContextFactory;
import org.mule.module.client.MuleClient;


public class TestJMSMuleClient {
public static void main(String[] args) throws Exception {

MuleContext muleContext = new DefaultMuleContextFactory()
.createMuleContext();
ConfigurationBuilder builder = new SpringXmlConfigurationBuilder(
"mule-config.xml");
builder.configure(muleContext);
muleContext.start();
MuleClient client = new MuleClient();
//here you need to create your object
// YourClass objectPayload = new YourClass();
//
client.dispatch("vm://JavaTch.Entry.Q ", objectPayload, null);
}
}



2) Embedded broker activeMQ instance

Modify your mule-config.xml to have embedded activeMQ instance.


<spring:beans>

<amq:broker id="AMQBroker" useJmx="false" persistent="false">
<amq:managementContext>
<amq:managementContext createConnector="false" />
</amq:managementContext>
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:61616" />
</amq:transportConnectors>
</amq:broker>
<amq:connectionFactory id="jmsFactoryCore"
brokerURL="tcp://localhost:61616" />
</spring:beans>


<jms:activemq-connector name="AMQConnector"
brokerURL="tcp://localhost:61616" connectionFactory-ref=
"jmsFactoryCore"/>

The above code will start a activeMQ instance.
Then we can use this connector in the jms endpoint

Tuesday, May 12, 2009

Mule2.x - expression-recipient-list-router – Dynamic Endpoint in mule

Mule2.x - expression-recipient-list-router – Dynamic Endpoint in mule

The expression recipient list router can be used to send the same message to multiple endpoints over the same endpoint or to implement routing-slip behavior where the next destination for the message is determined from message properties or the payload. It uses a list of recipient’s endpoints which are extracted from the message using an expression.

Here I will give you an example how to use the expression-recipient-list-router.

In this example I am using mule 2.2. (http://www.mulesource.org)


Mule-config.xml

Spring declaration
<spring:bean id="ExpressionHandlerBean"
class="com.javatch.expression.ExpressionHandlerBean">

actual mule configuration
<model name="test Expression">
<service name="Expression">
<inbound>
<vm:inbound-endpoint address="vm://Expression" synchronous="true" >
</vm:inbound-endpoint>
</inbound>
<component>
<spring-object bean="ExpressionHandlerBean"></spring-object>
</component>
<outbound>
<expression-recipient-list-router evaluator="header"
expression="ADDR_LIST" >
</expression-recipient-list-router>
</outbound>
</service>

<service name="TEST">
<inbound>
<vm:inbound-endpoint address="vm://TEST" synchronous="true" />
</inbound>
<outbound>
<pass-through-router>
<file:outbound-endpoint path="${some temp dir}"
transformer-refs="ValidateTheFlow" />
</pass-through-router>
</outbound>
</service>
</model>





In the component class I am adding the endpoint, here if you can any number endpoint ExpressionRecipientList.java (from Mule) will take care of functional flow. 

ExpressionHandlerBean.java

public class ExpressionHandlerBean implements Callable {

public Object onCall(MuleEventContext eventContext) throws Exception {
try {
List<String> addressList = new ArrayList<String>();
addressList.add("vm://TEST");
eventContext.getMessage().setProperty("ADDR_LIST",addressList);
}
catch( Exception ex ) {
ex.printStackTrace();
}
return null;
}

}

Friday, May 1, 2009

Setting up EhCache using Spring

Setting up EhCache using Spring

Ehcache is a pure Java cache with the following features: fast, simple, small foot print, minimal dependencies, provides memory and disk stores for scalability into gigabytes, scalable to hundreds of caches are a pluggable cache for Hibernate.

Here I am going to explain how to integrate ehcache with spring.

Following jar files are required in the class path in order to run this application J
ehcache-1.6.0-beta3.jar
spring-2.5.5.jar

We use ehcache.xml to configure all cache related information.


<ehcache>
<diskStore path="java.io.tmpdir"/>
<cache name="javatchEhcache"
maxElementsInMemory="1000"
eternal="true"
overflowToDisk="false"/>
<defaultCache
maxElementsInMemory="200"
maxElementsOnDisk="500"
eternal="false"
timeToIdleSeconds="120"
timeToLiveSeconds="120"
overflowToDisk="true"/>
</ehcache>

Back to spring configuration, we have to configure ehcache dependencies in to spring.

beans.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="ecManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>

<bean id="mycache" class=" com.javatch.ehcache.example.EhCacheManager" init-method="setupCache">
<property name="cacheManager" ref="ecManager"/>
</bean>

</beans>

Create ehcache reference from java
EhCacheManager.java
package com.javatch.ehcache.example;

import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

public class EhCacheManager {

private CacheManager cacheManager;
private static Cache myCache = null;

public void setCacheManager(CacheManager cacheManager) {
this.cacheManager = cacheManager;
}

private void setupCache() {
String cacheName = "javatchEhcache";
System.out.println("cache Name [" + cacheName + "]");
myCache = cacheManager.getCache(cacheName);
}

private static Element getValues(String key){
Element value = myCache.get(key);
if(value!=null) {
System.out.println("from cache");
return value;
} else {
// DAO call goes here...
myCache.put(new Element(key, "Object"));
System.out.println("not from cache");
}
return value;
}
private static void setValuesIntoCache(){
myCache.put(new Element("OS", "OSCache"));
myCache.put(new Element("OD", "OracleDBCache"));
}
public static void main(String[] args) {

BeanFactory factory = new XmlBeanFactory(new FileSystemResource("beans.xml"));
System.out.println(factory.getBean("mycache"));
setValuesIntoCache();
getValues("NB");

}

}

Thank you 

Tuesday, April 14, 2009

MTOM (Message Transmission Optimization Mechanism)

MTOM (Message Transmission Optimization Mechanism)

MTOM allows send and receives attachments (such as document, pdf and images) efficiently and in an interoperable manner. It uses XOP (XML-binary Optimized Packaging) to transmit binary data (attachments like PDF, Doc and images etc)


Advantage of MTOM:

Base64Binary encoded data bloats the attachment by ~33%. MTOM converts the Base64Binary data to raw bytes over MIME, thus reducing the wire foot-print for transmission. The reciever can optinally convert the raw bytes back to Base64Binary encoding.


MTOM Process

The Consumer application begins by sending a SOAP Message that contains complex data in Base64Binary encoded format. Base64Binary data type represents arbitrary data (e.g., Images, PDF files, Word Docs) in 65 textual characters that can be displayed as part of a SOAP Message element. For the Send SOAP Message Step 1 in the Figure above, a sample SOAP Body with Base64Binary encoded element


Next it tried convert the Base64Binary data to MIME data with an XML-binary Optimization Package (xop) content type.

A Simple MTOM using Apache CXF:

Server implementation:

package com.javatch.service;

import java.io.File;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import javax.activation.DataHandler;

import javax.jws.WebService;

import com.javatch.bean.Upload;

@WebService(endpointInterface = "com.javatch.service.MTOMServiceImpl",

serviceName = "MTOMService")

public class MTOMServiceImpl implements MTOMService {

public void uploadFile(Upload upload) {

DataHandler handler = upload.getFile();

try {

InputStream is = handler.getInputStream();

OutputStream os = new FileOutputStream(new File("c:\\"

+ upload.getFile()+"."+

upload.getExtn()));

byte[] buf = new byte[100000];

int len;

while ((len = is.read(buf)) > 0){

os.write(buf, 0, len);

}

is.close();

os.close();

System.out.println("File copied.");

} catch (IOException e) {

e.printStackTrace();

}

}

}

Service Interface:

@WebService

public interface MTOMService {

void uploadFile(@WebParam(name="upload") Upload upload);

}

Pojo:

package com.javatch.bean;

import javax.activation.DataHandler;

public class Upload

{

private String fileName;

private String extn;

private DataHandler file;

public String getFileName()

{

return this.fileName;

}

public void setFileName(String fileName)

{

this.fileName = fileName;

}

public DataHandler getFile()

{

return this.file;

}

public void setFile(DataHandler file)

{

this.file = file;

}

public String getExtn() {

return extn;

}

public void setExtn(String extn) {

this.extn = extn;

}

}

Cxf file:

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:jaxws="http://cxf.apache.org/jaxws"

xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd

http://cxf.apache.org/jaxws

http://cxf.apache.org/schemas/jaxws.xsd">

<import resource="classpath:META-INF/cxf/cxf.xml" />

<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml"/>

<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

<jaxws:endpoint id="uploadresume"

implementor="com.javatch.service.MTOMServiceImpl"

address="MTOMService">

<jaxws:properties>

<entry key="mtom-enabled" value="true"/>

jaxws:properties>

jaxws:endpoint>

beans>

The structure of application looks like this,

Webapps

--FileUpload

--WEB-INF

--classes

--com.javatch.bean

--Upload

--com.javatch.service

--MTOMService

--MTOMServiceImpl

--cxf.xml

--lib

--web.xml

We have to modify web.xml to include cxf with this application

Web.xml

xml version="1.0"?>

DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"

"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>ResumeUploaddisplay-name>

<context-param>

<param-name>contextConfigLocationparam-name>

<param-value>classpath:com/thea/service/cxf.xmlparam-value>

context-param>

<listener>

<listener-class>

org.springframework.web.context.ContextLoaderListener

listener-class>

listener>

<servlet>

<servlet-name>CXFServletservlet-name>

<servlet-class>

org.apache.cxf.transport.servlet.CXFServlet

servlet-class>

servlet>

<servlet-mapping>

<servlet-name>CXFServletservlet-name>

<url-pattern>/services/*url-pattern>

servlet-mapping>

web-app>

We are done with server files J

Client :

package com.javatch.client;

import java.io.File;

import java.util.HashMap;

import java.util.Map;

import javax.activation.DataHandler;

import javax.activation.DataSource;

import javax.activation.FileDataSource;

import org.apache.cxf.interceptor.LoggingInInterceptor;

import org.apache.cxf.interceptor.LoggingOutInterceptor;

import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

import com.javatch.bean.Upload;

import com.javatch.service.MTOMService;

public final class Client {

private Client() {

}

public static void main(String args[]) throws Exception {

Map props = new HashMap();

props.put("mtom-enabled", Boolean.TRUE);

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();

factory.setProperties(props);

factory.getInInterceptors().add(new LoggingInInterceptor());

factory.getOutInterceptors().add(new LoggingOutInterceptor());

factory.setServiceClass(MTOMService.class);

factory.setAddress

("http://localhost:8081/resumeupload/services/UploadResumeWS");

MTOMService client = (MTOMService) factory.create();

Upload upload=new Upload();

upload.setFileName("EnterpriseAOP_Free-seminar_July_2006");

upload.setExtn("pdf");

DataSource source = new FileDataSource(new File("C: \\EnterpriseAOP_Free-seminar_July_2006.pdf"));

upload.setFile(new DataHandler(source));

client.uploadFile(upload);

System.exit(0);

}

}

Copy FileUpload folder in to the webapps directory and restart the server.

Now use the client code to test the application.