Java Code Examples for org.apache.cxf.endpoint.Endpoint#getEndpointInfo()

The following examples show how to use org.apache.cxf.endpoint.Endpoint#getEndpointInfo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CryptoLoader.java    From cxf with Apache License 2.0 6 votes vote down vote up
public final Map<Object, Crypto> getCryptoCache(Message message) {
    Endpoint endpoint = message.getExchange().getEndpoint();
    if (endpoint != null) {
        EndpointInfo info = endpoint.getEndpointInfo();
        synchronized (info) {
            Map<Object, Crypto> o =
                CastUtils.cast((Map<?, ?>)info.getProperty(CRYPTO_CACHE));
            if (o == null) {
                o = new ConcurrentHashMap<>();
                info.setProperty(CRYPTO_CACHE, o);
            }
            return o;
        }
    }
    return null;
}
 
Example 2
Source File: ColocOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server isColocated(List<Server> servers, Endpoint endpoint, BindingOperationInfo boi) {
    if (servers != null) {
        Service senderService = endpoint.getService();
        EndpointInfo senderEI = endpoint.getEndpointInfo();
        for (Server s : servers) {
            Endpoint receiverEndpoint = s.getEndpoint();
            Service receiverService = receiverEndpoint.getService();
            EndpointInfo receiverEI = receiverEndpoint.getEndpointInfo();
            if (receiverService.getName().equals(senderService.getName())
                && receiverEI.getName().equals(senderEI.getName())) {
                //Check For Operation Match.
                BindingOperationInfo receiverOI = receiverEI.getBinding().getOperation(boi.getName());
                if (receiverOI != null
                    && isCompatibleOperationInfo(boi, receiverOI)) {
                    return s;
                }
            }
        }
    }

    return null;
}
 
Example 3
Source File: DOM4JProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage(ProviderFactory factory) {
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    endpoint.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    endpoint.get(Application.class.getName());
    EasyMock.expectLastCall().andReturn(null);
    endpoint.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    endpoint.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    endpoint.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example 4
Source File: DOM4JProviderTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
private Message createMessage(boolean suppress) {
    ProviderFactory factory = ServerProviderFactory.getInstance();
    Message m = new MessageImpl();
    m.put("org.apache.cxf.http.case_insensitive_queries", false);
    Exchange e = new ExchangeImpl();
    e.put(DOM4JProvider.SUPPRESS_XML_DECLARATION, suppress);
    m.setExchange(e);
    e.setInMessage(m);
    Endpoint endpoint = EasyMock.createMock(Endpoint.class);
    endpoint.getEndpointInfo();
    EasyMock.expectLastCall().andReturn(null).anyTimes();
    endpoint.get(Application.class.getName());
    EasyMock.expectLastCall().andReturn(null);
    endpoint.size();
    EasyMock.expectLastCall().andReturn(0).anyTimes();
    endpoint.isEmpty();
    EasyMock.expectLastCall().andReturn(true).anyTimes();
    endpoint.get(ServerProviderFactory.class.getName());
    EasyMock.expectLastCall().andReturn(factory).anyTimes();
    EasyMock.replay(endpoint);
    e.put(Endpoint.class, endpoint);
    return m;
}
 
Example 5
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 6 votes vote down vote up
/**
* Determine if the use of addressing is indicated by the presence of a
* the usingAddressing attribute.
*
* @param message the current message
* @pre message is outbound
* @pre requestor role
*/
private boolean hasUsingAddressing(Message message) {
    boolean ret = false;
    Endpoint endpoint = message.getExchange().getEndpoint();
    if (null != endpoint) {
        Boolean b = (Boolean)endpoint.get(USING_ADDRESSING);
        if (null == b) {
            EndpointInfo endpointInfo = endpoint.getEndpointInfo();
            List<ExtensibilityElement> endpointExts = endpointInfo != null ? endpointInfo
                .getExtensors(ExtensibilityElement.class) : null;
            List<ExtensibilityElement> bindingExts = endpointInfo != null
                && endpointInfo.getBinding() != null ? endpointInfo
                .getBinding().getExtensors(ExtensibilityElement.class) : null;
            List<ExtensibilityElement> serviceExts = endpointInfo != null
                && endpointInfo.getService() != null ? endpointInfo
                .getService().getExtensors(ExtensibilityElement.class) : null;
            ret = hasUsingAddressing(endpointExts) || hasUsingAddressing(bindingExts)
                         || hasUsingAddressing(serviceExts);
            b = ret ? Boolean.TRUE : Boolean.FALSE;
            endpoint.put(USING_ADDRESSING, b);
        } else {
            ret = b.booleanValue();
        }
    }
    return ret;
}
 
Example 6
Source File: WSPolicyFeature.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Server server, Bus bus) {
    Endpoint endpoint = server.getEndpoint();
    Policy p = initializeEndpointPolicy(endpoint, bus);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    EndpointInfo ei = endpoint.getEndpointInfo();
    EndpointPolicy ep = pe.getServerEndpointPolicy(ei, null, null);
    pe.setServerEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus)));

    // Add policy to the service model (and consequently to the WSDL)
    // FIXME - ideally this should probably be moved up to where the policies are applied to the
    // endpoint, rather than this late.  As a consequence of its location, you have to declare a
    // ws policy feature on every endpoint in order to get any policy attachments into the
    // wsdl.  Alternatively add to the WSDLServiceBuilder somehow.
    ServiceModelPolicyUpdater pu = new ServiceModelPolicyUpdater(ei);
    for (PolicyProvider pp : ((PolicyEngineImpl) pe).getPolicyProviders()) {
        if (pp instanceof ExternalAttachmentProvider) {
            pu.addPolicyAttachments(((ExternalAttachmentProvider) pp).getAttachments());
        }
    }
}
 
