public SOAPMessage get(Object endPoint) throws SOAPException { if (closed) { log.severe("SAAJ0011.p2p.get.already.closed.conn"); throw new SOAPExceptionImpl("Connection is closed"); } Class urlEndpointClass = null; try { urlEndpointClass = Class.forName("javax.xml.messaging.URLEndpoint"); } catch (Exception ex) { // Do nothing. URLEndpoint is available only when JAXM is there. } if (urlEndpointClass != null) { if (urlEndpointClass.isInstance(endPoint)) { String url = null; try { Method m = urlEndpointClass.getMethod("getURL", (Class[]) null); url = (String) m.invoke(endPoint, (Object[]) null); } catch (Exception ex) { log.severe("SAAJ0004.p2p.internal.err"); throw new SOAPExceptionImpl("Internal error: " + ex.getMessage()); } try { endPoint = new URL(url); } catch (MalformedURLException mex) { log.severe("SAAJ0005.p2p."); throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage()); } } } if (endPoint instanceof java.lang.String) { try { endPoint = new URL((String) endPoint); } catch (MalformedURLException mex) { log.severe("SAAJ0006.p2p.bad.URL"); throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage()); } } if (endPoint instanceof URL) try { SOAPMessage response = doGet((URL) endPoint); return response; } catch (Exception ex) { throw new SOAPExceptionImpl(ex); } else throw new SOAPExceptionImpl("Bad endPoint type " + endPoint); }
/** * Discover WS device on the local network with specified filter * * @param regexpProtocol url protocol matching regexp like "^http$", might be empty "" * @param regexpPath url path matching regexp like "onvif", might be empty "" * @return list of unique device urls filtered */ public static Collection<URL> discoverWsDevicesAsUrls(String regexpProtocol, String regexpPath) { final Collection<URL> urls = new TreeSet<>( new Comparator<URL>() { public int compare(URL o1, URL o2) { return o1.toString().compareTo(o2.toString()); } }); for (String key : discoverWsDevices()) { try { final URL url = new URL(key); boolean ok = true; if (regexpProtocol.length() > 0 && !url.getProtocol().matches(regexpProtocol)) ok = false; if (regexpPath.length() > 0 && !url.getPath().matches(regexpPath)) ok = false; if (ok) urls.add(url); } catch (MalformedURLException e) { e.printStackTrace(); } } return urls; }
public SOAPMessage call(SOAPMessage message, Object endPoint) throws SOAPException { if (closed) { log.severe("SAAJ0003.p2p.call.already.closed.conn"); throw new SOAPExceptionImpl("Connection is closed"); } Class urlEndpointClass = null; ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { if (loader != null) { urlEndpointClass = loader.loadClass(JAXM_URLENDPOINT); } else { urlEndpointClass = Class.forName(JAXM_URLENDPOINT); } } catch (ClassNotFoundException ex) { // Do nothing. URLEndpoint is available only when JAXM is there. log.finest("SAAJ0090.p2p.endpoint.available.only.for.JAXM"); } if (urlEndpointClass != null) { if (urlEndpointClass.isInstance(endPoint)) { String url = null; try { Method m = urlEndpointClass.getMethod("getURL", (Class[]) null); url = (String) m.invoke(endPoint, (Object[]) null); } catch (Exception ex) { // TBD -- exception chaining log.log(Level.SEVERE, "SAAJ0004.p2p.internal.err", ex); throw new SOAPExceptionImpl("Internal error: " + ex.getMessage()); } try { endPoint = new URL(url); } catch (MalformedURLException mex) { log.log(Level.SEVERE, "SAAJ0005.p2p.", mex); throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage()); } } } if (endPoint instanceof java.lang.String) { try { endPoint = new URL((String) endPoint); } catch (MalformedURLException mex) { log.log(Level.SEVERE, "SAAJ0006.p2p.bad.URL", mex); throw new SOAPExceptionImpl("Bad URL: " + mex.getMessage()); } } if (endPoint instanceof URL) try { SOAPMessage response = post(message, (URL) endPoint); return response; } catch (Exception ex) { // TBD -- chaining? throw new SOAPExceptionImpl(ex); } else { log.severe("SAAJ0007.p2p.bad.endPoint.type"); throw new SOAPExceptionImpl("Bad endPoint type " + endPoint); } }