use of javax.xml.ws.Holder in project camel by apache.
the class CxfProducer method checkParameterSize.
private void checkParameterSize(CxfEndpoint endpoint, Exchange exchange, Object[] parameters) {
BindingOperationInfo boi = getBindingOperationInfo(exchange);
if (boi == null) {
throw new RuntimeCamelException("Can't find the binding operation information from camel exchange");
}
if (!endpoint.isWrapped()) {
if (boi.isUnwrappedCapable()) {
boi = boi.getUnwrappedOperation();
}
}
int experctMessagePartsSize = boi.getInput().getMessageParts().size();
if (parameters.length < experctMessagePartsSize) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + experctMessagePartsSize + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
if (parameters.length > experctMessagePartsSize) {
// need to check the holder parameters
int holdersSize = 0;
for (Object parameter : parameters) {
if (parameter instanceof Holder) {
holdersSize++;
}
}
// need to check the soap header information
int soapHeadersSize = 0;
BindingMessageInfo bmi = boi.getInput();
if (bmi != null) {
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers != null) {
soapHeadersSize = headers.size();
}
}
if (holdersSize + experctMessagePartsSize + soapHeadersSize < parameters.length) {
throw new IllegalArgumentException("Get the wrong parameter size to invoke the out service, Expect size " + (experctMessagePartsSize + holdersSize + soapHeadersSize) + ", Parameter size " + parameters.length + ". Please check if the message body matches the CXFEndpoint POJO Dataformat request.");
}
}
}
use of javax.xml.ws.Holder in project camel by apache.
the class DefaultCxfBinding method getPayloadBodyElements.
protected static List<Source> getPayloadBodyElements(Message message, Map<String, String> nsMap) {
// take the namespace attribute from soap envelop
Map<String, String> bodyNC = CastUtils.cast((Map<?, ?>) message.get("soap.body.ns.context"));
if (bodyNC != null) {
// if there is no Node and the addNamespaceContext option is enabled, this map is available
nsMap.putAll(bodyNC);
} else {
Document soapEnv = (Document) message.getContent(Node.class);
if (soapEnv != null) {
NamedNodeMap attrs = soapEnv.getFirstChild().getAttributes();
for (int i = 0; i < attrs.getLength(); i++) {
Node node = attrs.item(i);
if (!node.getNodeValue().equals(Soap11.SOAP_NAMESPACE) && !node.getNodeValue().equals(Soap12.SOAP_NAMESPACE)) {
nsMap.put(node.getLocalName(), node.getNodeValue());
}
}
}
}
MessageContentsList inObjects = MessageContentsList.getContentsList(message);
if (inObjects == null) {
return new ArrayList<Source>(0);
}
org.apache.cxf.message.Exchange exchange = message.getExchange();
BindingOperationInfo boi = exchange.getBindingOperationInfo();
OperationInfo op = boi.getOperationInfo();
if (boi.isUnwrapped()) {
op = boi.getWrappedOperation().getOperationInfo();
}
List<MessagePartInfo> partInfos = null;
boolean client = Boolean.TRUE.equals(message.get(Message.REQUESTOR_ROLE));
if (client) {
// it is a response
partInfos = op.getOutput().getMessageParts();
} else {
// it is a request
partInfos = op.getInput().getMessageParts();
}
List<Source> answer = new ArrayList<Source>();
for (MessagePartInfo partInfo : partInfos) {
if (!inObjects.hasValue(partInfo)) {
continue;
}
Object part = inObjects.get(partInfo);
if (part instanceof Holder) {
part = ((Holder<?>) part).value;
}
if (part instanceof Source) {
Element element = null;
if (part instanceof DOMSource) {
element = getFirstElement(((DOMSource) part).getNode());
}
if (element != null) {
addNamespace(element, nsMap);
answer.add(new DOMSource(element));
} else {
answer.add((Source) part);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Extract body element {}", element == null ? "null" : getXMLString(element));
}
} else if (part instanceof Element) {
addNamespace((Element) part, nsMap);
answer.add(new DOMSource((Element) part));
} else {
if (LOG.isDebugEnabled()) {
LOG.debug("Unhandled part type '{}'", part.getClass());
}
}
}
return answer;
}
use of javax.xml.ws.Holder in project camel by apache.
the class AbstractCxfWsdlFirstTest method testInvokingServiceFromCXFClient.
@Test
public void testInvokingServiceFromCXFClient() throws Exception {
JaxwsTestHandler fromHandler = getMandatoryBean(JaxwsTestHandler.class, "fromEndpointJaxwsHandler");
fromHandler.reset();
JaxwsTestHandler toHandler = getMandatoryBean(JaxwsTestHandler.class, "toEndpointJaxwsHandler");
toHandler.reset();
URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
PersonService ss = new PersonService(wsdlURL, new QName("http://camel.apache.org/wsdl-first", "PersonService"));
Person client = ss.getSoap();
((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + getPort2() + "/" + getClass().getSimpleName() + "/PersonService/");
Holder<String> personId = new Holder<String>();
personId.value = "hello";
Holder<String> ssn = new Holder<String>();
Holder<String> name = new Holder<String>();
client.getPerson(personId, ssn, name);
assertEquals("we should get the right answer from router", "Bonjour", name.value);
personId.value = "";
try {
client.getPerson(personId, ssn, name);
fail("We expect to get the UnknowPersonFault here");
} catch (UnknownPersonFault fault) {
// We expect to get fault here
}
personId.value = "Invoking getPerson with invalid length string, expecting exception...xxxxxxxxx";
try {
client.getPerson(personId, ssn, name);
fail("We expect to get the WebSerivceException here");
} catch (WebServiceException ex) {
// Caught expected WebServiceException here
assertTrue("Should get the xml vaildate error! " + ex.getMessage(), ex.getMessage().indexOf("MyStringType") > 0 || ex.getMessage().indexOf("Could not parse the XML stream") != -1);
}
verifyJaxwsHandlers(fromHandler, toHandler);
}
use of javax.xml.ws.Holder in project camel by apache.
the class CXFWsdlOnlyPayloadModeMultiPartNoSpringTest method testMultiPartMessage.
@Test
public void testMultiPartMessage() {
URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
PersonMultiPartService ss = new PersonMultiPartService(wsdlURL, QName.valueOf(getServiceName()));
PersonMultiPartPortType client = ss.getPersonMultiPartPort();
((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port2 + "/CXFWsdlOnlyPayloadModeMultiPartNoSpringTest/PersonMultiPart");
Holder<Integer> ssn = new Holder<Integer>();
ssn.value = 0;
Holder<String> name = new Holder<String>();
name.value = "Unknown name";
client.getPersonMultiPartOperation("foo", 0, name, ssn);
assertEquals("New Person Name", name.value);
assertTrue(123456789 == ssn.value);
}
use of javax.xml.ws.Holder in project camel by apache.
the class CXFWsdlOnlyPayloadModeNoSpringTest method testRoutes.
@Test
public void testRoutes() throws Exception {
URL wsdlURL = getClass().getClassLoader().getResource("person.wsdl");
PersonService ss = new PersonService(wsdlURL, QName.valueOf(getServiceName()));
Person client = ss.getSoap();
Client c = ClientProxy.getClient(client);
((BindingProvider) client).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + port1 + "/" + getClass().getSimpleName() + "/PersonService");
c.getInInterceptors().add(new LoggingInInterceptor());
c.getOutInterceptors().add(new LoggingOutInterceptor());
Holder<String> personId = new Holder<String>();
personId.value = "hello";
Holder<String> ssn = new Holder<String>();
Holder<String> name = new Holder<String>();
client.getPerson(personId, ssn, name);
assertEquals("Bonjour", name.value);
}
Aggregations