use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.
the class HttpContextTest method testAuthentication.
public void testAuthentication() throws Exception {
int port = PortAllocator.getFreePort();
String address = "http://localhost:" + port + "/hello";
HttpServer server = HttpServer.create(new InetSocketAddress(port), 5);
ExecutorService threads = Executors.newFixedThreadPool(5);
server.setExecutor(threads);
server.start();
Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
HttpContext context = server.createContext("/hello");
final String realm = "localhost.realm.com";
context.setAuthenticator(new BasicAuthenticator(realm) {
public boolean checkCredentials(String username, String password) {
System.out.println("Authenticator is called");
if (username.equals("auth-user") && password.equals("auth-pass")) {
return true;
}
return false;
}
});
endpoint.publish(context);
/*
Works but the next request hangs
// Gets WSDL from the published endpoint
int code = getHttpStatusCode(address);
assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, code);
*/
// access service
QName portName = new QName("http://echo.org/", "RpcLitPort");
QName serviceName = new QName("http://echo.org/", "RpcLitEndpoint");
Service service = Service.create(serviceName);
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
Dispatch<Source> d = service.createDispatch(portName, Source.class, Service.Mode.PAYLOAD);
d.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "auth-user");
d.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "auth-pass");
String body = "<ns0:echoInteger xmlns:ns0=\"http://echo.abstract.org/\"><arg0>2</arg0></ns0:echoInteger>";
Source request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
Source response = d.invoke(request);
request = new StreamSource(new ByteArrayInputStream(body.getBytes()));
response = d.invoke(request);
endpoint.stop();
server.stop(1);
threads.shutdown();
}
use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.
the class HttpContextTest method testContext.
public void testContext() throws Exception {
int port = PortAllocator.getFreePort();
String address = "http://localhost:" + port + "/hello";
HttpServer server = HttpServer.create(new InetSocketAddress(port), 5);
ExecutorService threads = Executors.newFixedThreadPool(5);
server.setExecutor(threads);
server.start();
Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
HttpContext context = server.createContext("/hello");
endpoint.publish(context);
// Gets WSDL from the published endpoint
int code = getHttpStatusCode(address);
assertEquals(HttpURLConnection.HTTP_OK, code);
endpoint.stop();
server.stop(1);
threads.shutdown();
}
use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.
the class HttpStatusCodes method testUnsupportedMediaType.
public void testUnsupportedMediaType() throws Exception {
int port = PortAllocator.getFreePort();
String address = "http://localhost:" + port + "/hello";
Endpoint endpoint = Endpoint.publish(address, new RpcLitEndpoint());
// Send a request with "a/b" as Content-Type
String message = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><soapenv:Body/></soapenv:Envelope>";
HTTPResponseInfo rInfo = ClientServerTestUtil.sendPOSTRequest(address, message, "a/b");
int code = rInfo.getResponseCode();
assertEquals(HttpURLConnection.HTTP_UNSUPPORTED_TYPE, code);
endpoint.stop();
}
use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.
the class EndpointEPRTest method testMSEPR.
public void testMSEPR() throws Exception {
int port = PortAllocator.getFreePort();
String address = "http://localhost:" + port + "/hello";
Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
List<Source> metadata = new ArrayList<Source>();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
String[] docs = { "RpcLitEndpoint.wsdl", "RpcLitAbstract.wsdl", "RpcLitEndpoint.xsd" };
for (String doc : docs) {
URL url = cl.getResource(doc);
metadata.add(new StreamSource(url.openStream(), url.toExternalForm()));
}
endpoint.setMetadata(metadata);
endpoint.publish(address);
MemberSubmissionEndpointReference epr = endpoint.getEndpointReference(MemberSubmissionEndpointReference.class);
endpoint.stop();
EprUtil.validateEPR(epr, address, serviceName, portName, portTypeName, Boolean.TRUE);
printEPR(epr);
}
use of jakarta.xml.ws.Endpoint in project metro-jax-ws by eclipse-ee4j.
the class EndpointEPRTest method testW3CEPR.
public void testW3CEPR() throws Exception {
int port = PortAllocator.getFreePort();
String address = "http://localhost:" + port + "/hello";
Endpoint endpoint = Endpoint.create(new RpcLitEndpoint());
List<Source> metadata = new ArrayList<Source>();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
String[] docs = { "RpcLitEndpoint.wsdl", "RpcLitAbstract.wsdl", "RpcLitEndpoint.xsd" };
for (String doc : docs) {
URL url = cl.getResource(doc);
metadata.add(new StreamSource(url.openStream(), url.toExternalForm()));
}
endpoint.setMetadata(metadata);
endpoint.publish(address);
W3CEndpointReference epr = endpoint.getEndpointReference(W3CEndpointReference.class);
endpoint.stop();
EprUtil.validateEPR(epr, address, null, /*serviceName*/
null, /*portName*/
null, /*portTypeName*/
Boolean.FALSE);
printEPR(epr);
}
Aggregations