|
Key
This line was removed.
This word was removed. This word was added.
This line was added.
|
Changes (8)
View Page Historyh2. Introduction
{section}
{column}
This document is a complement to the documentation of the Petals SE-JSR181 component.
It assumes that you already know how to generate a JSR181 SU using PetalsStudio: most code examples detailed here are embedded in the JSR181 SU main class, pointed as <jsr181:class> in the jbi.xml of the SU.
{column}
{column}
{panel:title=Table of Contents}{toc}{panel}
{column}
{section}
{column}
This document is a complement to the documentation of the Petals SE-JSR181 component.
It assumes that you already know how to generate a JSR181 SU using PetalsStudio: most code examples detailed here are embedded in the JSR181 SU main class, pointed as <jsr181:class> in the jbi.xml of the SU.
{column}
{column}
{panel:title=Table of Contents}{toc}{panel}
{column}
{section}
This document is a complement to Petals SE-JSR181 component documentation. It assumes that you already know how to generate a JSR181 SU using PetalsStudio: most code examples detailed here are embedded in the JSR181 SU main class, pointed as <jsr181:class> in the jbi.xml of the SU.
h1. Implementing a web method that deals with complex types and attachments
h2. Implementing a web method that deals with complex types and attachments
This example is an upload method: it receives path + file name information (where to store the file) as a parameter, and a file to upload (as a binary attachment).
h32. Upload method in SU main class (JAX-WS annotated)
{code}
{code}
h32. Class for complex type parameter
This class is a simple JavaBean (POJO with getter/setter methods for each field: here, fields are "path" and "name", as the class represents an "upload destination" = a file).
}
{code}
{code}
h1. Invoking a Petals service
This class illustrates how a JSR-181 implementation can invoke a Petals service.
The invoked service is here a mailing service.
{code}
package org.ow2.sample;
import java.util.logging.Logger;
import javax.jbi.messaging.MessagingException;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.namespace.QName;
import org.ow2.petals.component.framework.api.Message.MEPConstants;
import org.ow2.petals.component.framework.api.exception.PEtALSCDKException;
import org.ow2.petals.component.framework.api.message.Exchange;
import org.ow2.petals.jsr181.JBIContext;
import org.ow2.petals.jsr181.JBIContextManager;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import com.ebmwebsourcing.easycommons.xml.DocumentBuilders;
/**
* Here is a sample JAX-WS implementation.
* <p>
* For more information about JAX-WS, please visit
* <b>https://jax-ws.dev.java.net/jax-ws-ea3/docs/annotations.html</b>.
* </p>
*/
@WebService( serviceName="MailProxyService", targetNamespace="http://sample.ow2.org", portName="MailProxyServicePort" )
public class MailProxyService {
/* (non-Javadoc)
* @see JaxWSInterface#HelloWorld()
*/
@WebMethod( operationName="helloWorld" )
@WebResult( name="returnMessage" )
public String helloWorld() {
return "Hello World!";
}
/*
* (non-Javadoc)
* @see toto.JaxWSInterface
* #propagateMessage(java.lang.String)
*/
@WebMethod( operationName="listenToTheWorld" )
@Oneway
public void propagateMessage( @WebParam( name="message" ) String message ) {
// We here illustrate a method that does not return anything.
// This method uses a Petals extension to invoke other services in the bus.
// Get the JBI context
JBIContext jbiContext = JBIContextManager.getJBIContext();
// Create the mail content
StringBuilder mailContent = new StringBuilder();
mailContent.append( "Propagating the received message...\n" ).append( message );
// Create a XML document...
final String MAIL_NS = "http://petals.ow2.org/components/mail/version-3";
Document mailDocument = DocumentBuilders.newDocument();
final Element mailElement = mailDocument.createElementNS( MAIL_NS, "mail" );
mailDocument.appendChild( mailElement );
final Element bodyElement = mailDocument.createElementNS( MAIL_NS, "body" );
mailElement.appendChild( bodyElement );
bodyElement.setTextContent( mailContent.toString());
// ... and send it to a mailing service.
try {
final Exchange mailExchange = jbiContext.getMessageSender().createExchange( MEPConstants.IN_ONLY_PATTERN );
mailExchange.setInterfaceName( new QName( "http://petals.ow2.org/components/mail/version-3", "Mail" ));
mailExchange.setService( new QName( "http://petals.ow2.org/components/mail/version-3", "ReportMailService" ));
mailExchange.setOperation(new QName("http://petals.ow2.org/components/mail/version-3", "SendMail"));
mailExchange.setInMessageContent( mailDocument );
// Synchronous invocation
jbiContext.getMessageSender().send( mailExchange );
} catch( MessagingException e ) {
Logger.getLogger( getClass().getName()).severe( "Failed to send a message to the Petals Mail component. Messaging error." );
} catch( PEtALSCDKException e ) {
Logger.getLogger( getClass().getName()).severe( "Failed to send a message to the Petals Mail component. Petals CDK error." );
}
}
}
{code}