use of javax.xml.ws.Service in project camel by apache.
the class CxfConsumerWSRMTest method testInvokeGreeter.
@Test
public void testInvokeGreeter() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedMessageCount(1);
Bus clientBus = context.getRegistry().lookupByNameAndType("client-bus", Bus.class);
assertNotNull(clientBus);
BusFactory.setThreadDefaultBus(clientBus);
try {
Service service = Service.create(SERVICE_NAME);
service.addPort(PORT_NAME, "http://schemas.xmlsoap.org/soap/", "http://localhost:" + CXFTestSupport.getPort1() + "/CxfConsumerWSRMTest/router");
Greeter greeter = service.getPort(PORT_NAME, Greeter.class);
greeter.greetMeOneWay("test");
} finally {
BusFactory.setThreadDefaultBus(null);
}
assertMockEndpointsSatisfied();
}
use of javax.xml.ws.Service in project jdk8u_jdk by JetBrains.
the class TestWsImport method main.
public static void main(String[] args) throws IOException {
String javaHome = System.getProperty("java.home");
if (javaHome.endsWith("jre")) {
javaHome = new File(javaHome).getParent();
}
String wsimport = javaHome + File.separator + "bin" + File.separator + "wsimport";
if (System.getProperty("os.name").startsWith("Windows")) {
wsimport = wsimport.concat(".exe");
}
Endpoint endpoint = Endpoint.create(new TestService());
HttpServer httpServer = null;
try {
// Manually create HttpServer here using ephemeral address for port
// so as to not end up with attempt to bind to an in-use port
httpServer = HttpServer.create(new InetSocketAddress(0), 0);
HttpContext httpContext = httpServer.createContext("/hello");
int port = httpServer.getAddress().getPort();
System.out.println("port = " + port);
httpServer.start();
endpoint.publish(httpContext);
String address = "http://localhost:" + port + "/hello";
Service service = Service.create(new URL(address + "?wsdl"), new QName("http://test/jaxws/sample/", "TestService"));
String[] wsargs = { wsimport, "-p", "wstest", "-J-Djavax.xml.accessExternalSchema=all", "-J-Dcom.sun.tools.internal.ws.Invoker.noSystemProxies=true", address + "?wsdl", "-clientjar", "wsjar.jar" };
ProcessBuilder pb = new ProcessBuilder(wsargs);
pb.redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s = r.readLine();
while (s != null) {
System.out.println(s.trim());
s = r.readLine();
}
p.waitFor();
p.destroy();
try (JarFile jarFile = new JarFile("wsjar.jar")) {
for (Enumeration em = jarFile.entries(); em.hasMoreElements(); ) {
String fileName = em.nextElement().toString();
if (fileName.contains("\\")) {
throw new RuntimeException("\"\\\" character detected in jar file: " + fileName);
}
}
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} finally {
endpoint.stop();
if (httpServer != null) {
httpServer.stop(0);
}
Path p = Paths.get("wsjar.jar");
Files.deleteIfExists(p);
p = Paths.get("wstest");
if (Files.exists(p)) {
try {
Files.walkFileTree(p, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return CONTINUE;
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (exc == null) {
Files.delete(dir);
return CONTINUE;
} else {
throw exc;
}
}
});
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}
use of javax.xml.ws.Service in project jdk8u_jdk by JetBrains.
the class Test method main.
public static void main(String[] args) throws IOException, TransformerException {
try {
String address = deployWebservice();
Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);
Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));
String resultXml = toString(response);
log("= request ======== \n");
log(XML_REQUEST);
log("= result ========= \n");
log(resultXml);
log("\n==================");
boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
if (!xsAnyMixedPartSame) {
fail("The xs:any content=mixed part is supposed to be same in request and response.");
throw new RuntimeException();
}
log("TEST PASSED");
} finally {
stopWebservice();
// if you need to debug or explore wsdl generation result
// comment this line out:
deleteGeneratedFiles();
}
}
use of javax.xml.ws.Service in project ats-framework by Axway.
the class AgentServicePool method createServicePort.
private AgentService createServicePort(String host) throws AgentException {
try {
String protocol = AgentConfigurator.getConnectionProtocol(host);
if (protocol == null) {
protocol = "http";
} else {
SslUtils.trustAllHttpsCertificates();
SslUtils.trustAllHostnames();
}
URL url = this.getClass().getResource("/META-INF/wsdl/" + AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME + ".wsdl");
Service agentService = Service.create(url, new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_LOCAL_NAME));
AgentService agentServicePort = agentService.getPort(new QName(AgentWsDefinitions.AGENT_SERVICE_XML_TARGET_NAMESPACE, AgentWsDefinitions.AGENT_SERVICE_XML_PORT_NAME), AgentService.class);
Map<String, Object> ctxt = ((BindingProvider) agentServicePort).getRequestContext();
// setting ENDPOINT ADDRESS, which defines the web service URL for SOAP communication
// NOTE: if we specify WSDL URL (...<endpoint_address>?wsdl), the JBoss server returns the WSDL on a SOAP call,
// but we are expecting a SOAP message response and an exception is thrown.
// The Jetty server (in ATS agents) is working in both cases.
ctxt.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, protocol + "://" + host + AgentWsDefinitions.AGENT_SERVICE_ENDPOINT_ADDRESS);
// setting timeouts
// timeout in milliseconds
ctxt.put(BindingProviderProperties.CONNECT_TIMEOUT, 10000);
// check if new unique id must be generated each time
if (!useNewUuId) {
// create temp file containing caller working directory and the unique id
String userWorkingDirectory = AtsSystemProperties.SYSTEM_USER_HOME_DIR;
String uuiFileLocation = AtsSystemProperties.SYSTEM_USER_TEMP_DIR + AtsSystemProperties.SYSTEM_FILE_SEPARATOR + "\\ats_uid.txt";
File uuiFile = new File(uuiFileLocation);
// otherwise add it to the file
if (uuiFile.exists()) {
String uuiFileContent = IoUtils.streamToString(IoUtils.readFile(uuiFileLocation));
if (uuiFileContent.contains(userWorkingDirectory)) {
for (String line : uuiFileContent.split("\n")) {
if (line.contains(userWorkingDirectory)) {
uniqueId = line.substring(userWorkingDirectory.length()).trim();
}
}
} else {
generateNewUUID();
new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
}
} else {
generateNewUUID();
try {
uuiFile.createNewFile();
} catch (IOException e) {
log.warn("Unable to create file '" + uuiFile.getAbsolutePath() + "'");
}
if (uuiFile.exists()) {
new LocalFileSystemOperations().appendToFile(uuiFileLocation, userWorkingDirectory + "\t" + uniqueId + "\n");
}
}
} else {
generateNewUUID();
}
// add header with unique session ID
Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put(ApplicationContext.ATS_UID_SESSION_TOKEN, Arrays.asList(uniqueId));
ctxt.put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);
return agentServicePort;
} catch (Exception e) {
throw new AgentException("Cannot connect to Agent application on host '" + host + "' check your configuration", e);
}
}
use of javax.xml.ws.Service in project wildfly by wildfly.
the class XercesUsageInWebServiceTestCase method testXercesUsageInWebService.
/**
* Test that the webservice invocation works fine
*
* @throws Exception
*/
@OperateOnDeployment("webservice-app-with-xerces")
@Test
public void testXercesUsageInWebService() throws Exception {
final QName serviceName = new QName("org.jboss.as.test.integration.xerces.ws", "XercesUsageWebService");
final URL wsdlURL = new URL(url.toExternalForm() + "XercesUsageWebService?wsdl");
final Service service = Service.create(wsdlURL, serviceName);
final XercesUsageWSEndpoint port = service.getPort(XercesUsageWSEndpoint.class);
final String xml = "dummy.xml";
final String result = port.parseUsingXerces(xml);
Assert.assertEquals("Unexpected return message from webservice", XercesUsageWebService.SUCCESS_MESSAGE, result);
}
Aggregations