use of org.apache.cxf.service.Service in project cxf by apache.
the class DocLiteralInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("DocLiteralInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
MessageContentsList parameters = new MessageContentsList();
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
boolean client = isRequestor(message);
// operation anymore, just return
if (bop != null && !StaxUtils.toNextElement(xmlReader)) {
// body may be empty for partial response to decoupled request
return;
}
Service service = ServiceModelUtil.getService(message.getExchange());
bop = getBindingOperationInfo(xmlReader, exchange, bop, client);
boolean forceDocLitBare = false;
if (bop != null && bop.getBinding() != null) {
forceDocLitBare = Boolean.TRUE.equals(bop.getBinding().getService().getProperty("soap.force.doclit.bare"));
}
DataReader<XMLStreamReader> dr = getDataReader(message);
try {
if (!forceDocLitBare && bop != null && bop.isUnwrappedCapable()) {
ServiceInfo si = bop.getBinding().getService();
// Wrapped case
MessageInfo msgInfo = setMessage(message, bop, client, si);
setDataReaderValidation(service, message, dr);
// Determine if we should keep the parameters wrapper
if (shouldWrapParameters(msgInfo, message)) {
QName startQName = xmlReader.getName();
MessagePartInfo mpi = msgInfo.getFirstMessagePart();
if (!mpi.getConcreteName().equals(startQName)) {
throw new Fault("UNEXPECTED_WRAPPER_ELEMENT", LOG, null, startQName, mpi.getConcreteName());
}
Object wrappedObject = dr.read(mpi, xmlReader);
parameters.put(mpi, wrappedObject);
} else {
// Unwrap each part individually if we don't have a wrapper
bop = bop.getUnwrappedOperation();
msgInfo = setMessage(message, bop, client, si);
List<MessagePartInfo> messageParts = msgInfo.getMessageParts();
Iterator<MessagePartInfo> itr = messageParts.iterator();
// stuck
if (xmlReader.getEventType() == XMLStreamConstants.START_ELEMENT) {
StaxUtils.nextEvent(xmlReader);
}
// loop through each child element
getPara(xmlReader, dr, parameters, itr, message);
}
} else {
// Bare style
BindingMessageInfo msgInfo = null;
Endpoint ep = exchange.getEndpoint();
ServiceInfo si = ep.getEndpointInfo().getService();
if (bop != null) {
// for xml binding or client side
if (client) {
msgInfo = bop.getOutput();
} else {
msgInfo = bop.getInput();
if (bop.getOutput() == null) {
exchange.setOneWay(true);
}
}
if (msgInfo == null) {
return;
}
setMessage(message, bop, client, si, msgInfo.getMessageInfo());
}
final Collection<OperationInfo> operations = new ArrayList<>(si.getInterface().getOperations());
if (xmlReader == null || !StaxUtils.toNextElement(xmlReader)) {
// empty input
getBindingOperationForEmptyBody(operations, ep, exchange);
return;
}
setDataReaderValidation(service, message, dr);
int paramNum = 0;
do {
QName elName = xmlReader.getName();
MessagePartInfo p;
if (!client && msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().isEmpty()) {
// no input messagePartInfo
return;
}
if (msgInfo != null && msgInfo.getMessageParts() != null && msgInfo.getMessageParts().size() > 0) {
if (msgInfo.getMessageParts().size() > paramNum) {
p = msgInfo.getMessageParts().get(paramNum);
} else {
p = null;
}
} else {
p = findMessagePart(exchange, operations, elName, client, paramNum, message);
}
if (!forceDocLitBare) {
// Make sure the elName found on the wire is actually OK for
// the purpose we need it
validatePart(p, elName, message);
}
final Object o = dr.read(p, xmlReader);
if (forceDocLitBare && parameters.isEmpty()) {
// webservice provider does not need to ensure size
parameters.add(o);
} else {
parameters.put(p, o);
}
paramNum++;
if (message.getContent(XMLStreamReader.class) == null || o == xmlReader) {
xmlReader = null;
}
} while (xmlReader != null && StaxUtils.toNextElement(xmlReader));
}
message.setContent(List.class, parameters);
} catch (Fault f) {
if (!isRequestor(message)) {
f.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw f;
}
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class WrappedOutInterceptor method handleMessage.
public void handleMessage(Message message) {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop != null && bop.isUnwrapped()) {
XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);
MessageInfo messageInfo;
if (isRequestor(message)) {
messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
} else {
messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
}
QName name = messageInfo.getFirstMessagePart().getConcreteName();
try {
String pfx = null;
Service service = message.getExchange().getService();
if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
}
if (pfx == null) {
pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
}
xmlWriter.setPrefix(pfx, name.getNamespaceURI());
xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
if (StringUtils.isEmpty(pfx)) {
xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
} else {
xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
}
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
}
// Add a final interceptor to write end element
message.getInterceptorChain().add(ending);
}
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class SimpleBatchSTSClient method createClient.
protected void createClient() throws BusException, EndpointException {
if (client != null) {
return;
}
bus.getExtension(Configurer.class).configureBean(name, this);
if (wsdlLocation != null) {
WSDLServiceFactory factory = new WSDLServiceFactory(bus, wsdlLocation, serviceName);
SourceDataBinding dataBinding = new SourceDataBinding();
factory.setDataBinding(dataBinding);
Service service = factory.create();
service.setDataBinding(dataBinding);
EndpointInfo ei = service.getEndpointInfo(endpointName);
Endpoint endpoint = new EndpointImpl(bus, service, ei);
client = new ClientImpl(bus, endpoint);
} else {
Endpoint endpoint = STSUtils.createSTSEndpoint(bus, namespace, null, location, soapVersion, policy, endpointName);
client = new ClientImpl(bus, endpoint);
}
client.getInFaultInterceptors().addAll(inFault);
client.getInInterceptors().addAll(in);
client.getOutInterceptors().addAll(out);
client.getOutFaultInterceptors().addAll(outFault);
in = null;
out = null;
inFault = null;
outFault = null;
if (features != null) {
for (AbstractFeature f : features) {
f.initialize(client, bus);
}
}
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class BeanPostProcessorTest method verifyServices.
@Test
public void verifyServices() throws Exception {
JaxWsClientFactoryBean cf = new JaxWsClientFactoryBean();
cf.setAddress("local://services/Alger");
cf.setServiceClass(IWebServiceRUs.class);
Client client = cf.create();
String response = (String) client.invoke("consultTheOracle")[0];
assertEquals("All your bases belong to us.", response);
Service service = WebServiceRUs.getService();
assertEquals(JAXBDataBinding.class, service.getDataBinding().getClass());
}
use of org.apache.cxf.service.Service in project cxf by apache.
the class StaxToDOMSignatureIdentifierTest method testSignatureThumbprint.
@Test
public void testSignatureThumbprint() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SIGNATURE);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new TestPwdCallback());
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<>();
actions.add(XMLSecurityConstants.SIGNATURE);
properties.setActions(actions);
properties.setSignatureKeyIdentifier(WSSecurityTokenConstants.KEYIDENTIFIER_THUMBPRINT_IDENTIFIER);
properties.setSignatureUser("myalias");
Properties cryptoProperties = CryptoFactory.getProperties("outsecurity.properties", this.getClass().getClassLoader());
properties.setSignatureCryptoProperties(cryptoProperties);
properties.setCallbackHandler(new TestPwdCallback());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
Aggregations