@WebService public class MyService { @Resource WebServiceContext wsContext; /** * Web service operation */ @WebMethod public String myMethod() { MessageContext mc = wsContext.getMessageContext(); HttpServletRequest req = (HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST); System.out.println("Client IP = " + req.getRemoteAddr()); } }
@WebService() public class ListProducts { @Resource WebServiceContext context; @WebMethod(operationName = "listProducts") public String listProducts() { return context.getUserPrincipal().toString(); } }
/** * * @param parameters */ @WebMethod(operationName = "RollbackOperation", action = "http://docs.oasis-open.org/ws-tx/wsat/2006/06/Rollback") @Oneway @Action(input="http://docs.oasis-open.org/ws-tx/wsat/2006/06/Rollback") public void rollbackOperation( @WebParam(name = "Rollback", targetNamespace = "http://docs.oasis-open.org/ws-tx/wsat/2006/06", partName = "parameters") Notification parameters) { MessageContext ctx = webServiceCtx.getMessageContext(); final Notification rollback = parameters; final MAP inboundMap = AddressingHelper.inboundMap(ctx); final ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(ctx); TaskManager.getManager().queueTask(new Task() { public void executeTask() { CompletionCoordinatorProcessor.getProcessor().rollback(rollback, inboundMap, arjunaContext) ; } }) ; }
@WebMethod(operationName = "CreateCoordinationContextOperation", action = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext") @WebResult(name = "CreateCoordinationContextResponse", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") @Action(input="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext", output="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContextResponse") public CreateCoordinationContextResponseType createCoordinationContextOperation( @WebParam(name = "CreateCoordinationContext", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") CreateCoordinationContextType parameters) { MessageContext ctx = webServiceCtx.getMessageContext(); HttpServletRequest request = (HttpServletRequest)ctx.get(MessageContext.SERVLET_REQUEST); boolean isSecure = "https".equals(request.getScheme()); MAP inboundMAP = AddressingHelper.inboundMap(ctx); return ActivationCoordinatorProcessor.getCoordinator().createCoordinationContext(parameters, inboundMAP, isSecure); } }
@WebMethod @WebResult(name = "customers") public Customers getCustomers(@WebParam(name = "GetCustomers") GetCustomers req) { Customers cbean = new Customers(); cbean.setCustomer(customers.values()); if (context == null || context.getMessageContext() == null) { throw new WebServiceException("WebServiceContext is null!"); } return cbean; }
public String greetMe(String me) { if ("secure".equals(me)) { MessageContext ctx = getContext().getMessageContext(); return "Hello " + ctx.get(BindingProvider.USERNAME_PROPERTY); } if ("principal".equals(me)) { return "Hello " + getContext().getUserPrincipal().getName(); } LOG.info("Invoking greetMe " + prefix + me); invocationCount++; return "Hello " + me; }
package org.example.sampleservice; import javax.annotation.Resource; import javax.jws.HandlerChain; import javax.jws.WebService; import javax.xml.ws.WebServiceContext; @WebService(endpointInterface = "org.example.sampleservice.SampleService") @HandlerChain(file="handlers.xml") public class SampleServiceImpl implements SampleService { @Resource private WebServiceContext ctx; @Override public String sayHello(String name) { String usernameFromHeader = (String) ctx.getMessageContext().get("USERNAME"); return "Hello, " + name + " (invoked by " + (usernameFromHeader == null ? "[err or no 'Security' header found]" : usernameFromHeader) + ")"; } }
"Implementation for this operation not found."); obj = method.invoke(operationImpl, obj, context.getUserPrincipal(), context.getMessageContext()); if (obj == null) { throw new Exception("Error in implementation class.");
public final List<String> ping() { try { List<String> handlerInfoList = getHandlersInfo(context.getMessageContext()); handlerInfoList.add("servant"); context.getMessageContext().remove("handler.info"); //System.out.println(">> servant returning list: " + handlerInfoList); return handlerInfoList; } catch (Exception e) { e.printStackTrace(); } return null; }
@Override public boolean isUserInRole(String role) { return getContext().isUserInRole(role); }
@Override public EndpointReference getEndpointReference(Element... arg0) { return getContext().getEndpointReference(arg0); }
@WebMethod(operationName = "fault", action = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06/fault") @Oneway @Action(input="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/fault") public void soapFault( @WebParam(name = "Fault", targetNamespace = "http://schemas.xmlsoap.org/soap/envelope/", partName = "parameters") Fault fault) { MessageContext ctx = webServiceCtx.getMessageContext(); final MAP inboundMap = AddressingHelper.inboundMap(ctx); final ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(ctx); final SoapFault soapFault = SoapFault11.fromFault(fault); TaskManager.getManager().queueTask(new Task() { public void executeTask() { ParticipantCompletionParticipantProcessor.getProcessor().soapFault(soapFault, inboundMap, arjunaContext); ; } }) ; } }
@WebMethod(operationName = "CreateCoordinationContextOperation", action = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext") @WebResult(name = "CreateCoordinationContextResponse", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") @Action(input="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext", output="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContextResponse") public CreateCoordinationContextResponseType createCoordinationContextOperation( @WebParam(name = "CreateCoordinationContext", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") CreateCoordinationContextType parameters) { MessageContext ctx = webServiceCtx.getMessageContext(); HttpServletRequest request = (HttpServletRequest)ctx.get(MessageContext.SERVLET_REQUEST); boolean isSecure = "https".equals(request.getScheme()); MAP inboundMAP = AddressingHelper.inboundMap(ctx); return ActivationCoordinatorProcessor.getCoordinator().createCoordinationContext(parameters, inboundMAP, isSecure); } }
return "anonymous"; if (webctx.getUserPrincipal() != null && !Utility.stringIsNullOrEmpty(webctx.getUserPrincipal().getName())) { return webctx.getUserPrincipal().getName(); MessageContext mc = webctx.getMessageContext(); try {//org.apache.cxf.configuration.security.AuthorizationPolicy Object cxfAuthz = mc.get("org.apache.cxf.configuration.security.AuthorizationPolicy"); if (cxfAuthz != null) { String user = CXFUserIdentifyUtil.getFirstIdentityToString(cxfAuthz); HttpServletRequest session = ((HttpServletRequest) mc.get(MessageContext.SERVLET_REQUEST)); if (session == null || session.getUserPrincipal() == null) { return "anonymous";
import javax.annotation.Resource import javax.jws.WebMethod; import javax.jws.WebService; import javax.servlet.http.HttpServletRequest; import javax.xml.ws.WebServiceContext; import javax.xml.ws.handler.MessageContext; @WebService() public class Test { @Resource WebServiceContext context; @WebMethod(operationName = "getInfo") public String getInfo() { HttpServletRequest request = (HttpServletRequest)context.getMessageContext().get(MessageContext.SERVLET_REQUEST); return "IP: "+request.getRemoteAddr()+", Port: "+request.getRemotePort()+", Host: "+request.getRemoteHost(); } }
public boolean isUserInRole(String role) { return getWebServiceContext().isUserInRole(role); }
@Override public <T extends EndpointReference> T getEndpointReference(Class<T> arg0, Element... arg1) { return getContext().getEndpointReference(arg0, arg1); }
@WebMethod(operationName = "SoapFault", action = "http://docs.oasis-open.org/ws-tx/wsat/2006/06/fault") @Oneway @Action(input="http://docs.oasis-open.org/ws-tx/wsat/2006/06/fault") public void soapFault( @WebParam(name = "Fault", targetNamespace = "http://schemas.xmlsoap.org/soap/envelope/", partName = "parameters") Fault fault) { MessageContext ctx = webServiceCtx.getMessageContext(); final MAP inboundMap = AddressingHelper.inboundMap(ctx); final ArjunaContext arjunaContext = ArjunaContext.getCurrentContext(ctx); final SoapFault soapFault = SoapFault11.fromFault(fault); TaskManager.getManager().queueTask(new Task() { public void executeTask() { ParticipantProcessor.getProcessor().soapFault(soapFault, inboundMap, arjunaContext); ; } }) ; } }
@WebMethod(operationName = "CreateCoordinationContextOperation", action = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext") @WebResult(name = "CreateCoordinationContextResponse", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") @Action(input="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContext", output="http://docs.oasis-open.org/ws-tx/wscoor/2006/06/CreateCoordinationContextResponse") public CreateCoordinationContextResponseType createCoordinationContextOperation( @WebParam(name = "CreateCoordinationContext", targetNamespace = "http://docs.oasis-open.org/ws-tx/wscoor/2006/06", partName = "parameters") CreateCoordinationContextType parameters) { MessageContext ctx = webServiceCtx.getMessageContext(); HttpServletRequest request = (HttpServletRequest)ctx.get(MessageContext.SERVLET_REQUEST); boolean isSecure = "https".equals(request.getScheme()); MAP inboundMAP = AddressingHelper.inboundMap(ctx); return ActivationCoordinatorProcessor.getCoordinator().createCoordinationContext(parameters, inboundMAP, isSecure); } }
private HttpServletRequest getRequest() { if (context != null && context.getMessageContext() != null) return (HttpServletRequest)context.getMessageContext().get(AbstractHTTPDestination.HTTP_REQUEST); return null; }