001: package org.objectweb.celtix.bus.bindings;
002:
003: import java.io.ByteArrayOutputStream;
004: import java.io.IOException;
005: import java.io.InputStream;
006: import java.io.OutputStream;
007:
008: import javax.wsdl.WSDLException;
009: import javax.xml.namespace.QName;
010: import javax.xml.ws.ServiceMode;
011: import javax.xml.ws.handler.MessageContext;
012:
013: import org.objectweb.celtix.Bus;
014: import org.objectweb.celtix.BusException;
015: import org.objectweb.celtix.bindings.AbstractBindingImpl;
016: import org.objectweb.celtix.bindings.AbstractServerBinding;
017: import org.objectweb.celtix.bindings.ServerBindingEndpointCallback;
018: import org.objectweb.celtix.context.InputStreamMessageContext;
019: import org.objectweb.celtix.context.MessageContextWrapper;
020: import org.objectweb.celtix.context.ObjectMessageContext;
021: import org.objectweb.celtix.context.OutputStreamMessageContext;
022: import org.objectweb.celtix.transports.ServerTransport;
023: import org.objectweb.celtix.transports.TransportFactory;
024: import org.objectweb.celtix.transports.TransportFactoryManager;
025: import org.objectweb.celtix.ws.addressing.EndpointReferenceType;
026:
027: public class TestServerBinding extends AbstractServerBinding {
028:
029: protected final AbstractBindingImpl binding;
030: String currentOperation = "undeclared";
031: String schemeName = "test";
032:
033: public TestServerBinding(Bus b, EndpointReferenceType ref,
034: ServerBindingEndpointCallback cbFactory) {
035: super (b, ref, cbFactory);
036: binding = new TestBinding(this );
037: }
038:
039: protected ServerTransport createTransport(EndpointReferenceType ref)
040: throws WSDLException, IOException {
041: TransportFactoryManager tfm = bus.getTransportFactoryManager();
042: String name = "http://celtix.objectweb.org/transports/test";
043: TransportFactory tf = null;
044: try {
045: tf = tfm.getTransportFactory(name);
046: } catch (BusException ex) {
047: // ignore
048: }
049: if (tf == null) {
050: tf = new TestTransportFactory();
051: try {
052: tfm.registerTransportFactory(name, tf);
053: } catch (BusException ex) {
054: System.out.println(ex.getMessage());
055: return null;
056: }
057: }
058: return tf.createServerTransport(ref);
059: }
060:
061: protected void unmarshal(MessageContext context,
062: ObjectMessageContext objContext) {
063: // populate object context with test data depending on current operation
064: // name
065: if ("greetMe".equals(currentOperation)) {
066: String name = System.getProperty("user.name");
067: objContext.setMessageObjects(name);
068: }
069: }
070:
071: protected void marshal(ObjectMessageContext objContext,
072: MessageContext context) {
073: }
074:
075: protected void marshalFault(ObjectMessageContext objContext,
076: MessageContext context) {
077: }
078:
079: protected void read(InputStreamMessageContext inCtx,
080: MessageContext context) throws IOException {
081: context.put(MessageContext.WSDL_OPERATION, new QName(
082: currentOperation));
083: }
084:
085: protected void write(MessageContext context,
086: OutputStreamMessageContext outCtx) throws IOException {
087: }
088:
089: public AbstractBindingImpl getBindingImpl() {
090: return binding;
091: }
092:
093: public boolean isCompatibleWithAddress(String address) {
094: return null != address && address.startsWith(schemeName);
095: }
096:
097: protected MessageContext invokeOnProvider(
098: MessageContext requestCtx, ServiceMode mode) {
099: return null;
100: }
101:
102: ServerTransport getTransport() {
103: return serverTransport();
104: }
105:
106: public void triggerTransport() {
107: if (transport instanceof TestServerTransport) {
108: TestServerTransport tsb = (TestServerTransport) transport;
109: tsb.fire();
110: }
111: }
112:
113: public QName getOperationName(MessageContext ctx) {
114: return new QName("", currentOperation);
115: }
116:
117: static class ToyInputStreamMessageContext extends
118: MessageContextWrapper implements InputStreamMessageContext {
119: private static final long serialVersionUID = 1;
120:
121: ToyInputStreamMessageContext(MessageContext wrapped) {
122: super (wrapped);
123: }
124:
125: public InputStream getInputStream() {
126: return null;
127: }
128:
129: public void setInputStream(InputStream ins) {
130: }
131:
132: public boolean isFault() {
133: return false;
134: }
135:
136: public void setFault(boolean isfault) {
137: }
138: }
139:
140: static class ToyOutputStreamMessageContext extends
141: MessageContextWrapper implements OutputStreamMessageContext {
142: private static final long serialVersionUID = 1;
143: private OutputStream outputStream;
144:
145: ToyOutputStreamMessageContext(MessageContext wrapped) {
146: super (wrapped);
147: }
148:
149: public OutputStream getOutputStream() {
150: if (null == outputStream) {
151: outputStream = new ByteArrayOutputStream();
152: }
153: return outputStream;
154: }
155:
156: public void setOutputStream(OutputStream os) {
157: outputStream = os;
158: }
159:
160: public boolean isFault() {
161: return false;
162: }
163:
164: public void setFault(boolean b) {
165: }
166:
167: public void setOneWay(boolean isOneWay) {
168: put(ONEWAY_MESSAGE_TF, isOneWay);
169: }
170:
171: public boolean isOneWay() {
172: return ((Boolean) get(ONEWAY_MESSAGE_TF)).booleanValue();
173: }
174:
175: public InputStreamMessageContext getCorrespondingInputStreamContext()
176: throws IOException {
177: return null;
178: }
179: }
180:
181: public boolean isBindingCompatible(String address) {
182: return address.contains("http:");
183: }
184:
185: }
|