Example 7
Source File: WSPolicyFeature.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Client client, Bus bus) {
    Endpoint endpoint = client.getEndpoint();
    Policy p = initializeEndpointPolicy(endpoint, bus);
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    EndpointInfo ei = endpoint.getEndpointInfo();
    EndpointPolicy ep = pe.getClientEndpointPolicy(ei, null, null);
    pe.setClientEndpointPolicy(ei, ep.updatePolicy(p, createMessage(endpoint, bus)));
}
 
Example 8
Source File: EndpointSelectionInterceptor.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Endpoint selectEndpoint(Message message, Set<Endpoint> eps) {
    SoapVersion sv = ((SoapMessage)message).getVersion();

    for (Endpoint e : eps) {
        EndpointInfo ei = e.getEndpointInfo();
        BindingInfo binding = ei.getBinding();

        if (binding instanceof SoapBindingInfo
            && ((SoapBindingInfo)binding).getSoapVersion().equals(sv)) {
            return e;
        }
    }

    return null;
}
 
Example 9
Source File: RMEndpoint.java    From cxf with Apache License 2.0 5 votes vote down vote up
void setPolicies(Message message) {
    // use same WS-policies as for application endpoint
    PolicyEngine engine = manager.getBus().getExtension(PolicyEngine.class);
    if (null == engine || !engine.isEnabled()) {
        return;
    }

    for (Endpoint endpoint : endpoints.values()) {
        EndpointInfo ei = endpoint.getEndpointInfo();
        EndpointPolicy epi = null == conduit
            ? engine.getServerEndpointPolicy(applicationEndpoint.getEndpointInfo(), null, message)
                : engine.getClientEndpointPolicy(applicationEndpoint.getEndpointInfo(), conduit, message);

        if (conduit != null) {
            engine.setClientEndpointPolicy(ei, epi);
        } else {
            engine.setServerEndpointPolicy(ei, epi);
        }
        EffectivePolicyImpl effectiveOutbound = new EffectivePolicyImpl();
        effectiveOutbound.initialise(epi, engine, false, false, message);
        EffectivePolicyImpl effectiveInbound = new EffectivePolicyImpl();
        effectiveInbound.initialise(epi, engine, true, false, message);

        BindingInfo bi = ei.getBinding();
        Collection<BindingOperationInfo> bois = bi.getOperations();

        for (BindingOperationInfo boi : bois) {
            engine.setEffectiveServerRequestPolicy(ei, boi, effectiveInbound);
            engine.setEffectiveServerResponsePolicy(ei, boi, effectiveOutbound);

            engine.setEffectiveClientRequestPolicy(ei, boi, effectiveOutbound);
            engine.setEffectiveClientResponsePolicy(ei, boi, effectiveInbound);
        }
    }

    // TODO: FaultPolicy (SequenceFault)
}
 
