/** * */ package org.acme.service; import java.io.StringWriter; import java.util.Arrays; import javax.xml.namespace.QName; import org.acme.sample.stubs.AnyElement; import org.acme.sample.stubs.AnyElementResponse; import org.acme.sample.stubs.Bar; import org.acme.sample.stubs.BarResponse; import org.acme.sample.stubs.Base; import org.acme.sample.stubs.Choice; import org.acme.sample.stubs.ChoiceResponse; import org.acme.sample.stubs.FooBulk; import org.acme.sample.stubs.FooBulkResponse; import org.acme.sample.stubs.FooWrapped; import org.acme.sample.stubs.FooWrappedResponse; import org.acme.sample.stubs.Nothing; import org.acme.sample.stubs.PolyResponse; import org.acme.sample.stubs.PolyWrapped; import org.acme.sample.stubs.SampleFault; import org.apache.axis.message.addressing.EndpointReferenceType; import org.gcube.common.core.contexts.GCUBEServiceContext; import org.gcube.common.core.contexts.GCUBEStatefulPortTypeContext; import org.gcube.common.core.faults.FaultUtils; import org.gcube.common.core.faults.GCUBEFault; import org.gcube.common.core.porttypes.GCUBEPortType; import org.gcube.common.core.state.GCUBEWSHome; import org.gcube.common.core.state.GCUBEWSResource; import org.gcube.common.core.state.GCUBEWSResourceKey; import org.gcube.common.core.types.VOID; import org.globus.wsrf.encoding.ObjectSerializer; /** * @author Fabio Simeoni * */ public class Stateless extends GCUBEPortType { public String foo(String s) { return s; } public FooWrappedResponse fooWrapped(FooWrapped wrapped) { return new FooWrappedResponse(wrapped.getParam()); } public FooWrappedResponse fooMixed(String s) { return new FooWrappedResponse(s); } public FooBulkResponse fooBulk(FooBulk bulk) { System.out.println(Arrays.asList(bulk.getParam())); return new FooBulkResponse(Arrays.deepToString(bulk.getParam())); } public Nothing nothing(Nothing n) { System.err.println("invoked NOTHING "+n); return new Nothing(); } public String fooFault(String flag) throws SampleFault, GCUBEFault { if (flag.equals("contingency")) throw new SampleFault(); else if (flag.equals("proper")) throw FaultUtils.newFault(new GCUBEFault(), new RuntimeException("generic problem")); else throw new RuntimeException("generic problem"); } public BarResponse bar(Bar s) { return new BarResponse(new String[] { s.getIn1(), s.getIn1() }); } public String baz(VOID v) { return "called"; } public EndpointReferenceType create(String input) { try { GCUBEStatefulPortTypeContext ptcxt = StatefulContext.getContext(); GCUBEWSHome home = ptcxt.getWSHome(); GCUBEWSResourceKey key = ptcxt.makeKey(input); GCUBEWSResource ws = home.create(key, input); ws.store(); return ws.getEPR(); } catch (Exception e) { throw new RuntimeException(e); } } public String createAsString(String input) { try { GCUBEStatefulPortTypeContext ptcxt = StatefulContext.getContext(); GCUBEWSHome home = ptcxt.getWSHome(); GCUBEWSResourceKey key = ptcxt.makeKey(input); GCUBEWSResource ws = home.create(key, input); ws.store(); StringWriter w = new StringWriter(); ObjectSerializer.serialize(w,ws.getEPR(), new QName("http://foo","test")); return w.toString(); } catch (Exception e) { throw new RuntimeException(e); } } public String any(Object o) { System.err.println(o); return o.getClass().getName(); } public AnyElementResponse anyElement(AnyElement o) { System.out.println(Arrays.deepToString(o.get_any())); return new AnyElementResponse(); } public PolyResponse poly(Base b) { System.err.println(b.getClass()); return new PolyResponse(); } public PolyResponse polyWrapped(PolyWrapped w) { System.err.println(w.getParam().getClass()); return new PolyResponse(); } public ChoiceResponse choice(Choice c) { System.err.println("one:"+c.getOne()); System.err.println("two:"+c.getTwo()); return new ChoiceResponse(); } /** {@inheritDoc} */ @Override public GCUBEServiceContext getServiceContext() { return ServiceContext.getContext(); } }