public class Builder { private User sender = null; // Other properties public Builder sender( User sender ) { this.sender = sender; return this; } // Methods for other properties public Message build() { Message message = new Message(); message.setSender( sender ); // Set the other properties return message; } }
private HttpServletResponse getHttpResponseFromMessage(Message message) throws IOException { Object responseObj = message.get(HTTP_RESPONSE); if (responseObj instanceof HttpServletResponse) { return (HttpServletResponse)responseObj; } else if (null != responseObj) { String m = (new org.apache.cxf.common.i18n.Message("UNEXPECTED_RESPONSE_TYPE_MSG", LOG, responseObj.getClass())).toString(); LOG.log(Level.WARNING, m); throw new IOException(m); } else { String m = (new org.apache.cxf.common.i18n.Message("NULL_RESPONSE_MSG", LOG)).toString(); LOG.log(Level.WARNING, m); throw new IOException(m); } }
public void handleMessage(Message message) { BindingOperationInfo bop = message.getExchange().getBindingOperationInfo(); XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class); messageInfo = bop.getWrappedOperation().getOperationInfo().getInput(); } else { messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput(); QName name = messageInfo.getFirstMessagePart().getConcreteName(); Service service = message.getExchange().getService(); if (service.getDataBinding().getDeclaredNamespaceMappings() != null) { pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI()); pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false); xmlWriter.setPrefix(pfx, name.getNamespaceURI()); xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI()); if (StringUtils.isEmpty(pfx)) { throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
private void buildMessage(AbstractMessageContainer minfo, Message msg) { SchemaCollection schemas = minfo.getOperation().getInterface().getService() .getXmlSchemaCollection(); List<?> orderedParam = msg.getOrderedParts(null); for (Part part : cast(orderedParam, Part.class)) { MessagePartInfo pi = minfo.addMessagePart(new QName(minfo.getName().getNamespaceURI(), part .getName())); if (part.getTypeName() != null) { pi.setTypeQName(part.getTypeName()); pi.setElement(false); pi.setXmlSchema(schemas.getTypeByQName(part.getTypeName())); } else if (part.getElementName() != null) { pi.setElementQName(part.getElementName()); if (null == schemaElement) { org.apache.cxf.common.i18n.Message errorMessage = new org.apache.cxf.common.i18n.Message("WSDL4J_BAD_ELEMENT_PART", LOG, part.getName(), } else { org.apache.cxf.common.i18n.Message errorMessage = new org.apache.cxf.common.i18n.Message("PART_NO_NAME_NO_TYPE", LOG, part.getName());
private void writeMessage(Message message, QName name, boolean executeBare) { XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class); try { String pfx = name.getPrefix(); if (StringUtils.isEmpty(pfx)) { pfx = "ns1"; } StaxUtils.writeStartElement(xmlWriter, pfx, name.getLocalPart(), name.getNamespaceURI()); if (executeBare) { new BareOutInterceptor().handleMessage(message); } xmlWriter.writeEndElement(); } catch (XMLStreamException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE, e)); } } }
protected void checkForElement(ServiceInfo serviceInfo, MessagePartInfo mpi) { SchemaInfo si = getOrCreateSchema(serviceInfo, mpi.getElementQName().getNamespaceURI(), getQualifyWrapperSchema()); XmlSchemaElement e = si.getSchema().getElementByName(mpi.getElementQName().getLocalPart()); if (e != null) { mpi.setXmlSchema(e); return; } XmlSchema schema = si.getSchema(); si.setElement(null); //cached element is now invalid XmlSchemaElement el = new XmlSchemaElement(schema, true); el.setName(mpi.getElementQName().getLocalPart()); el.setNillable(true); XmlSchemaType tp = (XmlSchemaType)mpi.getXmlSchema(); if (tp == null) { throw new ServiceConstructionException(new Message("INTRACTABLE_PART", LOG, mpi.getName(), mpi.getMessageInfo().getName())); } el.setSchemaTypeName(tp.getQName()); mpi.setXmlSchema(el); }
protected void initializeWSDLOperationsForProvider() { Class<?> c = getProviderParameterType(getServiceClass()); if (c == null) { throw new ServiceConstructionException(new Message("INVALID_PROVIDER_EXC", LOG)); QName catchAll = new QName("http://cxf.apache.org/jaxws/provider", "invoke"); if (bop.isUnwrappedCapable()) { 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); inf.setTypeClass(c); break; 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();
public DomainExpression build(Element element) { loadDynamic(); DomainExpressionBuilder builder; QName qname = new QName(element.getNamespaceURI(), element.getLocalName()); builder = get(qname); if (null == builder) { throw new PolicyException(new Message("NO_DOMAINEXPRESSIONBUILDER_EXC", BUNDLE, qname.toString())); } return builder.build(element); } }
try { Definition def = wsdlManager.getDefinition(wsdlDocumentLocation); interfaceName = def.getService(serviceName).getPort(portName.getLocalPart()).getBinding() .getPortType().getQName(); } catch (Exception e) { JAXWSAConstants.WSA_REFERENCEPARAMETERS_NAME, JAXWSAConstants.NS_WSA); for (Element ele : referenceParameters) { StaxUtils.writeElement(ele, writer, true); ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation : wsdlDocumentLocation; writer.writeNamespace(JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.WSAM_INTERFACE_NAME, JAXWSAConstants.NS_WSAM); String portTypePrefix = interfaceName.getPrefix(); if (portTypePrefix == null || portTypePrefix.isEmpty()) { portTypePrefix = "ns1"; StaxUtils.writeElement(e, writer, true); StaxUtils.writeElement(e, writer, true); throw new WebServiceException(new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
private void writeWrapper(Message message, BindingOperationInfo bop, XMLStreamWriter xmlWriter) { if (bop.isUnwrapped()) { MessageInfo messageInfo; if (isRequestor(message)) { messageInfo = bop.getWrappedOperation().getOperationInfo().getInput(); } else { messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput(); } MessagePartInfo outPart = messageInfo.getMessageParts().get(0); QName name = outPart.getConcreteName(); try { String pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI()); xmlWriter.setPrefix(pfx, name.getNamespaceURI()); xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI()); xmlWriter.writeNamespace(pfx, name.getNamespaceURI()); } catch (XMLStreamException e) { throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e); } } }
if (portExtensors != null) { Iterator<ExtensibilityElement> extensionElements = portExtensors.iterator(); QName wsaEpr = new QName(Names.WSA_NAMESPACE_NAME, "EndpointReference"); while (extensionElements.hasNext()) { ExtensibilityElement ext = extensionElements.next(); if (ext instanceof UnknownExtensibilityElement && wsaEpr.equals(ext.getElementType())) { Element eprEle = ((UnknownExtensibilityElement)ext).getElement(); List<Element> addressElements = DOMUtils.getChildrenWithName(eprEle, throw new UnsupportedOperationException(new Message("GET_ENDPOINTREFERENCE_UNSUPPORTED_BINDING", LOG, bindingId).toString());
return; Endpoint ep = message.getExchange().getEndpoint(); XMLStreamReader xsr = message.getContent(XMLStreamReader.class); if (xsr == null) { return; if (!StaxUtils.toNextElement(reader)) { throw new Fault(new org.apache.cxf.common.i18n.Message("NO_OPERATION_ELEMENT", LOG)); Exchange ex = message.getExchange(); QName startQName = reader.getName(); if (startQName.getLocalPart().equals(XMLFault.XML_FAULT_ROOT)) { message.getInterceptorChain().abort(); BindingOperationInfo boi = ex.getBindingOperationInfo(); boolean isRequestor = isRequestor(message); if (boi == null) { xsr.nextTag(); } catch (XMLStreamException xse) { throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_READ_EXC", LOG));
private QName getPortTypeName(Class<?> serviceEndpointInterface) { Class<?> seiClass = serviceEndpointInterface; if (!serviceEndpointInterface.isAnnotationPresent(WebService.class)) { Message msg = new Message("SEI_NO_WEBSERVICE_ANNOTATION", BUNDLE, serviceEndpointInterface .getCanonicalName()); throw new WebServiceException(msg.toString()); seiClass = Thread.currentThread().getContextClassLoader().loadClass(epi); } catch (ClassNotFoundException e) { Message msg = new Message("COULD_NOT_LOAD_CLASS", BUNDLE, epi); throw new WebServiceException(msg.toString()); Message msg = new Message("SEI_NO_WEBSERVICE_ANNOTATION", BUNDLE, seiClass.getCanonicalName()); throw new WebServiceException(msg.toString()); return new QName(tns, name);
String partName = mpi.getConcreteName().getLocalPart(); String ct = (String) mpi.getProperty(Message.CONTENT_TYPE); int idx = mpi.getIndex(); Object o = outObjects.get(idx); throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_NOT_SUPPORTED", LOG, o.getClass()));
private void processInput(JavaMethod method, MessageInfo inputMessage) throws ToolException { if (requireOutOfBandHeader()) { try { Class.forName("org.apache.cxf.binding.soap.SoapBindingFactory"); } catch (Exception e) { LOG.log(Level.WARNING, new Message("SOAP_MISSING", LOG).toString()); } } JAXWSBinding mBinding = inputMessage.getOperation().getExtensor(JAXWSBinding.class); for (MessagePartInfo part : inputMessage.getMessageParts()) { if (isOutOfBandHeader(part) && !requireOutOfBandHeader()) { continue; } JavaParameter param = getParameterFromPart(method, part, JavaType.Style.IN); if (mBinding != null && mBinding.getJaxwsParas() != null) { for (JAXWSParameter jwp : mBinding.getJaxwsParas()) { if (part.getName().getLocalPart().equals(jwp.getPart())) { param.setName(jwp.getName()); } } } addParameter(part, method, param); } }
private void throwMultipleMultipleTypeException(Collection<QName> binds) throws Exception { StringBuilder sb = new StringBuilder(); org.apache.cxf.common.i18n.Message msgDef = new org.apache.cxf.common.i18n.Message("Multiple Bindings already defined in the wsdl", LOG); sb.append(msgDef.toString()); Iterator<QName> it2 = binds.iterator(); int cnt = 0; while (it2.hasNext()) { cnt++; sb.append(" " + cnt + " --> " + it2.next().getLocalPart()); } throw new Exception(sb.toString()); }
protected InterfaceInfo getInterfaceInfo() { if (getEndpointInfo() != null) { return getEndpointInfo().getInterface(); } QName qn = this.getInterfaceName(); for (ServiceInfo si : getService().getServiceInfos()) { if (qn.equals(si.getInterface().getName())) { return si.getInterface(); } } throw new ServiceConstructionException(new Message("COULD_NOT_FIND_PORTTYPE", LOG, qn)); }
protected void waitResponse(Exchange exchange) throws IOException { synchronized (exchange) { long remaining = synchronousTimeout; Long o = PropertyUtils.getLong(exchange.getOutMessage(), SYNC_TIMEOUT); if (o != null) { remaining = o; } while (!Boolean.TRUE.equals(exchange.get(FINISHED)) && remaining > 0) { long start = System.currentTimeMillis(); try { exchange.wait(remaining); } catch (InterruptedException ex) { // ignore } long end = System.currentTimeMillis(); remaining -= (int)(end - start); } if (!Boolean.TRUE.equals(exchange.get(FINISHED))) { LogUtils.log(LOG, Level.WARNING, "RESPONSE_TIMEOUT", exchange.get(OperationInfo.class).getName().toString()); String msg = new org.apache.cxf.common.i18n.Message("RESPONSE_TIMEOUT", LOG, exchange.get(OperationInfo.class) .getName().toString()) .toString(); throw new IOException(msg); } } }
public void handleMessage(JBIMessage message) throws Fault { Exchange ex = message.getExchange(); Endpoint ep = ex.get(Endpoint.class); BindingOperationInfo boi = ex.get(BindingOperationInfo.class); if (boi == null) { if (message.getJbiExchange().getOperation() != null) { BindingInfo service = ep.getEndpointInfo().getBinding(); boi = getBindingOperationInfo(service, message.getJbiExchange().getOperation()); if (boi == null) { throw new Fault(new Message("UNKNOWN_OPERATION", BUNDLE, message.getJbiExchange().getOperation().toString())); } } else { throw new Fault(new Message("UNKNOWN_OPERATION", BUNDLE, message.getJbiExchange().getInterfaceName().toString())); } ex.put(BindingOperationInfo.class, boi); ex.put(OperationInfo.class, boi.getOperationInfo()); ex.setOneWay(boi.getOperationInfo().isOneWay()); message.put(MessageInfo.class, boi.getInput().getMessageInfo()); } }