Example 10
Source File: MAPAggregatorImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
private EndpointReferenceType getReplyTo(Message message,
                                         EndpointReferenceType originalReplyTo) {
    Exchange exchange = message.getExchange();
    Endpoint info = exchange.getEndpoint();
    if (info == null) {
        return originalReplyTo;
    }
    synchronized (info) {
        EndpointInfo ei = info.getEndpointInfo();
        Destination dest = ei.getProperty(DECOUPLED_DESTINATION, Destination.class);
        if (dest == null) {
            dest = createDecoupledDestination(message);
            if (dest != null) {
                info.getEndpointInfo().setProperty(DECOUPLED_DESTINATION, dest);
            }
        }
        if (dest != null) {
            // if the decoupled endpoint context prop is set and the address is relative, return the absolute url.
            final String replyTo = dest.getAddress().getAddress().getValue();
            if (replyTo.startsWith("/")) {
                String debase =
                    (String)message.getContextualProperty(WSAContextUtils.DECOUPLED_ENDPOINT_BASE_PROPERTY);
                if (debase != null) {
                    return EndpointReferenceUtils.getEndpointReference(debase + replyTo);
                }
            }
            return dest.getAddress();
        }
    }
    return originalReplyTo;
}
 
Example 11
Source File: WSS4JUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ReplayCache instance. It first checks to see whether caching has been explicitly 
 * enabled or disabled via the booleanKey argument. If it has been set to false then no
 * replay caching is done (for this booleanKey). If it has not been specified, then caching
 * is enabled only if we are not the initiator of the exchange. If it has been specified, then
 * caching is enabled.
 * 
 * It tries to get an instance of ReplayCache via the instanceKey argument from a 
 * contextual property, and failing that the message exchange. If it can't find any, then it
 * defaults to using an EH-Cache instance and stores that on the message exchange.
 */
public static ReplayCache getReplayCache(
    SoapMessage message, String booleanKey, String instanceKey
) {
    boolean specified = false;
    Object o = message.getContextualProperty(booleanKey);
    if (o != null) {
        if (!MessageUtils.isTrue(o)) {
            return null;
        }
        specified = true;
    }

    if (!specified && MessageUtils.isRequestor(message)) {
        return null;
    }
    Endpoint ep = message.getExchange().get(Endpoint.class);
    if (ep != null && ep.getEndpointInfo() != null) {
        EndpointInfo info = ep.getEndpointInfo();
        synchronized (info) {
            ReplayCache replayCache = 
                    (ReplayCache)message.getContextualProperty(instanceKey);
            if (replayCache == null) {
                replayCache = (ReplayCache)info.getProperty(instanceKey);
            }
            if (replayCache == null) {
                ReplayCacheFactory replayCacheFactory = ReplayCacheFactory.newInstance();
                String cacheKey = instanceKey;
                if (info.getName() != null) {
                    cacheKey += "-" + info.getName().toString().hashCode();
                }
                replayCache = replayCacheFactory.newReplayCache(cacheKey, message);
                info.setProperty(instanceKey, replayCache);
            }
            return replayCache;
        }
    }
    return null;
}
 
