use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class SoapBindingFactoryTest method testFactory.
@Test
public void testFactory() throws Exception {
Definition d = createDefinition("/wsdl_soap/hello_world.wsdl");
Bus bus = getMockBus();
BindingFactoryManager bfm = getBindingFactoryManager(WSDLConstants.NS_SOAP11, bus);
bus.getExtension(BindingFactoryManager.class);
expectLastCall().andReturn(bfm).anyTimes();
DestinationFactoryManager dfm = control.createMock(DestinationFactoryManager.class);
expect(bus.getExtension(DestinationFactoryManager.class)).andStubReturn(dfm);
control.replay();
WSDLServiceBuilder builder = new WSDLServiceBuilder(bus);
ServiceInfo serviceInfo = builder.buildServices(d, new QName("http://apache.org/hello_world_soap_http", "SOAPService")).get(0);
BindingInfo bi = serviceInfo.getBindings().iterator().next();
assertTrue(bi instanceof SoapBindingInfo);
SoapBindingInfo sbi = (SoapBindingInfo) bi;
assertEquals("document", sbi.getStyle());
assertTrue(WSDLConstants.NS_SOAP11_HTTP_TRANSPORT.equalsIgnoreCase(sbi.getTransportURI()));
assertTrue(sbi.getSoapVersion() instanceof Soap11);
BindingOperationInfo boi = sbi.getOperation(new QName("http://apache.org/hello_world_soap_http", "sayHi"));
SoapOperationInfo sboi = boi.getExtensor(SoapOperationInfo.class);
assertNotNull(sboi);
assertEquals("document", sboi.getStyle());
assertEquals("", sboi.getAction());
BindingMessageInfo input = boi.getInput();
SoapBodyInfo bodyInfo = input.getExtensor(SoapBodyInfo.class);
assertEquals("literal", bodyInfo.getUse());
List<MessagePartInfo> parts = bodyInfo.getParts();
assertNotNull(parts);
assertEquals(1, parts.size());
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class SoapPreProtocolOutInterceptorTest method setUpBindingOperationInfo.
private BindingOperationInfo setUpBindingOperationInfo(String nsuri, String opreq, String opresp, Method method) {
ServiceInfo si = new ServiceInfo();
InterfaceInfo iinf = new InterfaceInfo(si, new QName(nsuri, method.getDeclaringClass().getSimpleName()));
OperationInfo opInfo = iinf.addOperation(new QName(nsuri, method.getName()));
opInfo.setProperty(Method.class.getName(), method);
opInfo.setInput(opreq, opInfo.createMessage(new QName(nsuri, opreq), Type.INPUT));
opInfo.setOutput(opresp, opInfo.createMessage(new QName(nsuri, opresp), Type.INPUT));
return new BindingOperationInfo(null, opInfo);
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JAXBEncoderDecoderTest method testMarshallExceptionWithOrder.
@Test
public void testMarshallExceptionWithOrder() throws Exception {
Document doc = DOMUtils.getEmptyDocument();
Element elNode = doc.createElementNS("http://cxf.apache.org", "ExceptionRoot");
OrderException exception = new OrderException("Mymessage");
exception.setAValue("avalue");
exception.setDetail("detail");
exception.setInfo1("info1");
exception.setInfo2("info2");
exception.setIntVal(10000);
QName elName = new QName("http://cxf.apache.org", "OrderException");
ServiceInfo serviceInfo = new ServiceInfo();
InterfaceInfo interfaceInfo = new InterfaceInfo(serviceInfo, null);
OperationInfo op = interfaceInfo.addOperation(new QName("http://cxf.apache.org", "operation"));
MessageInfo message = new MessageInfo(op, null, null);
MessagePartInfo part = new MessagePartInfo(elName, message);
part.setElement(true);
part.setElementQName(elName);
part.setTypeClass(OrderException.class);
// just need a simple generic context to handle the exceptions internal primitives
JAXBContext exceptionContext = JAXBContext.newInstance(new Class[] { String.class });
JAXBEncoderDecoder.marshallException(exceptionContext.createMarshaller(), exception, part, elNode);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
StaxUtils.writeTo(elNode, bout);
int a = bout.toString().lastIndexOf("aValue");
int b = bout.toString().lastIndexOf("detail");
int c = bout.toString().lastIndexOf("info1");
int d = bout.toString().lastIndexOf("info2");
int e = bout.toString().lastIndexOf("intVal");
assertTrue(a < b);
assertTrue(b < c);
assertTrue(c < d);
assertTrue(d < e);
assertTrue(bout.toString().indexOf("transientValue") < 0);
assertTrue(bout.toString(), bout.toString().indexOf("mappedField=\"MappedField\"") > 0);
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class CodeFirstWSDLTest method testDocumentationOnImpl.
@Test
public void testDocumentationOnImpl() throws Exception {
// CXF-3092
EndpointImpl ep = (EndpointImpl) Endpoint.publish("local://foo", new CXF3092Impl());
ServiceWSDLBuilder wsdlBuilder = new ServiceWSDLBuilder(bus, ep.getService().getServiceInfos().get(0));
Definition def = wsdlBuilder.build();
Document d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
// org.apache.cxf.helpers.XMLUtils.printDOM(d);
assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
JaxwsServiceBuilder builder = new JaxwsServiceBuilder();
builder.setServiceClass(CXF3092Impl.class);
ServiceInfo serviceInfo = builder.createService();
wsdlBuilder = new ServiceWSDLBuilder(bus, serviceInfo);
def = wsdlBuilder.build();
d = bus.getExtension(WSDLManager.class).getWSDLFactory().newWSDLWriter().getDocument(def);
// org.apache.cxf.helpers.XMLUtils.printDOM(d);
assertXPathEquals("//wsdl:definitions/wsdl:documentation", "My top level documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:service/wsdl:documentation", "My Service documentation", d.getDocumentElement());
assertXPathEquals("//wsdl:definitions/wsdl:binding/wsdl:documentation", "My binding doc", d.getDocumentElement());
}
use of org.apache.cxf.service.model.ServiceInfo in project cxf by apache.
the class JaxWsServiceFactoryBean method initializeWSDLOperationsForProvider.
protected void initializeWSDLOperationsForProvider() {
Class<?> c = getProviderParameterType(getServiceClass());
if (c == null) {
throw new ServiceConstructionException(new Message("INVALID_PROVIDER_EXC", LOG));
}
if (getEndpointInfo() == null && isFromWsdl()) {
// most likely, they specified a WSDL, but for some reason
// did not give a valid ServiceName/PortName. For provider,
// we'll allow this since everything is bound directly to
// the invoke method, however, this CAN cause other problems
// such as addresses in the wsdl not getting updated and such
// so we'll WARN about it.....
List<QName> enames = new ArrayList<>();
for (ServiceInfo si : getService().getServiceInfos()) {
for (EndpointInfo ep : si.getEndpoints()) {
enames.add(ep.getName());
}
}
LOG.log(Level.WARNING, "COULD_NOT_FIND_ENDPOINT", new Object[] { getEndpointName(), enames });
}
try {
Method invoke = getServiceClass().getMethod("invoke", c);
QName catchAll = new QName("http://cxf.apache.org/jaxws/provider", "invoke");
// Bind every operation to the invoke method.
for (ServiceInfo si : getService().getServiceInfos()) {
si.setProperty("soap.force.doclit.bare", Boolean.TRUE);
if (!isFromWsdl()) {
for (EndpointInfo ei : si.getEndpoints()) {
ei.setProperty("soap.no.validate.parts", Boolean.TRUE);
}
}
for (BindingInfo bind : si.getBindings()) {
for (BindingOperationInfo bop : bind.getOperations()) {
OperationInfo o = bop.getOperationInfo();
if (bop.isUnwrappedCapable()) {
// force to bare, no unwrapping
bop.getOperationInfo().setUnwrappedOperation(null);
bop.setUnwrappedOperation(null);
}
if (o.getInput() != null) {
final List<MessagePartInfo> messageParts;
if (o.getInput().getMessagePartsNumber() == 0) {
MessagePartInfo inf = o.getInput().addMessagePart(o.getName());
inf.setConcreteName(o.getName());
messageParts = o.getInput().getMessageParts();
bop.getInput().setMessageParts(messageParts);
} else {
messageParts = o.getInput().getMessageParts();
}
for (MessagePartInfo inf : messageParts) {
inf.setTypeClass(c);
break;
}
}
if (o.getOutput() != null) {
final List<MessagePartInfo> messageParts;
if (o.getOutput().getMessagePartsNumber() == 0) {
MessagePartInfo inf = o.getOutput().addMessagePart(o.getName());
inf.setConcreteName(new QName(o.getName().getNamespaceURI(), o.getName().getLocalPart() + "Response"));
messageParts = o.getOutput().getMessageParts();
bop.getOutput().setMessageParts(messageParts);
} else {
messageParts = o.getOutput().getMessageParts();
}
for (MessagePartInfo inf : messageParts) {
inf.setTypeClass(c);
break;
}
}
getMethodDispatcher().bind(o, invoke);
}
BindingOperationInfo bop = bind.getOperation(catchAll);
if (bop == null) {
OperationInfo op = bind.getInterface().getOperation(catchAll);
if (op == null) {
op = bind.getInterface().addOperation(catchAll);
String name = catchAll.getLocalPart();
MessageInfo mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Request"), MessageInfo.Type.INPUT);
op.setInput(catchAll.getLocalPart() + "Request", mInfo);
MessagePartInfo mpi = mInfo.addMessagePart("parameters");
mpi.setElement(true);
mpi.setTypeClass(c);
mpi.setTypeQName(Constants.XSD_ANYTYPE);
mInfo = op.createMessage(new QName(catchAll.getNamespaceURI(), name + "Response"), MessageInfo.Type.OUTPUT);
op.setOutput(name + "Response", mInfo);
mpi = mInfo.addMessagePart("parameters");
mpi.setElement(true);
mpi.setTypeClass(c);
mpi.setTypeQName(Constants.XSD_ANYTYPE);
BindingOperationInfo bo = new BindingOperationInfo(bind, op);
op.setProperty("operation.is.synthetic", Boolean.TRUE);
bo.setProperty("operation.is.synthetic", Boolean.TRUE);
bind.addOperation(bo);
}
}
}
}
} catch (SecurityException | NoSuchMethodException e) {
throw new ServiceConstructionException(e);
}
}
Aggregations