private EndpointReference determineEndpointReference(String serviceName) throws ParserConfigurationException { Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); Element eprNode = doc.createElementNS( "http://www.w3.org/2005/08/addressing", "EndpointReference"); Element addressNode = doc.createElement("Address"); Element metadataNode = doc.createElement("Metadata"); String wsdlURL = remoteWSDLUrl.replace("{service}", serviceName); addressNode.setTextContent(wsdlURL); doc.appendChild(eprNode); eprNode.appendChild(addressNode); eprNode.appendChild(metadataNode); EndpointReference epr = EndpointReference.readFrom(new DOMSource(doc)); return epr; }
public <T> T getPort(Service service, Class<T> serviceClass) throws ParserConfigurationException { // and determine the real endpoint belonging to the provisioning // URL, and create the port based on it. Doing so, we omit // parsing the remote WSDL twice and also related authentication // problems EndpointReference epr = determineEndpointReference(); T port = service.getPort(epr, serviceClass); if (requiresUserAuthentication(userName, password)) { BindingProvider bindingProvider = (BindingProvider) port; Map<String, Object> clientRequestContext = bindingProvider .getRequestContext(); clientRequestContext.put(BindingProvider.USERNAME_PROPERTY, userName); clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY, password); } return port; }
/** * Creates an end point reference corresponding to the service defined for * the technical product. * * @return The endpoint reference. * @throws ParserConfigurationException */ private EndpointReference determineEndpointReference() throws ParserConfigurationException { Document doc = DocumentBuilderFactory.newInstance() .newDocumentBuilder().newDocument(); Element eprNode = doc.createElementNS( "http://www.w3.org/2005/08/addressing", "EndpointReference"); Element addressNode = doc.createElement("Address"); Element metadataNode = doc.createElement("Metadata"); addressNode.setTextContent(details.getEndpointURL()); doc.appendChild(eprNode); eprNode.appendChild(addressNode); eprNode.appendChild(metadataNode); EndpointReference epr = EndpointReference.readFrom(new DOMSource(doc)); return epr; }
/** * Gives the EPR based on the clazz. It may need to perform tranformation from * W3C EPR to MS EPR or vise-versa. */ public static <T extends EndpointReference> T transform(Class<T> clazz, @NotNull EndpointReference epr) { assert epr != null; if (clazz.isAssignableFrom(W3CEndpointReference.class)) { if (epr instanceof W3CEndpointReference) { return (T) epr; } else if (epr instanceof MemberSubmissionEndpointReference) { return (T) toW3CEpr((MemberSubmissionEndpointReference) epr); } } else if (clazz.isAssignableFrom(MemberSubmissionEndpointReference.class)) { if (epr instanceof W3CEndpointReference) { return (T) toMSEpr((W3CEndpointReference) epr); } else if (epr instanceof MemberSubmissionEndpointReference) { return (T) epr; } } //This must be an EPR that we dont know throw new WebServiceException("Unknwon EndpointReference: " + epr.getClass()); }
/** * Determines the reference to a web service provided by a technical * service. * * @param <T> * The type of service obtained. * @param localWsdlUrl * The URL to a local service-related WSDL. The WSDL should be * provided as file in a bundled .jar file. * @param serviceClass * The service class implemented by the WSDL. * @return The web service reference. * @throws ParserConfigurationException * @throws WebServiceException * Has to be caught by a caller, although it's a runtime * exception */ public <T> T getPort(URL localWsdlUrl, Class<T> serviceClass) throws ParserConfigurationException, WebServiceException { Service service = getService(localWsdlUrl, serviceClass); EndpointReference epr = determineEndpointReference(); T port = service.getPort(epr, serviceClass); if (requiresUserAuthentication(userName, password)) { BindingProvider bindingProvider = (BindingProvider) port; Map<String, Object> clientRequestContext = bindingProvider .getRequestContext(); clientRequestContext.put(BindingProvider.USERNAME_PROPERTY, userName); clientRequestContext.put(BindingProvider.PASSWORD_PROPERTY, password); } return port; }
private void assertEndpointReference(EndpointReference epr) throws Exception { assertEquals(W3CEndpointReference.class.getName(), epr.getClass().getName()); Element endpointReference = DOMUtils.parse(epr.toString()); assertEquals("EndpointReference", endpointReference.getNodeName()); assertEquals("http://www.w3.org/2005/08/addressing", endpointReference.getAttribute("xmlns")); NodeList addresses = endpointReference.getElementsByTagName("Address"); assertEquals(1, addresses.getLength()); URL eprAddress = new URL(addresses.item(0).getFirstChild().getNodeValue()); URL ENDPOINT_ADDRESS = new URL(baseURL.toString() + "/jaxws-endpointReference"); //compare hosts' IPs String eprAddressHost = InetAddress.getByName(eprAddress.getHost()).getHostAddress(); String endpointAddressHost = InetAddress.getByName(ENDPOINT_ADDRESS.getHost()).getHostAddress(); assertEquals(eprAddressHost, endpointAddressHost); assertEquals(ENDPOINT_ADDRESS.toString().replace(ENDPOINT_ADDRESS.getHost(), eprAddress.getHost()), eprAddress.toString()); }
@Test @RunAsClient public void testToString() throws Exception { String XML_SOURCE = "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n" + "<EndpointReference xmlns='http://www.w3.org/2005/08/addressing'>\n" + " <Address>http://localhost:8080/jaxws-endpointReference</Address>\n" + " <Metadata\n" + " wsdli:wsdlLocation='http://org.jboss.ws/endpointReference http://localhost:8080/jaxws-endpointReference?wsdl'\n" + " xmlns:wsdli='http://www.w3.org/ns/wsdl-instance'>\n" + " <wsam:InterfaceName xmlns:wsam='http://www.w3.org/2005/08/addressing' xmlns:wsns='http://org.jboss.ws/endpointReference'>wsns:Endpoint</wsam:InterfaceName>\n" + " <wsam:ServiceName xmlns:wsam='http://www.w3.org/2005/08/addressing' xmlns:wsns='http://org.jboss.ws/endpointReference' xmlns='' EndpointName='HelloPort'>wsns:EndpointService</wsam:ServiceName>\n" + " </Metadata>\n" + "</EndpointReference>\n"; assertTrue("lost xmlns:wsns namespace declaration", this.getXML(XML_SOURCE).indexOf("xmlns:wsns") != -1); StreamSource source = new StreamSource(new StringReader(XML_SOURCE)); EndpointReference epRef = EndpointReference.readFrom(source); assertTrue("lost xmlns:wsns namespace declaration", epRef.toString().indexOf("xmlns:wsns") != -1); }
public String sayHello() { log.info("Current context: " + ctx); try { EndpointReference epr = ctx.getEndpointReference(); log.info("Endpoint reference: " + epr); if (epr == null || !epr.toString().contains("jbws2257")) { return "Unexpected endpoint reference: " + epr; } } catch (Exception e) { log.error("Error while reading endpoint reference from context!", e); return e.getMessage(); } return "Hello World!"; }
private void assertEndpointReference(EndpointReference epr, String refPar, DocumentBuilder builder) throws IOException { Logger.getLogger(this.getClass()).info("epr: "+epr); assert(W3CEndpointReference.class.getName().equals(epr.getClass().getName())); Element endpointReference = DOMUtils.parse(epr.toString(), builder); assert("EndpointReference".equals(endpointReference.getNodeName())); assert("http://www.w3.org/2005/08/addressing".equals(endpointReference.getAttribute("xmlns"))); NodeList addresses = endpointReference.getElementsByTagName("Address"); assert(addresses.getLength() == 1); assert(("http://" + hostName + ":8082/jaxws-endpoint").equals(addresses.item(0).getFirstChild().getNodeValue())); if (refPar != null) { Element refEle = DOMUtils.parse(refPar, builder); NodeList nodeList = endpointReference.getElementsByTagNameNS(refEle.getNamespaceURI(), refEle.getLocalName()); assert(nodeList.getLength() == 1); assert(refEle.getTextContent().equals(nodeList.item(0).getTextContent())); } }
@Override public EndpointReference getEndpointReference(Element... referenceParameters) { ClassLoader origClassLoader = getContextClassLoader(); boolean restoreTCCL = false; try { restoreTCCL = checkAndFixContextClassLoader(origClassLoader); return delegate.getEndpointReference(referenceParameters); } finally { if (restoreTCCL) setContextClassLoader(origClassLoader); } }
@Override public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element... referenceParameters) { ClassLoader origClassLoader = getContextClassLoader(); boolean restoreTCCL = false; try { restoreTCCL = checkAndFixContextClassLoader(origClassLoader); return delegate.getEndpointReference(clazz, referenceParameters); } finally { if (restoreTCCL) setContextClassLoader(origClassLoader); } }
@Override public UserProfileServiceWS newUserProfileService(String endpoint, String endpointChangeService, Map<String, List<String>> requestHeaders) { EndpointReference endpointRef = new W3CEndpointReferenceBuilder() .address(endpoint).build(); EndpointReference endpointChangeRef = new W3CEndpointReferenceBuilder() .address(endpointChangeService).build(); UserProfileServiceSoap inUserProfileServiceSoap = userProfileServiceSoap.getPort( endpointRef, UserProfileServiceSoap.class); UserProfileChangeServiceSoap inUserProfileChangeServiceSoap = userProfileChangeServiceSoap.getPort( endpointChangeRef, UserProfileChangeServiceSoap.class); ((BindingProvider) inUserProfileServiceSoap).getRequestContext().put( MessageContext.HTTP_REQUEST_HEADERS, requestHeaders); ((BindingProvider) inUserProfileChangeServiceSoap).getRequestContext() .put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders); addSocketTimeoutConfiguration((BindingProvider) inUserProfileServiceSoap); addSocketTimeoutConfiguration( (BindingProvider) inUserProfileChangeServiceSoap); return new SharePointUserProfileServiceWS(inUserProfileServiceSoap, inUserProfileChangeServiceSoap); }
public EndpointReference getEndpointReference(Element... referenceParameters) { org.apache.cxf.message.Message msg = getWrappedMessage(); Endpoint ep = msg.getExchange().get(Endpoint.class); W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder(); builder.address(ep.getEndpointInfo().getAddress()); builder.serviceName(ep.getService().getName()); builder.endpointName(ep.getEndpointInfo().getName()); if (referenceParameters != null) { for (Element referenceParameter : referenceParameters) { builder.referenceParameter(referenceParameter); } } return builder.build(); }
/** * Creates from the spec version of {@link EndpointReference}. * * <p> * This method performs the data conversion, so it's slow. * Do not use this method in a performance critical path. */ public WSEndpointReference(EndpointReference epr, AddressingVersion version) { try { MutableXMLStreamBuffer xsb = new MutableXMLStreamBuffer(); epr.writeTo(new XMLStreamBufferResult(xsb)); this.infoset = xsb; this.version = version; this.rootElement = new QName("EndpointReference", version.nsUri); parse(); } catch (XMLStreamException e) { throw new WebServiceException(ClientMessages.FAILED_TO_PARSE_EPR(epr),e); } }
/** * Converts from {@link EndpointReference}. * * This handles null {@link EndpointReference} correctly. * Call {@link #WSEndpointReference(EndpointReference)} directly * if you know it's not null. */ public static @Nullable WSEndpointReference create(@Nullable EndpointReference epr) { if (epr != null) { return new WSEndpointReference(epr); } else { return null; } }
public EPR(Class<? extends EndpointReference> eprClass, String address, String serviceName, String portName, String portTypeName, QName wsdlMetadata, String referenceParameters, String referenceProperties) { this.eprClass = eprClass; this.address = address; this.serviceName = serviceName; this.portName = portName; this.portTypeName = portTypeName; this.referenceParameters = referenceParameters; this.referenceProperties = referenceProperties; this.wsdlMetadata = wsdlMetadata; }
public EndpointReference readEndpointReference(final Source eprInfoset) { try { Unmarshaller unmarshaller = eprjc.get().createUnmarshaller(); return (EndpointReference) unmarshaller.unmarshal(eprInfoset); } catch (JAXBException e) { throw new WebServiceException("Error creating Marshaller or marshalling.", e); } }
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, String address, String wsdlAddress, Element... referenceParameters) { List<Element> refParams = null; if (referenceParameters != null) { refParams = Arrays.asList(referenceParameters); } return getEndpointReference(clazz, address, wsdlAddress, null, refParams); }
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, String address, String wsdlAddress, List<Element> metadata, List<Element> referenceParameters) { QName portType = null; if (port != null) { portType = port.getBinding().getPortTypeName(); } AddressingVersion av = AddressingVersion.fromSpecClass(clazz); return new WSEndpointReference( av, address, serviceName, portName, portType, metadata, wsdlAddress, referenceParameters, endpointReferenceExtensions.values(), null).toSpec(clazz); }
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, Element...referenceParameters) { Packet packet = getRequestPacket(); if (packet == null) { throw new IllegalStateException("getEndpointReference() can only be called while servicing a request"); } String address = packet.webServiceContextDelegate.getEPRAddress(packet, endpoint); String wsdlAddress = null; if(endpoint.getServiceDefinition() != null) { wsdlAddress = packet.webServiceContextDelegate.getWSDLAddress(packet,endpoint); } return clazz.cast(endpoint.getEndpointReference(clazz,address,wsdlAddress, referenceParameters)); }