Example 12
Source File: ServiceUtils.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static SchemaValidationType getSchemaValidationTypeFromModel(Message message) {
    Exchange exchange = message.getExchange();
    SchemaValidationType validationType = null;

    if (exchange != null) {

        BindingOperationInfo boi = exchange.getBindingOperationInfo();
        if (boi != null) {
            OperationInfo opInfo = boi.getOperationInfo();
            if (opInfo != null) {
                validationType = getSchemaValidationTypeFromModel(opInfo);
            }
        }

        if (validationType == null) {
            Endpoint endpoint = exchange.getEndpoint();
            if (endpoint != null) {
                EndpointInfo ep = endpoint.getEndpointInfo();
                if (ep != null) {
                    validationType = getSchemaValidationTypeFromModel(ep);
                }
            }
        }
    }

    return validationType;
}
 
Example 13
Source File: WrappedMessageContext.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static EndpointInfo getEndpointInfo(Exchange exchange) {
    if (exchange != null) {
        Endpoint endpoint = exchange.getEndpoint();
        if (endpoint != null) {
            return endpoint.getEndpointInfo();
        }
    }
    return null;
}
 
Example 14
Source File: WSS4JUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ReplayCache instance. It first checks to see whether caching has been explicitly 
 * enabled or disabled via the booleanKey argument. If it has been set to false then no
 * replay caching is done (for this booleanKey). If it has not been specified, then caching
 * is enabled only if we are not the initiator of the exchange. If it has been specified, then
 * caching is enabled.
 * 
 * It tries to get an instance of ReplayCache via the instanceKey argument from a 
 * contextual property, and failing that the message exchange. If it can't find any, then it
 * defaults to using an EH-Cache instance and stores that on the message exchange.
 */
public static ReplayCache getReplayCache(
    SoapMessage message, String booleanKey, String instanceKey
) {
    boolean specified = false;
    Object o = message.getContextualProperty(booleanKey);
    if (o != null) {
        if (!MessageUtils.isTrue(o)) {
            return null;
        }
        specified = true;
    }

    if (!specified && MessageUtils.isRequestor(message)) {
        return null;
    }
    Endpoint ep = message.getExchange().get(Endpoint.class);
    if (ep != null && ep.getEndpointInfo() != null) {
        EndpointInfo info = ep.getEndpointInfo();
        synchronized (info) {
            ReplayCache replayCache = 
                    (ReplayCache)message.getContextualProperty(instanceKey);
            if (replayCache == null) {
                replayCache = (ReplayCache)info.getProperty(instanceKey);
            }
            if (replayCache == null) {
                ReplayCacheFactory replayCacheFactory = ReplayCacheFactory.newInstance();
                String cacheKey = instanceKey;
                if (info.getName() != null) {
                    cacheKey += "-" + info.getName().toString().hashCode();
                }
                replayCache = replayCacheFactory.newReplayCache(cacheKey, message);
                info.setProperty(instanceKey, replayCache);
            }
            return replayCache;
        }
    }
    return null;
}
 
Example 15
Source File: WSS4JUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ReplayCache instance. It first checks to see whether caching has been explicitly 
 * enabled or disabled via the booleanKey argument. If it has been set to false then no
 * replay caching is done (for this booleanKey). If it has not been specified, then caching
 * is enabled only if we are not the initiator of the exchange. If it has been specified, then
 * caching is enabled.
 * 
 * It tries to get an instance of ReplayCache via the instanceKey argument from a 
 * contextual property, and failing that the message exchange. If it can't find any, then it
 * defaults to using an EH-Cache instance and stores that on the message exchange.
 */
