Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: MTOM Example does not compile

  1. #11

    Default Here is How to do it with MTOM (part 10)

    6 - Here is the code for the client (It uses the same schema as the server side, already included in one of the previous parts):

    package com.oracle.mtom.client;

    import java.io.IOException;
    import java.io.File;
    import java.util.Calendar;
    import java.util.TimeZone;
    import java.util.GregorianCalendar;
    import javax.xml.datatype.DatatypeFactory;
    import javax.xml.datatype.DatatypeConstants;
    import javax.activation.FileDataSource;
    import javax.activation.DataHandler;
    import javax.xml.transform.TransformerException;
    import javax.xml.transform.stream.StreamResult;

    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.ws.client.core.support.WebServ iceGatewaySupport;
    import org.springframework.xml.transform.StringSource;
    import org.springframework.ws.WebServiceMessage;
    import org.springframework.ws.client.core.WebServiceMessa geCallback;
    import org.springframework.ws.soap.SoapMessage;
    import org.springframework.ws.soap.addressing.core.Endpoi ntReference;
    import org.springframework.ws.soap.addressing.client.Acti onCallback;
    import java.net.URI;
    import org.springframework.ws.soap.addressing.version.Add ressing10;

    import javax.xml.bind.JAXBElement;

    import com.oracle.mtom.schema.*;

    public class MtomServiceClient extends WebServiceGatewaySupport {

    private ObjectFactory objectFactory;

    private boolean useWSAddressing = false;

    private String action;

    private String to;

    private String replyTo;

    public MtomServiceClient(){
    objectFactory = new ObjectFactory();
    }

    public void setUseWSAddressing(boolean value){
    useWSAddressing = value;
    }

    public boolean getUseWSAddressing(){
    return useWSAddressing;
    }

    public void setAction(String value){
    action = value;
    }

    public String getAction(){
    return action;
    }

    public void setTo(String value){
    to = value;
    }

    public String getTo(){
    return to;
    }

    public void setReplyTo(String value){
    replyTo = value;
    }

    public String getReplyTo(){
    return replyTo;
    }

    public void processRequest(String source1, String source2) throws IOException, TransformerException, Exception {

    JAXBElement responseElement = null;

    com.oracle.mtom.schema.Package pkg = new com.oracle.mtom.schema.Package();
    pkg.setPackageTitle("Policy-xyz");
    pkg.setRecipient1("Insured");
    pkg.setRecipient2("Agent");
    pkg.setRecipient3("Carrier");


    DatatypeFactory factory = DatatypeFactory.newInstance();
    TimeZone tz = TimeZone.getTimeZone("UTC");
    GregorianCalendar gc = new GregorianCalendar(tz);
    pkg.setStartDate(factory.newXMLGregorianCalendar(g c));
    gc.add(Calendar.DATE, 30); //30 days later
    pkg.setEndDate(factory.newXMLGregorianCalendar(gc) );


    //Optional attachment 1
    if (source1 != null && source1.trim().length() > 0){
    File f = new File(source1);
    FileDataSource fd = new FileDataSource(f);
    DataHandler dh = new DataHandler(fd);
    Attachment attachment1 = new Attachment();
    attachment1.setName(f.getName());
    attachment1.setContent(dh);
    pkg.getAttachment().add(attachment1);
    }

    //Optional attachment 2
    if (source2 != null && source2.trim().length() > 0){
    File f = new File(source2);
    FileDataSource fd = new FileDataSource(f);
    DataHandler dh = new DataHandler(fd);
    Attachment attachment2 = new Attachment();
    attachment2.setName(f.getName());
    attachment2.setContent(dh);
    pkg.getAttachment().add(attachment2);
    }

    pkg.setOptional1("dummy text");

    JAXBElement<com.oracle.mtom.schema.Package> request = objectFactory.createTestRequest(pkg );


    if (useWSAddressing){
    System.out.println("Using WS-Addressing");
    ActionCallback myCallback = new ActionCallback(new URI(action), //Action Header
    new Addressing10(), //Version Header
    new URI(to)); //To Header

    myCallback.setReplyTo(new EndpointReference(new URI(replyTo))); //Reply-To Header

    responseElement = (JAXBElement)getWebServiceTemplate().marshalSendAn dReceive(request, myCallback);

    }else{
    System.out.println("Not using WS-Addressing.");

    responseElement = (JAXBElement)getWebServiceTemplate().marshalSendAn dReceive(request);
    }

    if (responseElement != null){
    PackageResponse rsp = (PackageResponse)responseElement.getValue();
    System.out.println("Results=<" + rsp.getResults() + ">");
    System.out.println("ArchiveDate=<" + rsp.getArchiveDate() + ">");
    }

    }

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

    ApplicationContext ctx = new ClassPathXmlApplicationContext(args[0]);

    MtomServiceClient mtomServiceClient = (MtomServiceClient) ctx.getBean("MtomServiceClient", MtomServiceClient.class);

    mtomServiceClient.processRequest(args.length > 1? args[1]: null, args.length > 2? args[2] : null);


    }catch (Exception e) {
    e.printStackTrace();
    }

    }


    }

    continues on the next thread...

  2. #12

    Default Here is How to do it with MTOM (part 11)

    7 - Here is the spring config. file for the client side:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:sec="http://www.springframework.org/schema/security"
    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-2.0.xsd">


    <bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshalle r">
    <!--A list of colon : separated package names that contain schema derived classes -->
    <property name="contextPath" value="com.oracle.mtom.schema"/>
    <!--Enables / disables MTOM -->
    <property name="mtomEnabled" value="true"/>
    <!--Used for validation. Cannot validate when MTOM is enabled. -->
    <!-- <property name="schema" value="schema.xsd"/> -->
    </bean>


    <bean id="MtomServiceClient" class="com.oracle.mtom.client.MtomServiceClient">
    <property name="defaultUri" value="http://localhost:8080/mtomService2"/>

    <!-- Using STAX instead of SAAJ works but the attachment becomes inline and MTOM is no longer used. -->
    <!-- <property name="messageFactory" ref="messageFactory"/> -->

    <property name="marshaller" ref="marshaller"/>
    <property name="unmarshaller" ref="marshaller"/>

    </bean>
    </beans>

  3. #13

    Default Here is How to do it with MTOM (part 12)

    8 - Here is the client side pom.xml file:

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.oracle.mtom</groupId>
    <artifactId>mtomServiceClient</artifactId>
    <packaging>jar</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>mtomServiceClient Spring-WS Application</name>
    <url>http://www.springframework.org/spring-ws</url>
    <build>
    <finalName>mtomServiceClient</finalName>
    <plugins>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
    <source>1.5</source>
    <target>1.5</target>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <executions>
    <execution>
    <goals>
    <goal>generate</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <generatePackage>com.oracle.mtom.schema</generatePackage>
    <schemaDirectory>.</schemaDirectory>
    </configuration>
    </plugin>
    </plugins>
    </build>
    <repositories>
    <repository>
    <id>maven2-repository.dev.java.net</id>
    <name>Java.net Maven 2 Repository</name>
    <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
    <id>maven-repository.dev.java.net</id>
    <name>Java.net Maven 1 Repository (legacy)</name>
    <url>http://download.java.net/maven/1</url>
    <layout>legacy</layout>
    </repository>
    <repository>
    <id>EclipseLink Repo</id>
    <url>http://www.eclipse.org/downloads/download.php?r=1&amp;nf=1&amp;file=/rt/eclipselink/maven.repo</url>
    </repository>
    </repositories>
    <pluginRepositories>
    <pluginRepository>
    <id>maven2-repository.dev.java.net</id>
    <name>Java.net Maven 2 Repository</name>
    <url>http://download.java.net/maven/2</url>
    </pluginRepository>
    <pluginRepository>
    <id>maven-repository.dev.java.net</id>
    <name>Java.net Maven 1 Repository (legacy)</name>
    <url>http://download.java.net/maven/1</url>
    <layout>legacy</layout>
    </pluginRepository>
    </pluginRepositories>
    <dependencies>
    <dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-core-tiger</artifactId>
    <version>1.5.6</version>
    <exclusions>
    <exclusion>
    <groupId>stax</groupId>
    <artifactId>stax-api</artifactId>
    </exclusion>
    <exclusion>
    <groupId>wsdl4j</groupId>
    <artifactId>wsdl4j</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    <dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-oxm-tiger</artifactId>
    <version>1.5.6</version>
    <scope>runtime</scope>
    <exclusions>
    <exclusion>
    <groupId>stax</groupId>
    <artifactId>stax-api</artifactId>
    </exclusion>
    </exclusions>
    </dependency>

    <dependency>
    <groupId>javax.mail</groupId>
    <artifactId>mail</artifactId>
    <version>1.4</version>
    </dependency>

    <dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1</version>
    </dependency>

    <!-- JAXB2 -->
    <!--
    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.1</version>
    <exclusions>
    <exclusion>
    <groupId>javax.xml.stream</groupId>
    <artifactId>stax-api</artifactId>
    </exclusion>
    </exclusions>
    </dependency>
    -->

    <!--
    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.5</version>
    </dependency>
    -->

    <!-- EclipseLink JAXB2 interface -->
    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>javax.xml.bind</artifactId>
    <version>2.0.0.v20080604-1500</version>
    </dependency>

    <!-- EclipseLink JAXB2 implementation -->
    <dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.0</version>
    </dependency>

    <!--
    <dependency>
    <groupId>com.oracle.jaxb</groupId>
    <artifactId>oracle-jaxb-package</artifactId>
    <version>1.0-SNAPSHOT</version>
    </dependency>
    -->

    <!-- SAAJ -->
    <dependency>
    <groupId>javax.xml.soap</groupId>
    <artifactId>saaj-api</artifactId>
    <version>1.3</version>
    </dependency>

    <!--Sun's SAAJ implementation. -->

    <dependency>
    <groupId>com.sun.xml.messaging.saaj</groupId>
    <artifactId>saaj-impl</artifactId>
    <version>1.3</version>
    </dependency>

    <!-- Oracle's SAAJ implementation -->
    <!--
    <dependency>
    <groupId>oracle.j2ee.ws.saaj</groupId>
    <artifactId>orasaaj</artifactId>
    <version>11.1.1.0.0</version>
    </dependency>

    <dependency>
    <groupId>javax.xml</groupId>
    <artifactId>xmlparserv2</artifactId>
    <version>11.1.0.6.0_production</version>
    </dependency>
    -->

    <!-- STAX -->

    <dependency>
    <groupId>javanet.staxutils</groupId>
    <artifactId>stax-utils</artifactId>
    <version>1.0.1</version>
    </dependency>

    <!-- Woodstox STAX -->

    <dependency>
    <groupId>woodstox-core-asl</groupId>
    <artifactId>woodstox-core-asl</artifactId>
    <version>4.0.3</version>
    </dependency>

    <dependency>
    <groupId>stax2-api</groupId>
    <artifactId>stax2-api</artifactId>
    <version>3.0.1</version>
    </dependency>

    <!-- Oracle dependencies for ORAWSDL -->
    <dependency>
    <groupId>oracle</groupId>
    <artifactId>orawsdl</artifactId>
    <version>11.1.1</version>
    </dependency>

    <dependency>
    <groupId>oracle</groupId>
    <artifactId>oracle_http_client_</artifactId>
    <version>11.1.1</version>
    </dependency>

    <dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.15</version>
    <exclusions>
    <exclusion>
    <groupId>com.sun.jdmk</groupId>
    <artifactId>jmxtools</artifactId>
    </exclusion>
    <exclusion>
    <groupId>com.sun.jmx</groupId>
    <artifactId>jmxri</artifactId>
    </exclusion>
    </exclusions>
    </dependency>

    <!-- WS-Security -->

    <dependency>
    <groupId>org.apache.ws.security</groupId>
    <artifactId>wss4j</artifactId>
    <version>1.5.6</version>
    </dependency>

    <dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-security</artifactId>
    <version>1.5.6</version>
    <exclusions>
    <exclusion>
    <groupId>org.acegisecurity</groupId>
    <artifactId>acegi-security</artifactId>
    </exclusion>
    <exclusion>
    <groupId>com.sun.xml.wss</groupId>
    <artifactId>xws-security</artifactId>
    </exclusion>
    <exclusion>
    <groupId>javax.xml.crypto.dsig</groupId>
    <artifactId>xmldsig</artifactId>
    </exclusion>
    </exclusions>
    </dependency>


    </dependencies>
    </project>


    There is another thread in which I posted how to do Validation with MTOM. It is really a workaround for now. Please search 'A Workaround to Validate with MTOM'.
    Last edited by joe_roberts_z; May 18th, 2009 at 04:57 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •