當前位置: 首頁>>代碼示例>>Java>>正文


Java MessageContext類代碼示例

本文整理匯總了Java中javax.xml.ws.handler.MessageContext的典型用法代碼示例。如果您正苦於以下問題:Java MessageContext類的具體用法?Java MessageContext怎麽用?Java MessageContext使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


MessageContext類屬於javax.xml.ws.handler包,在下文中一共展示了MessageContext類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createWebServiceContextMock

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
private WebServiceContext createWebServiceContextMock(String expectedIP,
        String expectedUser) {
    requestMock = mock(HttpServletRequest.class);
    when(requestMock.getRemoteAddr()).thenReturn(expectedIP);

    Principal principalMock = mock(Principal.class);
    when(principalMock.getName()).thenReturn(expectedUser);

    MessageContext msgContextMock = mock(MessageContext.class);
    when(msgContextMock.get(anyString())).thenReturn(requestMock);

    WebServiceContext wsContextMock = mock(WebServiceContext.class);
    when(wsContextMock.getUserPrincipal()).thenReturn(principalMock);
    when(wsContextMock.getMessageContext()).thenReturn(msgContextMock);

    return wsContextMock;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:18,代碼來源:CategorizationServiceWSTest.java

示例2: getCaller

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * @return a token which contains a random Unique ID per caller and the caller IP as well
 */
private String getCaller() {

    MessageContext msgx = wsContext.getMessageContext();

    HttpServletRequest request = ((HttpServletRequest) msgx.get(MessageContext.SERVLET_REQUEST));

    String uid = "";
    try {
        Map<String, List<String>> headers = (Map<String, List<String>>) msgx.get(MessageContext.HTTP_REQUEST_HEADERS);
        uid = headers.get(ApplicationContext.ATS_UID_SESSION_TOKEN).get(0);
    } catch (Exception e) {
        if (!alreadyLoggedErrorAboutSessionUid) {
            log.warn("Could not get ATS UID for call from " + request.getRemoteAddr()
                     + ". This error will not be logged again before Agent restart.", e);
            alreadyLoggedErrorAboutSessionUid = true;
        }
    }

    return "<Caller: " + request.getRemoteAddr() + "; ATS UID: " + uid + ">";
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:24,代碼來源:AgentWsImpl.java

示例3: closeServersideHandlers

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * Called by close(MessageContext mc) in a Server Handlertube
 */
protected void closeServersideHandlers(MessageContext msgContext) {
    if (processor == null)
        return;
    if (remedyActionTaken) {
        //Close only invoked handlers in the chain

        //SERVER-SIDE
        processor.closeHandlers(msgContext, processor.getIndex(), handlers.size() - 1);
        processor.setIndex(-1);
        //reset remedyActionTaken
        remedyActionTaken = false;
    } else {
        //Close all handlers in the chain

        //SERVER-SIDE
        processor.closeHandlers(msgContext, 0, handlers.size() - 1);

    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:HandlerTube.java

示例4: callHandlersOnResponse

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
            Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
            attSet.add(att);
        }
    }

    try {
        //SERVER-SIDE
        processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

    } catch (WebServiceException wse) {
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        throw re;

    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:25,代碼來源:ServerMessageHandlerTube.java

示例5: get

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
@Override
@SuppressWarnings("element-type-mismatch")
public Object get(Object key) {
    if (packet.supports(key)) {
        return packet.get(key);    // strongly typed
    }
    if (packet.getHandlerScopePropertyNames(true).contains(key)) {
        return null;            // no such application-scope property
    }
    Object value =  packet.invocationProperties.get(key);

    //add the attachments from the Message to the corresponding attachment property
    if(key.equals(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS) ||
            key.equals(MessageContext.INBOUND_MESSAGE_ATTACHMENTS)){
        Map<String, DataHandler> atts = (Map<String, DataHandler>) value;
        if(atts == null)
            atts = new HashMap<String, DataHandler>();
        AttachmentSet attSet = packet.getMessage().getAttachments();
        for(Attachment att : attSet){
            atts.put(att.getContentId(), att.asDataHandler());
        }
        return atts;
    }
    return value;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:EndpointMessageContextImpl.java

示例6: callHandlersOnResponse

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {

        //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
        Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
        AttachmentSet attSet = context.packet.getMessage().getAttachments();
        for (Map.Entry<String, DataHandler> entry : atts.entrySet()) {
            String cid = entry.getKey();
            if (attSet.get(cid) == null) { // Otherwise we would be adding attachments twice
                Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
                attSet.add(att);
            }
        }

        try {
            //SERVER-SIDE
            processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

        } catch (WebServiceException wse) {
            //no rewrapping
            throw wse;
        } catch (RuntimeException re) {
            throw re;

        }
    }
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:ServerSOAPHandlerTube.java

示例7: callHandlersOnResponse

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
void callHandlersOnResponse(MessageUpdatableContext context, boolean handleFault) {
    //Lets copy all the MessageContext.OUTBOUND_ATTACHMENT_PROPERTY to the message
    Map<String, DataHandler> atts = (Map<String, DataHandler>) context.get(MessageContext.OUTBOUND_MESSAGE_ATTACHMENTS);
    AttachmentSet attSet = context.packet.getMessage().getAttachments();
    for (Entry<String, DataHandler> entry : atts.entrySet()) {
        String cid = entry.getKey();
        Attachment att = new DataHandlerAttachment(cid, atts.get(cid));
        attSet.add(att);
    }

    try {
        //SERVER-SIDE
        processor.callHandlersResponse(HandlerProcessor.Direction.OUTBOUND, context, handleFault);

    } catch (WebServiceException wse) {
        //no rewrapping
        throw wse;
    } catch (RuntimeException re) {
        throw re;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:22,代碼來源:ServerLogicalHandlerTube.java

示例8: close

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * Calls close on previously invoked handlers.
 * Also, Cleans up any state left over in the Tube instance from the current
 * invocation, as Tube instances can be reused after the completion of MEP.
 *
 * On Client, SOAPHandlers are closed first and then LogicalHandlers
 * On Server, LogicalHandlers are closed first and then SOAPHandlers
 */
final public void close(MessageContext msgContext) {
    //assuming cousinTube is called if requestProcessingSucessful is true
    if (requestProcessingSucessful) {
        if (cousinTube != null) {
            cousinTube.close(msgContext);
        }

    }
    if (processor != null)
        closeHandlers(msgContext);

    // Clean up the exchange for next invocation.
    exchange = null;
    requestProcessingSucessful = false;

}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:HandlerTube.java

示例9: closeClientsideHandlers

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * Called by close(MessageContext mc) in a Client Handlertube
 */
protected void closeClientsideHandlers(MessageContext msgContext) {
     if (processor == null)
        return;
    if (remedyActionTaken) {
        //Close only invoked handlers in the chain

        //CLIENT-SIDE
        processor.closeHandlers(msgContext, processor.getIndex(), 0);
        processor.setIndex(-1);
        //reset remedyActionTaken
        remedyActionTaken = false;
    } else {
        //Close all handlers in the chain

        //CLIENT-SIDE
        processor.closeHandlers(msgContext, handlers.size() - 1, 0);

    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:HandlerTube.java

示例10: createPacket

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
Packet createPacket(SOAPMessage arg) {
    Iterator iter = arg.getMimeHeaders().getAllHeaders();
    Headers ch = new Headers();
    while(iter.hasNext()) {
        MimeHeader mh = (MimeHeader) iter.next();
        ch.add(mh.getName(), mh.getValue());
    }
    Packet packet = new Packet(SAAJFactory.create(arg));
    packet.invocationProperties.put(MessageContext.HTTP_REQUEST_HEADERS, ch);
    return packet;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:12,代碼來源:SOAPMessageDispatch.java

示例11: handleMessage

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
@Override
public boolean handleMessage(final SOAPMessageContext msgCtx) {

    // Indicator telling us which direction this message is going in
    final Boolean outInd = (Boolean) msgCtx.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);

    // Handler must only add security headers to outbound messages
    if (outInd.booleanValue()) {
        try {
            // Get the SOAP Envelope
            final SOAPEnvelope envelope = msgCtx.getMessage().getSOAPPart().getEnvelope();

            // Header may or may not exist yet
            SOAPHeader header = envelope.getHeader();
            if (header == null)
                header = envelope.addHeader();

            // Add WSS Usertoken Element Tree 
            final SOAPElement security = header.addChildElement("Security", "wsse",
                    "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
            final SOAPElement userToken = security.addChildElement("UsernameToken", "wsse");
            userToken.addChildElement("Username", "wsse").addTextNode(userId);
            userToken.addChildElement("Password", "wsse").addAttribute(new QName("Type"), "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText").addTextNode(password);

        } catch (final Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    return true;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:32,代碼來源:SOAPSecurityHandler.java

示例12: handleMessage

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * The method is invoked for normal processing of outbound messages.
 * 
 * @param context
 *            the message context.
 * @return An indication of whether handler processing should continue for
 *         the current message. Return <code>true</code> to continue
 *         processing.
 * 
 * @throws Exception
 *             Causes the JAX-WS runtime to cease fault message processing.
 **/
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request_p = (Boolean) context
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (request_p.booleanValue()) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader hdr = env.getHeader();
            if (hdr == null) {
                hdr = env.addHeader();
            }
            QName qname_user = new QName("http://com/auth/", "auth");
            SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
            helem_user.setActor(VERSION);
            if (version != null && version.trim().length() != 0) {
                helem_user.addTextNode(version);
            }

            msg.saveChanges();
            message = soapMessage2String(msg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return true;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:41,代碼來源:VersionHandlerCtmg.java

示例13: getReferenceParameters

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * Gives a list of Reference Parameters in the Message
 * <p>
 * Headers which have attribute wsa:IsReferenceParameter="true"
 * This is not cached as one may reset the Message.
 *<p>
 */
@Property(MessageContext.REFERENCE_PARAMETERS)
public
@NotNull
List<Element> getReferenceParameters() {
    Message msg = getMessage();
    List<Element> refParams = new ArrayList<Element>();
    if (msg == null) {
        return refParams;
    }
    MessageHeaders hl = msg.getHeaders();
    for (Header h : hl.asList()) {
        String attr = h.getAttribute(AddressingVersion.W3C.nsUri, "IsReferenceParameter");
        if (attr != null && (attr.equals("true") || attr.equals("1"))) {
            Document d = DOMUtil.createDom();
            SAX2DOMEx s2d = new SAX2DOMEx(d);
            try {
                h.writeTo(s2d, XmlUtil.DRACONIAN_ERROR_HANDLER);
                refParams.add((Element) d.getLastChild());
            } catch (SAXException e) {
                throw new WebServiceException(e);
            }
            /*
            DOMResult result = new DOMResult(d);
            XMLDOMWriterImpl domwriter = new XMLDOMWriterImpl(result);
            try {
                h.writeTo(domwriter);
                refParams.add((Element) result.getNode().getLastChild());
            } catch (XMLStreamException e) {
                throw new WebServiceException(e);
            }
            */
        }
    }
    return refParams;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:43,代碼來源:Packet.java

示例14: handleMessage

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
/**
 * The method is invoked for normal processing of outbound messages.
 * 
 * @param context
 *            the message context.
 * @return An indication of whether handler processing should continue for
 *         the current message. Return <code>true</code> to continue
 *         processing.
 * 
 * @throws Exception
 *             Causes the JAX-WS runtime to cease fault message processing.
 **/
@Override
public boolean handleMessage(SOAPMessageContext context) {
    Boolean request_p = (Boolean) context
            .get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
    if (request_p.booleanValue()) {
        try {
            SOAPMessage msg = context.getMessage();
            SOAPEnvelope env = msg.getSOAPPart().getEnvelope();
            SOAPHeader hdr = env.getHeader();
            if (hdr == null) {
                hdr = env.addHeader();
            }
            QName qname_user = new QName("http://com/auth/", "auth");
            SOAPHeaderElement helem_user = hdr.addHeaderElement(qname_user);
            helem_user.setActor(VERSION);
            if (version == null || version.trim().length() == 0) {
                helem_user.addTextNode(apiVersionInfo.getProperty(VERSION));
            } else {
                helem_user.addTextNode(version);
            }

            msg.saveChanges();
            message = soapMessage2String(msg);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return true;
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:43,代碼來源:VersionHandler.java

示例15: setup

import javax.xml.ws.handler.MessageContext; //導入依賴的package包/類
@Before
public void setup() {

    httpRequestMock = mock(HttpServletRequest.class);
    when(httpRequestMock.getHeader("x-forwarded-for"))
            .thenReturn("1.1.1.1");
    when(httpRequestMock.getHeader("X-Forwarded-For"))
            .thenReturn("1.1.1.2");
    when(httpRequestMock.getRemoteAddr()).thenReturn("255.255.255.255");
    wsContextMock = mock(WebServiceContext.class);
    MessageContext msgContextMock = mock(MessageContext.class);
    when(msgContextMock.get(MessageContext.SERVLET_REQUEST)).thenReturn(
            httpRequestMock);
    when(wsContextMock.getMessageContext()).thenReturn(msgContextMock);
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:16,代碼來源:IPResolverTest.java


注:本文中的javax.xml.ws.handler.MessageContext類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。