public static ReplayCache getReplayCache(
    SoapMessage message, String booleanKey, String instanceKey
) {
    boolean specified = false;
    Object o = message.getContextualProperty(booleanKey);
    if (o != null) {
        if (!MessageUtils.isTrue(o)) {
            return null;
        }
        specified = true;
    }

    if (!specified && MessageUtils.isRequestor(message)) {
        return null;
    }
    Endpoint ep = message.getExchange().get(Endpoint.class);
    if (ep != null && ep.getEndpointInfo() != null) {
        EndpointInfo info = ep.getEndpointInfo();
        synchronized (info) {
            ReplayCache replayCache = 
                    (ReplayCache)message.getContextualProperty(instanceKey);
            if (replayCache == null) {
                replayCache = (ReplayCache)info.getProperty(instanceKey);
            }
            if (replayCache == null) {
                ReplayCacheFactory replayCacheFactory = ReplayCacheFactory.newInstance();
                String cacheKey = instanceKey;
                if (info.getName() != null) {
                    cacheKey += "-" + info.getName().toString().hashCode();
                }
                replayCache = replayCacheFactory.newReplayCache(cacheKey, message);
                info.setProperty(instanceKey, replayCache);
            }
            return replayCache;
        }
    }
    return null;
}
 
Example 16
Source File: WSS4JUtils.java    From steady with Apache License 2.0 5 votes vote down vote up
/**
 * Get a ReplayCache instance. It first checks to see whether caching has been explicitly 
 * enabled or disabled via the booleanKey argument. If it has been set to false then no
 * replay caching is done (for this booleanKey). If it has not been specified, then caching
 * is enabled only if we are not the initiator of the exchange. If it has been specified, then
 * caching is enabled.
 * 
 * It tries to get an instance of ReplayCache via the instanceKey argument from a 
 * contextual property, and failing that the message exchange. If it can't find any, then it
 * defaults to using an EH-Cache instance and stores that on the message exchange.
 */
public static ReplayCache getReplayCache(
    SoapMessage message, String booleanKey, String instanceKey
) {
    boolean specified = false;
    Object o = message.getContextualProperty(booleanKey);
    if (o != null) {
        if (!MessageUtils.isTrue(o)) {
            return null;
        }
        specified = true;
    }

    if (!specified && MessageUtils.isRequestor(message)) {
        return null;
    }
    Endpoint ep = message.getExchange().get(Endpoint.class);
    if (ep != null && ep.getEndpointInfo() != null) {
        EndpointInfo info = ep.getEndpointInfo();
        synchronized (info) {
            ReplayCache replayCache = 
                    (ReplayCache)message.getContextualProperty(instanceKey);
            if (replayCache == null) {
                replayCache = (ReplayCache)info.getProperty(instanceKey);
            }
            if (replayCache == null) {
                ReplayCacheFactory replayCacheFactory = ReplayCacheFactory.newInstance();
                String cacheKey = instanceKey;
                if (info.getName() != null) {
                    cacheKey += "-" + info.getName().toString().hashCode();
                }
                replayCache = replayCacheFactory.newReplayCache(cacheKey, message);
                info.setProperty(instanceKey, replayCache);
            }
            return replayCache;
        }
    }
    return null;
}
 
Example 17
Source File: PolicyVerificationInInterceptor.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Determines the effective policy, and checks if one of its alternatives
 * is supported.
 *
 * @param message
 * @throws PolicyException if none of the alternatives is supported
 */
