Skip to content

Print infos about registered handlers and order #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,19 @@ synchronized Endpoint createEndpoint(Map<ServiceReference<?>, HandlerInfo> handl
}
handlerList = handlerMap.values().stream().filter(handlerInfo -> handlerInfo.matches(reference))
.sorted(HandlerInfo.SORT_BY_PRIORITY).toList();
System.out.println("Handler List is: ");
for (HandlerInfo handlerInfo : handlerList) {
System.out.println(" Rank " + handlerInfo.getServiceRank() + " / Id " + handlerInfo.getServiceId()
+ " = " + handlerInfo.fetchHandler());
}
@SuppressWarnings("rawtypes") // required by API...
List<Handler> chain = handlerList.stream().map(info -> info.fetchHandler()).filter(Objects::nonNull)
.map(Handler.class::cast).toList();
if (!chain.isEmpty()) {
System.out.println("Set Handler Chain:");
for (int i = 0; i < chain.size(); i++) {
System.out.println(" " + i + ") " + chain.get(i));
}
try {
endpoint.getBinding().setHandlerChain(chain);
} catch (RuntimeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void unbindEndpointImplementor(ServiceReference<?> endpointImplementorRef
*/
@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
public void addHandler(ServiceReference<Handler<? extends MessageContext>> handler) {
logger.debug("UPDATE handler={}", handler);
logger.debug("ADD handler={}", handler);
HandlerInfo info = handlerMap.put(handler, new HandlerInfo(handler, context.getBundleContext()));
if (info != null) {
info.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@
import org.eclipse.osgi.technology.webservices.integration.tests.handler.InvalidHandler;
import org.eclipse.osgi.technology.webservices.integration.tests.handler.TestLogicalHandler;
import org.eclipse.osgi.technology.webservices.integration.tests.handler.TestSoapHandler;
import org.eclipse.osgi.technology.webservices.integration.tests.handler.TestSoapHandler2;
import org.eclipse.osgi.technology.webservices.integration.tests.implementor.BadImplementor;
import org.eclipse.osgi.technology.webservices.integration.tests.implementor.WSEcho;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import org.osgi.framework.FrameworkUtil;
import org.osgi.service.webservice.runtime.WebserviceServiceRuntime;
import org.osgi.service.webservice.runtime.dto.EndpointDTO;
Expand Down Expand Up @@ -74,6 +76,7 @@ public void testEchoService(@InjectBundleContext
bundleContext, filter);
TestSoapHandler soapHandler = registerSoapHandler(bundleContext,
filter);
registerSoapHandler2(bundleContext, filter);
String publishAddress = DEFAULT_PUBLISH_ADDRESS + "/wsecho";
EndpointDTO endpoint = registerEchoEndpoint(bundleContext, id,
publishAddress);
Expand Down Expand Up @@ -239,6 +242,15 @@ private TestSoapHandler registerSoapHandler(BundleContext bundleContext,
return soapHandler;
}

private TestSoapHandler2 registerSoapHandler2(BundleContext bundleContext, String filter) {
TestSoapHandler2 soapHandler = new TestSoapHandler2();
bundleContext.registerService(Handler.class, soapHandler,
FrameworkUtil.asDictionary(Map.of(WebserviceWhiteboardConstants.WEBSERVICE_HANDLER_FILTER, filter,
WebserviceWhiteboardConstants.WEBSERVICE_HANDLER_EXTENSION, "true", HANDLER_TYPE,
HANDLER_SOAP, Constants.SERVICE_RANKING, 100)));
return soapHandler;
}

private TestLogicalHandler registerLogicalHandler(
BundleContext bundleContext, String filter) {
TestLogicalHandler logicalHandler = new TestLogicalHandler();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ public class TestLogicalHandler implements LogicalHandler<LogicalMessageContext>

@Override
public boolean handleMessage(LogicalMessageContext context) {
boolean outbound = (boolean) context.get(LogicalMessageContext.MESSAGE_OUTBOUND_PROPERTY);
int msg = handledMessages.incrementAndGet();
System.out.println("TestLogicalHandler.handleMessage no. " + msg);
System.out.println(
"[" + (outbound ? "outbound" : "inbound") + "] TestLogicalHandler.handleMessage no. " + msg + " ");
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.xml.namespace.QName;

import jakarta.xml.ws.handler.LogicalMessageContext;
import jakarta.xml.ws.handler.MessageContext;
import jakarta.xml.ws.handler.soap.SOAPHandler;
import jakarta.xml.ws.handler.soap.SOAPMessageContext;
Expand All @@ -33,8 +34,9 @@ public class TestSoapHandler implements SOAPHandler<SOAPMessageContext> {

@Override
public boolean handleMessage(SOAPMessageContext context) {
boolean outbound = (boolean) context.get(LogicalMessageContext.MESSAGE_OUTBOUND_PROPERTY);
int msg = handledMessages.incrementAndGet();
System.out.println("TestSoapHandler.handleMessage no. " + msg);
System.out.println("[" + (outbound ? "outbound" : "inbound") + "] TestSoapHandler.handleMessage no. " + msg);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*******************************************************************************
* Copyright (c) 2024 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.osgi.technology.webservices.integration.tests.handler;

import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import javax.xml.namespace.QName;

import jakarta.xml.ws.handler.LogicalMessageContext;
import jakarta.xml.ws.handler.MessageContext;
import jakarta.xml.ws.handler.soap.SOAPHandler;
import jakarta.xml.ws.handler.soap.SOAPMessageContext;

/**
* A handler that allows inspection of the messages it handled
*/
public class TestSoapHandler2 implements SOAPHandler<SOAPMessageContext> {

/**
* The number of messages handled by this handler
*/
public AtomicInteger handledMessages = new AtomicInteger();

@Override
public boolean handleMessage(SOAPMessageContext context) {
boolean outbound = (boolean) context.get(LogicalMessageContext.MESSAGE_OUTBOUND_PROPERTY);
int msg = handledMessages.incrementAndGet();
System.out.println("[" + (outbound ? "outbound" : "inbound") + "] TestSoapHandler2.handleMessage no. " + msg);
return true;
}

@Override
public boolean handleFault(SOAPMessageContext context) {
System.out.println("TestSoapHandler2.handleFault()");
return true;
}

@Override
public void close(MessageContext context) {
System.out.println("TestSoapHandler2.close()");
}

@Override
public Set<QName> getHeaders() {
return Set.of();
}

}
Loading