1 22 23 package org.objectweb.petals.engine.helloworld; 24 25 import java.net.URI ; 26 import java.util.logging.Level ; 27 28 import javax.jbi.JBIException; 29 import javax.jbi.servicedesc.ServiceEndpoint; 30 import javax.naming.NameAlreadyBoundException ; 31 import javax.naming.NamingException ; 32 import javax.xml.namespace.QName ; 33 34 import org.objectweb.petals.component.common.HandlingException; 35 import org.objectweb.petals.component.common.MEPConstants; 36 import org.objectweb.petals.component.common.se.AbstractServiceEngine; 37 import org.objectweb.petals.component.common.util.MessageExchangeWrapper; 38 import org.objectweb.petals.component.common.util.WSDLHelper; 39 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions; 40 import org.w3c.dom.Document ; 41 42 public class HelloWorldEngine extends AbstractServiceEngine { 43 44 private static final String PRINT_MESS = "printMessage"; 45 46 private static final String BIND_MESS = "bindMessage"; 47 48 private static final String SAY_HELLO = "sayHello"; 49 50 private Helloworld helloworld; 51 52 private ServiceEndpoint endpoint; 53 54 private static final String INTERFACE = "HelloworldInterface"; 55 56 private static final String SERVICE = "HelloworldService"; 57 58 private static final String ENDPOINT = "HelloworldEndpoint"; 59 60 private static final QName SERVICE_NAME = new QName ( 61 "http://petals.objectweb.org/", SERVICE); 62 63 private static final QName INTERFACE_NAME = new QName ( 64 "http://petals.objectweb.org/", INTERFACE); 65 66 private Document desc; 67 68 @Override 69 protected boolean onExchange(final MessageExchangeWrapper exchange, 70 final Extensions extensions) throws HandlingException { 71 72 String outContent = null; 73 boolean outResponse = false; 74 75 String opName = exchange.getOperationName(); 77 78 URI pattern = exchange.getExchangePattern(); 80 81 String stringContent = exchange.getInMessageContent(); 83 84 if (PRINT_MESS.equalsIgnoreCase(opName) 85 && pattern.equals(MEPConstants.IN_ONLY_PATTERN.value())) { 86 helloworld.printMessage(stringContent); 87 } else if (BIND_MESS.equalsIgnoreCase(opName) 88 && pattern.equals(MEPConstants.IN_ONLY_PATTERN.value())) { 89 helloworld.bindMessage(stringContent); 90 } else if (SAY_HELLO.equalsIgnoreCase(opName) 91 && pattern.equals(MEPConstants.IN_OUT_PATTERN.value())) { 92 outContent = helloworld.sayHello(stringContent); 93 outResponse = true; 94 } else { 95 throw new HandlingException("Operation not allowed (" + opName 96 + ") with the following pattern (" + pattern + ")"); 97 } 98 99 if (outResponse) { 100 exchange.setOutMessageContent(outContent); 101 } 102 103 return outResponse; 104 } 105 106 @Override 107 public void start() throws JBIException { 108 super.start(); 109 try { 111 112 getContext().getNamingContext().createSubcontext( 113 HelloworldImpl.HELLOWORLD_CONTEXT); 114 115 } catch (NameAlreadyBoundException e) { 116 getLogger().log(Level.INFO, 117 "the HelloWorld jndi context is already bound."); 118 } catch (NamingException e) { 119 throw new JBIException(e); 120 } 121 122 desc = WSDLHelper.createLightWSDL20(INTERFACE_NAME, SERVICE_NAME, 123 ENDPOINT); 124 helloworld = new HelloworldImpl(getContext(), getLogger()); 126 127 endpoint = getContext().activateEndpoint(SERVICE_NAME, ENDPOINT); 129 } 130 131 @Override 132 protected String getResourceBundleName() { 133 return "hello"; 134 } 135 136 @Override 137 public void stop() throws JBIException { 138 super.stop(); 139 getContext().deactivateEndpoint(endpoint); 140 helloworld = null; 141 } 142 143 public Document getServiceDescription(final ServiceEndpoint endpoint) { 144 return desc; 145 } 146 147 } 148 | Popular Tags |