protected void handle(Message message) {

    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }

    Exchange exchange = message.getExchange();
    BindingOperationInfo boi = exchange.getBindingOperationInfo();
    if (null == boi) {
        LOG.fine("No binding operation info.");
        return;
    }

    Endpoint e = exchange.getEndpoint();
    if (null == e) {
        LOG.fine("No endpoint.");
        return;
    }

    Bus bus = exchange.getBus();
    PolicyEngine pe = bus.getExtension(PolicyEngine.class);
    if (null == pe) {
        return;
    }

    if (MessageUtils.isPartialResponse(message)) {
        LOG.fine("Not verifying policies on inbound partial response.");
        return;
    }

    getTransportAssertions(message);

    EffectivePolicy effectivePolicy = message.get(EffectivePolicy.class);
    if (effectivePolicy == null) {
        EndpointInfo ei = e.getEndpointInfo();
        if (MessageUtils.isRequestor(message)) {
            effectivePolicy = pe.getEffectiveClientResponsePolicy(ei, boi, message);
        } else {
            effectivePolicy = pe.getEffectiveServerRequestPolicy(ei, boi, message);
        }
    }
    try {
        List<List<Assertion>> usedAlternatives = aim.checkEffectivePolicy(effectivePolicy.getPolicy());
        if (usedAlternatives != null && !usedAlternatives.isEmpty() && message.getExchange() != null) {
            message.getExchange().put("ws-policy.validated.alternatives", usedAlternatives);
        }
    } catch (PolicyException ex) {
        LOG.log(Level.SEVERE, "Inbound policy verification failed: " + ex.getMessage());
        //To check if there is ws addressing policy violation and throw WSA specific
        //exception to pass jaxws2.2 tests
        if (ex.getMessage().indexOf("Addressing") > -1) {
            throw new Fault("A required header representing a Message Addressing Property "
                                + "is not present", LOG)
                .setFaultCode(new QName("http://www.w3.org/2005/08/addressing",
                                          "MessageAddressingHeaderRequired"));
        }
        throw ex;
    }
    LOG.fine("Verified policies for inbound message.");
}
 
Example 18
Source File: WSS4JUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
/**
 * Get a ReplayCache instance. It first checks to see whether caching has been explicitly
 * enabled or disabled via the booleanKey argument. If it has been set to false then no
 * replay caching is done (for this booleanKey). If it has not been specified, then caching
 * is enabled only if we are not the initiator of the exchange. If it has been specified, then
 * caching is enabled.
 *
 * It tries to get an instance of ReplayCache via the instanceKey argument from a
 * contextual property, and failing that the message exchange. If it can't find any, then it
 * defaults to using an EH-Cache instance and stores that on the message exchange.
 */
public static ReplayCache getReplayCache(
    SoapMessage message, String booleanKey, String instanceKey
) throws WSSecurityException {
    boolean specified = false;
    Object o = message.getContextualProperty(booleanKey);
    if (o != null) {
        if (!PropertyUtils.isTrue(o)) {
            return null;
        }
        specified = true;
    }

    if (!specified && MessageUtils.isRequestor(message)) {
        return null;
    }
    
    ReplayCache replayCache = (ReplayCache)message.getContextualProperty(instanceKey);
    Endpoint ep = message.getExchange().getEndpoint();
    if (replayCache == null && ep != null && ep.getEndpointInfo() != null) {
        EndpointInfo info = ep.getEndpointInfo();
        synchronized (info) {
            replayCache = (ReplayCache)info.getProperty(instanceKey);

            if (replayCache == null) {
                String cacheKey = instanceKey;
                if (info.getName() != null) {
                    int hashcode = info.getName().toString().hashCode();
                    if (hashcode < 0) {
                        cacheKey += hashcode;
                    } else {
                        cacheKey += "-" + hashcode;
                    }
                }
                if (WSS4JCacheUtil.isEhCacheInstalled()) {
                    Bus bus = message.getExchange().getBus();
                    Path diskstoreParent = null;
                    try {
                        diskstoreParent = Files.createTempDirectory("cxf");
                    } catch (IOException ex) {
                        throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, ex);
                    }
                    replayCache = new CXFEHCacheReplayCache(cacheKey, bus, diskstoreParent);
                } else {
                    replayCache = new MemoryReplayCache();
                }

                info.setProperty(instanceKey, replayCache);
            }
        }
    }
    return replayCache;
}
 
