ObjectFactory factory = new ObjectFactory(); JAXBElement<String> createMessageDescription = factory.createMessageDescription("description"); message.setDescription(createMessageDescription);
ObjectFactory factory = new ObjectFactory(); XhtmlHtmlType html = factory.createXhtmlHtmlType(); XhtmlHeadType head = factory.createXhtmlHeadType(); html.setHead(head); XhtmlStyleType style = factory.createXhtmlStyleType(); head.getContent().add(factory.createXhtmlHeadTypeStyle(style));
ObjectFactory objectFactory = new ObjectFactory(); JAXBElement<String> jaxbElement = objectFactory.createAmount("Hello World");
protected String getBasePath(String contextPath) throws IOException { return contextPath + getAddress().getAddress().getValue(); }
private void extractWsdlEprs(EndpointInfo endpoint) { //parse the EPR in wsdl List<ExtensibilityElement> portExtensors = endpoint.getExtensors(ExtensibilityElement.class); 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())) { DOMSource domSource = new DOMSource(((UnknownExtensibilityElement)ext).getElement()); W3CEndpointReference w3cEPR = new W3CEndpointReference(domSource); EndpointReferenceType ref = ProviderImpl.convertToInternal(w3cEPR); endpoint.getTarget().setMetadata(ref.getMetadata()); endpoint.getTarget().setReferenceParameters(ref.getReferenceParameters()); endpoint.getTarget().getOtherAttributes().putAll(ref.getOtherAttributes()); } } } }
private boolean isWSAddressingReplyToSpecified(Exchange ex) { AddressingProperties map = ContextUtils.retrieveMAPs(ex.getInMessage(), false, false, false); return map != null && !ContextUtils.isGenericAddress(map.getReplyTo()); } };
public final void resolveFeatures() { AddressingFeature addressing = getAddressingFeature(); if (addressing == null) { return; } if (addressing.isEnabled()) { WSAddressingFeature feature = getWSAddressingFeature(); if (feature == null) { feature = new WSAddressingFeature(); addAddressingFeature(feature); } feature.setAddressingRequired(addressing.isRequired()); feature.setResponses(addressing.getResponses().toString()); } else { removeAddressingFeature(); getEndpointInfo().setProperty("org.apache.cxf.ws.addressing.MAPAggregator.addressingDisabled", Boolean.TRUE); } }
WSAddressingFeature feature = new WSAddressingFeature(); if (addressingRequired(bindingExtensors) || addressingRequired(portExtensors)) { feature.setAddressingRequired(true);
@Override public <T> Dispatch<T> createDispatch(EndpointReference endpointReference, Class<T> type, Mode mode, WebServiceFeature... features) { EndpointReferenceType ref = ProviderImpl.convertToInternal(endpointReference); QName portName = EndpointReferenceUtils.getPortQName(ref, bus); updatePortInfoAddress(portName, EndpointReferenceUtils.getAddress(ref)); return createDispatch(portName, type, mode, features); }
public EndpointReferenceType getAddressWithId(String id) { EndpointReferenceType ref = null; if (isMultiplexWithAddress()) { String address = EndpointReferenceUtils.getAddress(reference); ref = EndpointReferenceUtils.duplicate(reference); if (address.endsWith("/")) { EndpointReferenceUtils.setAddress(ref, address + id); } else { EndpointReferenceUtils.setAddress(ref, address + "/" + id); } } else { ref = super.getAddressWithId(id); } return ref; }
public <T> T getPort(EndpointReferenceType endpointReference, Class<T> type, WebServiceFeature... features) { endpointReference = EndpointReferenceUtils.resolve(endpointReference, bus); QName serviceQName = EndpointReferenceUtils.getServiceName(endpointReference, bus); String portName = EndpointReferenceUtils.getPortName(endpointReference); QName portQName = null; if (portName != null && serviceQName != null) { String ns = serviceQName.getNamespaceURI(); if (StringUtils.isEmpty(ns)) { //hack to workaround a xalan bug for (QName qn : portInfos.keySet()) { if (portName.equals(qn.getLocalPart())) { ns = qn.getNamespaceURI(); } } } if (StringUtils.isEmpty(ns) && serviceName != null) { ns = serviceName.getNamespaceURI(); } portQName = new QName(ns, portName); } return createPort(portQName, endpointReference, type, features); }
ObjectFactory objFactory = new ObjectFactory(); MyRootElement root = objFactory.createMyRootElement(); ... // Set root properties ... if (!writeDocument(objFactory.createMyRootElement(root), output)) { System.err.println("Failed to marshal XML document"); } ... private boolean writeDocument(JAXBElement document, OutputStream output) { Class<?> clazz = document.getValue().getClass(); try { JAXBContext context = JAXBContext.newInstance(clazz.getPackage().getName()); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(document, output); return true; } catch (JAXBException e) { e.printStackTrace(System.err); return false; } }
private static class SingletonObjectFactoryHolder{ private static final ObjectFactory INSTANCE; static { try { INSTANCE = new ObjectFactory(); } catch (Exception e) { throw new ExceptionInInitializerError(e); } } }
private void validatePossibleFault(Message message, BindingOperationInfo bop, Node ds) { Element el = DOMUtils.getFirstElement(ds); if (!"Fault".equals(el.getLocalName())) { return; } message.put(Message.RESPONSE_CODE, 500); el = DOMUtils.getFirstElement(el); while (el != null && !"detail".equals(el.getLocalName())) { el = DOMUtils.getNextElement(el); } if (el != null) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); try { validateFaultDetail(el, schema, bop); } catch (Exception e) { throw new Fault(e); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } } private void validateFaultDetail(Element detail, Schema schema, BindingOperationInfo bop) throws Exception {
protected String getBasePath(String contextPath) throws IOException { String address = getAddress().getAddress().getValue(); if (address == null) { return contextPath; } if (address.startsWith("http")) { return URI.create(address).getPath(); } return contextPath + address; }
@Override public Dispatch<Object> createDispatch(EndpointReference endpointReference, JAXBContext context, Mode mode, WebServiceFeature... features) { EndpointReferenceType ref = ProviderImpl.convertToInternal(endpointReference); QName portName = EndpointReferenceUtils.getPortQName(ref, bus); updatePortInfoAddress(portName, EndpointReferenceUtils.getAddress(ref)); return createDispatch(portName, context, mode, features); }
private void validateFault(SoapMessage message, SOAPFault fault, BindingOperationInfo bop) { if (ServiceUtils.isSchemaValidationEnabled(SchemaValidationType.OUT, message)) { Schema schema = EndpointReferenceUtils.getSchema(message.getExchange().getService() .getServiceInfos().get(0), message.getExchange().getBus()); Detail d = fault.getDetail(); try { validateFaultDetail(d, schema, bop); } catch (Exception e) { throw new SoapFault(e.getMessage(), e, message.getVersion().getReceiver()); } //We validated what we can from a fault standpoint message.put(Message.SCHEMA_VALIDATION_ENABLED, Boolean.FALSE); } }
/** * @return the default target address */ public String getAddress() { if (defaultAddress != null) { return defaultAddress.getString(); } else if (fromEndpointReferenceType) { return getTarget().getAddress().getValue(); } return endpointInfo.getAddress(); }
private Address setAndGetDefaultAddress() throws URISyntaxException { if (defaultAddress == null) { synchronized (this) { if (defaultAddress == null) { if (fromEndpointReferenceType && getTarget().getAddress().getValue() != null) { defaultAddress = new Address(this.getTarget().getAddress().getValue()); } else if (endpointInfo.getAddress() != null) { defaultAddress = new Address(endpointInfo.getAddress()); } } } } return defaultAddress; }
protected void updateDestination(HttpServletRequest request, String base, AbstractHTTPDestination d) { String ad = d.getEndpointInfo().getAddress(); if (ad == null && d.getAddress() != null && d.getAddress().getAddress() != null) { ad = d.getAddress().getAddress().getValue(); if (ad == null) { ad = "/"; } } // Using HTTP_PREFIX check is safe for ServletController // URI.create(ad).isRelative() can be used - a bit more expensive though if (ad != null && !ad.startsWith(HTTP_PREFIX)) { if (disableAddressUpdates) { request.setAttribute("org.apache.cxf.transport.endpoint.address", base + ad); } else { BaseUrlHelper.setAddress(d, base + ad); } } }