/** * Create the actual Endpoint instance. * @param bean the service object to wrap * @return the Endpoint instance * @see Endpoint#create(Object) * @see Endpoint#create(String, Object) */ @UsesJava7 // optional use of Endpoint#create with WebServiceFeature[] protected Endpoint createEndpoint(Object bean) { if (this.endpointFeatures != null || this.webServiceFeatures != null) { WebServiceFeature[] endpointFeaturesToUse = this.endpointFeatures; if (endpointFeaturesToUse == null) { endpointFeaturesToUse = new WebServiceFeature[this.webServiceFeatures.length]; for (int i = 0; i < this.webServiceFeatures.length; i++) { endpointFeaturesToUse[i] = convertWebServiceFeature(this.webServiceFeatures[i]); } } return Endpoint.create(this.bindingType, bean, endpointFeaturesToUse); } else { return Endpoint.create(this.bindingType, bean); } }
@Override public void dispose () { super.dispose (); List<Endpoint> endpoints; synchronized ( this ) { endpoints = new ArrayList<Endpoint> ( this.endpoints.values () ); this.endpoints.clear (); } for ( final Endpoint e : endpoints ) { e.stop (); } }
@Override protected void unexportService ( final ServiceReference<?> serviceReference ) { final Endpoint e; synchronized ( this ) { e = this.endpoints.remove ( serviceReference ); } if ( e != null ) { if ( e.isPublished () ) { try { e.stop (); } catch ( final Exception ex ) { logger.warn ( "Failed to stop export", ex ); } } } }
/** * Create the actual Endpoint instance. * @param bean the service object to wrap * @return the Endpoint instance * @see Endpoint#create(Object) * @see Endpoint#create(String, Object) */ protected Endpoint createEndpoint(Object bean) { if (this.endpointFeatures != null || this.webServiceFeatures != null) { WebServiceFeature[] endpointFeaturesToUse = this.endpointFeatures; if (endpointFeaturesToUse == null) { endpointFeaturesToUse = new WebServiceFeature[this.webServiceFeatures.length]; for (int i = 0; i < this.webServiceFeatures.length; i++) { endpointFeaturesToUse[i] = convertWebServiceFeature(this.webServiceFeatures[i]); } } return Endpoint.create(this.bindingType, bean, endpointFeaturesToUse); } else { return Endpoint.create(this.bindingType, bean); } }
public static void main(String[] args) throws Exception { // find a free port ServerSocket ss = new ServerSocket(0); int port = ss.getLocalPort(); ss.close(); Endpoint endPoint1 = null; Endpoint endPoint2 = null; try { endPoint1 = Endpoint.publish("http://0.0.0.0:" + port + "/method1", new Method1()); endPoint2 = Endpoint.publish("http://0.0.0.0:" + port + "/method2", new Method2()); System.out.println("Sleep 3 secs..."); Thread.sleep(3000); } finally { stop(endPoint2); stop(endPoint1); } }
public static void main(String[] args) { // HelloWorldImpl implementor = new HelloWorldImpl(); // JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean(); // // 除了http://localhost部分其他部分可以随便写,但格式不能乱 http://IP:PORT/NAME // factory.setAddress("http://localhost:8080/ws/hello"); // factory.setServiceClass(HelloWorld.class);//可省,但不建议,因为可能会有些小问题 // factory.setServiceBean(implementor); //// //LoggingInInterceptor和LoggingOutInterceptor是日志拦截器,用于输入和输出时显示日志 // factory.getInInterceptors().add(new LoggingInInterceptor()); // factory.getOutInterceptors().add(new LoggingOutInterceptor()); // factory.create(); // System.out.println("ws is published"); HelloWorld hw = new HelloWorldImpl(); Endpoint.publish(ADDRESS, hw); }
public Datex2Supplier createSupplier(String supplierPath, String subscriptionPath) { if (subscriptionPath != null) { ClientSubscriptionImpl subscription = new ClientSubscriptionImpl( supplierPath, subscriptionPath); autowire(subscription); Endpoint.publish(subscriptionPath, subscription); } Datex2SupplierImpl supplier = new Datex2SupplierImpl(supplierPath, subscriptionPath); autowire(supplier); ClientPullImpl pull = new ClientPullImpl(supplier); autowire(pull); Endpoint.publish(supplierPath, pull); return supplier; }
/** * 发布Webservice */ public static void startServer() { if (server != null) { System.out.println("WebService服务正在运行。。。"); return; } LeaveWebService leaveWebService = new LeaveWebServiceImpl(); /*JaxWsServerFactoryBean svrFactory = new JaxWsServerFactoryBean(); svrFactory.setServiceClass(LeaveWebService.class); svrFactory.setAddress(WEBSERVICE_URL); svrFactory.setServiceBean(leaveWebService); svrFactory.getInInterceptors().add(new LoggingInInterceptor()); svrFactory.getOutInterceptors().add(new LoggingOutInterceptor()); server = svrFactory.create(); server.start();*/ Endpoint.publish(WEBSERVICE_URL, leaveWebService); System.out.println("请假Webservice已发布:" + WEBSERVICE_URL + "?wsdl"); }
@Test public void testMultiplePublishSameAddress() throws Exception { server.start(); String contextPath = "/ctxt"; String path = "/echo"; for (int i = 0; i < 3; i++) { HttpContext ctx = UndertowContextFactory.createHttpContext(server, contextPath, path); String address = "http://localhost:" + currentPort + contextPath + path; Endpoint endpoint = Endpoint.create(new EndpointBean()); endpoint.publish(ctx); // Use httpserver context for publishing invokeEndpoint(address); endpoint.stop(); } }
@Test public void testMultipleEndpointsSameContext() throws Exception { server.start(); String contextPath = "/ctxt"; String path = "/echo"; int k = 3; Endpoint[] endpoints = new Endpoint[k]; HttpContext[] contexts = new HttpContext[k]; String[] addresses = new String[k]; for (int i = 0; i < k; i++) { addresses[i] = "http://localhost:" + currentPort + contextPath + path + i; contexts[i] = UndertowContextFactory.createHttpContext(server, contextPath, path + i); endpoints[i] = Endpoint.create(new EndpointBean()); endpoints[i].publish(contexts[i]); } for (int i = 0; i < k; i++) { invokeEndpoint(addresses[i]); } for (int i = 0; i < k; i++) { endpoints[i].stop(); } }
@Test public void testMultipleEndpointsDifferentContexts() throws Exception { server.start(); String contextPath = "/ctxt"; String path = "/echo"; int k = 3; Endpoint[] endpoints = new Endpoint[k]; HttpContext[] contexts = new HttpContext[k]; String[] addresses = new String[k]; for (int i = 0; i < k; i++) { addresses[i] = "http://localhost:" + currentPort + contextPath + i + path; contexts[i] = UndertowContextFactory.createHttpContext(server, contextPath + i, path); endpoints[i] = Endpoint.create(new EndpointBean()); endpoints[i].publish(contexts[i]); } for (int i = 0; i < k; i++) { invokeEndpoint(addresses[i]); } for (int i = 0; i < k; i++) { endpoints[i].stop(); } }
public static void main(String[] argv) throws IOException { try { ConnectionsReader connReader = new ConnectionsReader(); QueriesReader queriesReader = new QueriesReader(); SettingsReader settingsReader = new SettingsReader(); HashMap<String, Object> config; logs = new LogHandler(); config = settingsReader.readSettings(new File("").getAbsolutePath() + File.separator + "config" + File.separator + "settings.xml", logs); connections = connReader.readSettings(new File("").getAbsolutePath() + File.separator + "config" + File.separator + "connections.xml", logs); connections = queriesReader.readQueries(new File("").getAbsolutePath() + File.separator + "config" + File.separator + "queries.xml", connections, logs); Dispatcher implementor = new Dispatcher(); String address = "http://" + config.get("ip") + ":" + config.get("port") + "/" + config.get("name"); System.out.println("Server wsdl can be found on http://localhost:" + config.get("port") + "/" + config.get("name")); Endpoint.publish(address, implementor); } catch (Exception e) { e.printStackTrace(); logs.write(Level.SEVERE, e.getMessage()); } }
private void configureEndpoint(EndpointConfig config, Endpoint endpoint) { Map<String, Object> props = endpoint.getProperties(); // Basic config if(config.getWsdlService() != null) { props.put(Endpoint.WSDL_SERVICE, config.getWsdlService()); } if(config.getWsdlPort() != null) { props.put(Endpoint.WSDL_PORT, config.getWsdlPort()); } // setup schema validation props.put(Message.SCHEMA_VALIDATION_ENABLED, SchemaValidation.SchemaValidationType.valueOf(schemaValidation.toUpperCase())); for (EndpointCustomizer customizer : endpointCustomizers) { customizer.configureEndpoint(endpoint); } }
@Override public void loadBus(ServletConfig servletConfig) { super.loadBus(servletConfig); // You could add the endpoint publish codes here try { //be sure to use the bus that's been created in loadBus.. Bus bus = getBus(); BusFactory.setThreadDefaultBus(bus); Endpoint.publish("/Echo1", new EchoImpl()); } finally { //free the thread default bus association in the current thread which //is serving the servlet init, as it can have side effect on other //servlet(s) deployed afterwards BusFactory.setThreadDefaultBus(null); } }
@Test @RunAsClient public void test() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port + "/jaxws-endpoint1"; Endpoint endpoint1 = publishEndpoint(new EndpointBean(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port + "/jaxws-endpoint2"; Endpoint endpoint2 = publishEndpoint(new EndpointBean(), publishURL2); invokeEndpoint(publishURL1); invokeEndpoint(publishURL2); endpoint1.stop(); endpoint2.stop(); }
public String echo(String input, String serverHost, int port) { Endpoint ep = Endpoint.create(new EndpointBean()); String publishUrl = "http://" + serverHost + ":" + port + "/foo/bar"; ep.publish(publishUrl); try { QName qname = new QName("http://org.jboss.ws/jaxws/endpoint", "EndpointService"); Service service = Service.create(new URL(publishUrl + "?wsdl"), qname); EndpointInterface proxy = (EndpointInterface) service.getPort(EndpointInterface.class); return proxy.echo(input); } catch (Exception e) { throw new WebServiceException(e); } finally { if (ep != null) { ep.stop(); } } }
@Test @RunAsClient public void testDifferentPortsSameContext() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port1 + "/jaxws-endpoint/"; Endpoint endpoint1 = publishEndpoint1(new Endpoint1Impl(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port2 + "/jaxws-endpoint"; Endpoint endpoint2 = publishEndpoint2(new Endpoint1Impl(), publishURL2); invokeEndpoint1(publishURL1); invokeEndpoint1(publishURL2); endpoint1.stop(); endpoint2.stop(); }
@Test @RunAsClient public void testDifferentPortsNoContext() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port1 + "/"; Endpoint endpoint1 = publishEndpoint1(new Endpoint1Impl(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port2; Endpoint endpoint2 = publishEndpoint2(new Endpoint1Impl(), publishURL2); invokeEndpoint1(publishURL1); if (isIntegrationCXF()) { //sun.net.www.protocol.http.HttpURLConnection barfs on addresses like http://localhost:8872?wsdl invokeEndpoint1(publishURL2.replace(String.valueOf(port2), port2 + "/")); } else { invokeEndpoint1(publishURL2); } endpoint1.stop(); endpoint2.stop(); }
@Test @RunAsClient public void testDifferentPortsAndLongPaths() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port1 + "/jaxws-endpoint/endpoint/long/path/"; Endpoint endpoint1 = publishEndpoint3(new Endpoint1Impl(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port2 + "/jaxws-endpoint/endpoint/long/path"; Endpoint endpoint2 = publishEndpoint1(new Endpoint1Impl(), publishURL2); invokeEndpoint1(publishURL1); invokeEndpoint1(publishURL2); endpoint1.stop(); endpoint2.stop(); }
@Test @RunAsClient public void testSamePortsAndAlmostIdenticalLongPaths() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port1 + "/jaxws-endpoint/endpoint/number1/"; Endpoint endpoint1 = publishEndpoint2(new Endpoint1Impl(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port1 + "/jaxws-endpoint/endpoint/number11"; Endpoint endpoint2 = publishEndpoint3(new Endpoint1Impl(), publishURL2); invokeEndpoint2(publishURL1); invokeEndpoint2(publishURL2); endpoint1.stop(); endpoint2.stop(); }
@Test @RunAsClient public void testDifferentPortsAndIdenticalPaths() throws Exception { String publishURL1 = "http://" + getServerHost() + ":" + port1 + "/jaxws-endpoint/endpoint/number1/"; Endpoint endpoint1 = publishEndpoint1(new Endpoint1Impl(), publishURL1); String publishURL2 = "http://" + getServerHost() + ":" + port2 + "/jaxws-endpoint/endpoint/number1"; Endpoint endpoint2 = publishEndpoint2(new Endpoint1Impl(), publishURL2); invokeEndpoint2(publishURL1); invokeEndpoint2(publishURL2); endpoint1.stop(); endpoint2.stop(); }
@Override public Endpoint createEndpoint(String bindingId, Object implementor) { ClassLoader origClassLoader = getContextClassLoader(); boolean restoreTCCL = false; try { restoreTCCL = checkAndFixContextClassLoader(origClassLoader); setValidThreadDefaultBus(); return new DelegateEndpointImpl(super.createEndpoint(bindingId, implementor)); } finally { if (restoreTCCL) setContextClassLoader(origClassLoader); } }
@Override public Endpoint createEndpoint(String bindingId, Object implementor, WebServiceFeature ... features) { ClassLoader origClassLoader = getContextClassLoader(); boolean restoreTCCL = false; try { restoreTCCL = checkAndFixContextClassLoader(origClassLoader); setValidThreadDefaultBus(); return new DelegateEndpointImpl(super.createEndpoint(bindingId, implementor, features)); } finally { if (restoreTCCL) setContextClassLoader(origClassLoader); } }
@Override public Endpoint createEndpoint(String bindingId, Class<?> implementorClass, Invoker invoker, WebServiceFeature ... features) { ClassLoader origClassLoader = getContextClassLoader(); boolean restoreTCCL = false; try { restoreTCCL = checkAndFixContextClassLoader(origClassLoader); setValidThreadDefaultBus(); return new DelegateEndpointImpl(super.createEndpoint(bindingId, implementorClass, invoker, features)); } finally { if (restoreTCCL) setContextClassLoader(origClassLoader); } }
/** * This verifies that DelegateEndpointImpl delegates to the Apache * CXF EndpointImpl after having properly setup the TCCL so that it * can load and create instances of the ProviderImpl class. */ @Test public void testEndpointImplPublishCorrectlySetsTCCL() { ClassLoader orig = Thread.currentThread().getContextClassLoader(); try { Endpoint ep1 = new DelegateEndpointImpl(new TestEndpoint()); ep1.publish(new Integer(1)); //just to ensure the publish(Object arg) is used ep1.publish("foo"); Thread.currentThread().setContextClassLoader(new TestClassLoader()); Endpoint ep2 = new DelegateEndpointImpl(new TestEndpoint()); ep2.publish(new Integer(1)); //just to ensure the publish(Object arg) is used ep2.publish("foo"); } finally { Thread.currentThread().setContextClassLoader(orig); } }
@Override public void loadBus(ServletConfig servletConfig) throws ServletException { super.loadBus(servletConfig); // TODO: Hacky first version to get default Process Engine ProcessEngine processEngine = ProcessEngineConfiguration .createProcessEngineConfigurationFromResourceDefault() .buildProcessEngine(); Bus bus = getBus(); BusFactory.setDefaultBus(bus); Endpoint.publish("/RuntimeService", new RuntimeWebServiceImpl(processEngine)); // You can als use the simple frontend API to do this ServerFactoryBean factory = new ServerFactoryBean(); factory.setBus(bus); factory.setServiceClass(RuntimeWebServiceImpl.class); factory.setAddress("/RuntimeService"); factory.create(); }
@Override @WebMethod(exclude = true) protected void execute() throws Exception { TaskerboxWebService<T> wsImpl = this.wsClass.newInstance(); wsImpl.setChannel(this); Endpoint.publish(this.wsAddress, wsImpl); logInfo(log, "Web service '" + this.wsClass.getName() + "' was published successfully.\n" + "WSDL URL: " + this.wsAddress + "?WSDL"); // Keep the local web server running until the process is killed while (Thread.currentThread().isAlive()) { try { Thread.sleep(10000); } catch (InterruptedException ex) { } } }
@Before public void setUp() { try { address = "http://localhost:9000/services/DocumentSegmentationService"; ep = Endpoint.publish(address, new DocumentSegmentationServicePortTypeImpl()); returnedValueOfProcessDocument = new SegmentDocumentResponse(); returnedValueOfProcessDocument .setMaskedDocument("<ClinicalDocument></ClinicalDocument>"); returnedValueOfProcessDocument.setProcessedDocument(null); returnedValueOfProcessDocument.setPostProcessingMetadata(null); } catch (Exception e) { logger.error(e.getMessage(), e); } }
@BeforeClass public static void setUp() { try { address = "http://localhost:9000/services/DS4PContextHandler"; ep = Endpoint.publish(address, new DS4PContextHandlerImpl()); returnedValueOfEnforcePolicy = new Return (); returnedValueOfEnforcePolicy.setPdpDecision("Permit"); returnedValueOfEnforcePolicy.setPurposeOfUse("TREAT"); returnedValueOfEnforcePolicy.setHomeCommunityId("2.16.840.1.113883.3.467"); returnedValueOfEnforcePolicy.setResourceId(""); returnedValueOfEnforcePolicy.setResourceName(""); returnedValueOfEnforcePolicy.setPdpStatus(""); returnedValueOfEnforcePolicy.setPdpRequest(""); returnedValueOfEnforcePolicy.setPdpResponse(""); returnedValueOfEnforcePolicy.setRequestTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar(2008,10,1))); returnedValueOfEnforcePolicy.setResponseTime(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar(2008,10,1))); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void connect() { if (isConnected() || getName() == null || getName().length() == 0 || service == null) return; error = null; endpoint = null; webService = service.getServiceObject(); try { log.fine("JWS Connect: " + getName()); endpoint = Endpoint.publish("/" + getName(), webService); } catch (Throwable t) { error = t.getMessage(); webService = null; endpoint = null; log.log(Level.WARNING, "ERROR: " + getName() + " " + webService, t); } if (endpoint != null) service.published(this); }
private void reset() throws Exception { messagesReceived = 0; if (ep == null || !ep.isPublished()) { int httpPort = 9600 + new Random().nextInt(99); String hostname = TckPublisher.getProperties().getProperty("bindaddress"); if (hostname == null) { hostname = InetAddress.getLocalHost().getHostName(); } url = "http://" + hostname + ":" + httpPort + "/" + UUID.randomUUID().toString(); logger.info("Firing up embedded endpoint at " + url); do { try { ep = Endpoint.publish(url, this); httpPort = 9600 + new Random().nextInt(99); } catch (Exception ex) { logger.warn(ex.getMessage()); } } while (ep != null && !ep.isPublished()); } }
@BeforeClass public static void startup() throws Exception { if (!TckPublisher.isEnabled()) return; startManager(); hostname = TckPublisher.getProperties().getProperty("bindaddress"); if (hostname == null) { hostname = InetAddress.getLocalHost().getHostName(); } port = 9600; //bring up the TCK SubscriptionListener String httpEndpoint = "http://" + hostname + ":" + port + "/tcksubscriptionlistener"; System.out.println("Bringing up SubscriptionListener endpoint at " + httpEndpoint); endPoint = Endpoint.publish(httpEndpoint, new UDDISubscriptionListenerImpl()); int count = 0; while (!endPoint.isPublished()) { port = 9600 + new Random().nextInt(99); httpEndpoint = "http://" + hostname + ":" + port + "/tcksubscriptionlistener"; System.out.println("Bringing up SubscriptionListener endpoint at " + httpEndpoint); endPoint = Endpoint.publish(httpEndpoint, new UDDISubscriptionListenerImpl()); count++; if (count > 10) { Assert.fail("unable to bring up endpoint"); } } }
@BeforeClass public static void startup() throws Exception { if (!TckPublisher.isEnabled()) { return; } startManager(); hostname = "localhost"; //bring up the TCK SubscriptionListener port = 9600; String httpEndpoint = "http://" + hostname + ":" + port + "/tcksubscriptionlistener"; System.out.println("Bringing up SubscriptionListener endpoint at " + httpEndpoint); endPoint = Endpoint.publish(httpEndpoint, new UDDISubscriptionListenerImpl()); int count = 0; while (!endPoint.isPublished()) { port = 9600 + new Random().nextInt(99); httpEndpoint = "http://" + hostname + ":" + port + "/tcksubscriptionlistener"; System.out.println("Bringing up SubscriptionListener endpoint at " + httpEndpoint); endPoint = Endpoint.publish(httpEndpoint, new UDDISubscriptionListenerImpl()); count++; if (count > 10) { Assert.fail("unable to bring up endpoint"); } } }
public static void main (String args[]) { System.out.println("1. Bring up the hello world endpoint at port 18080"); Endpoint helloWorldEndPoint = Endpoint.create(new HelloWorldImpl()); helloWorldEndPoint.publish("http://localhost:18080/services/helloworld"); System.out.println("2. Programmatically publish the endpoint to UDDI"); Publish sp = new Publish(); try { uddiClient = new UDDIClient("META-INF/wsdl2uddi-uddi.xml"); UDDIClerk clerk = uddiClient.getClerk("joe"); System.out.println("setting up the publisher"); sp.setupJoePublisher(clerk); System.out.println("publish the business"); sp.publishBusiness(clerk); System.out.println("and the wsdl"); sp.publishWSDL(clerk); System.out.println("waiting for calls into the HelloWorldImpl..."); } catch (Exception e) { e.printStackTrace(); } }
public void testMetadata() throws Exception { SampleEndpoint sample = new SampleEndpoint(); Endpoint ep = Endpoint.create(sample); assertTrue("The returned Endpoint instance was null", ep != null); ep.publish("test"); assertTrue("The endpoint was not published successfully", ep.isPublished()); String wsdlLocation = "http://test.wsdl.com/Test.wsdl"; // Dummy URL List<Source> metadata = new ArrayList<Source>(); Source source = new StreamSource(new ByteArrayInputStream(new byte[0])); // Dummy content source.setSystemId(wsdlLocation); metadata.add(source); ep.setMetadata(metadata); metadata = ep.getMetadata(); assertNotNull(metadata); source = metadata.get(0); assertNotNull(source); assertEquals(source.getSystemId(), wsdlLocation); ep.stop(); }