Example 19
Source File: CxfCdiAutoSetup.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
private Function<ServletDestination, String> getServletDestinationPath(ServletConfig sc, LogFacade log)
{
    return sd -> {
        final Endpoint endpoint = ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint();
        final ApplicationInfo app = ApplicationInfo.class.cast(endpoint.get(Application.class.getName()));
        final JAXRSServiceFactoryBean sfb = JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName()));
        final String base = sd.getEndpointInfo().getAddress();

        if (sfb != null) {
            final List<Logs.LogResourceEndpointInfo> resourcesToLog = new ArrayList<>();
            int classSize = 0;
            int addressSize = 0;

            final List<ClassResourceInfo> resources = sfb.getClassResourceInfo();
            for (final ClassResourceInfo info : resources) {
                if (info.getResourceClass() == null) { // possible?
                    continue;
                }

                final String address = Logs.singleSlash(base, info.getURITemplate().getValue());

                final String clazz = uproxyName(info.getResourceClass().getName());
                classSize = Math.max(classSize, clazz.length());
                addressSize = Math.max(addressSize, address.length());

                int methodSize = 7;
                int methodStrSize = 0;

                final List<Logs.LogOperationEndpointInfo> toLog = new ArrayList<>();

                final MethodDispatcher md = info.getMethodDispatcher();
                for (final OperationResourceInfo ori : md.getOperationResourceInfos()) {
                    final String httpMethod = ori.getHttpMethod();
                    final String currentAddress = Logs.singleSlash(address, ori.getURITemplate().getValue());
                    final String methodToStr = Logs.toSimpleString(ori.getMethodToInvoke());
                    toLog.add(new Logs.LogOperationEndpointInfo(httpMethod, currentAddress, methodToStr));

                    if (httpMethod != null) {
                        methodSize = Math.max(methodSize, httpMethod.length());
                    }
                    addressSize = Math.max(addressSize, currentAddress.length());
                    methodStrSize = Math.max(methodStrSize, methodToStr.length());
                }

                Collections.sort(toLog);

                resourcesToLog.add(new Logs.LogResourceEndpointInfo(address, clazz, toLog, methodSize, methodStrSize));
            }

            // effective logging
            log.info("REST Application: " + endpoint.getEndpointInfo().getAddress() + " -> "
                    + ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).map(CxfCdiAutoSetup::uproxyName).orElse(""));

            Collections.sort(resourcesToLog);
            final int fClassSize = classSize;
            final int fAddressSize = addressSize;
            resourcesToLog.forEach(resource -> {
                log.info("     Service URI: "
                        + Logs.forceLength(resource.address, fAddressSize, true) + " -> "
                        + Logs.forceLength(resource.classname, fClassSize, true));

                resource.operations.forEach(info -> {
                    log.info("          "
                            + Logs.forceLength(info.http, resource.methodSize, false) + " "
                            + Logs.forceLength(info.address, fAddressSize, true) + " ->      "
                            + Logs.forceLength(info.method, resource.methodStrSize, true));
                });
                resource.operations.clear();
            });
            resourcesToLog.clear();

            // log @Providers
            if (Configuration.class.cast(sc.getServletContext().getAttribute("meecrowave.configuration")).isJaxrsLogProviders()) {
                final ServerProviderFactory spf = ServerProviderFactory.class.cast(endpoint.get(ServerProviderFactory.class.getName()));
                dump(log, spf, "MessageBodyReaders", "messageReaders");
                dump(log, spf, "MessageBodyWriters", "messageWriters");
            }
        } else {
            final EndpointInfo endpointInfo = endpoint.getEndpointInfo();
            if (endpointInfo.getName() != null) {
                log.info("@WebService > " + endpointInfo.getName().toString() + " -> " + base);
            }
        }

        return base;
    };
}
 
Example 20
Source File: DefaultLogEventMapper.java    From cxf with Apache License 2.0 4 votes vote down vote up
private EndpointInfo getEPInfo(Message message) {
    Endpoint ep = message.getExchange().getEndpoint();
    return (ep == null) ? new EndpointInfo() : ep.getEndpointInfo();
}