org.apache.tuscany.sca.invocation.Message.getHeaders()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(225)

本文整理了Java中org.apache.tuscany.sca.invocation.Message.getHeaders()方法的一些代码示例,展示了Message.getHeaders()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.getHeaders()方法的具体详情如下:
包路径:org.apache.tuscany.sca.invocation.Message
类名称:Message
方法名:getHeaders

Message.getHeaders介绍

[英]Returns a list of objects that are contained in the message header
[中]返回消息头中包含的对象列表

代码示例

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Transfer relevant header information from the old message (incoming) to the new message (outgoing)
 * @param newMsg
 * @param oldMsg
 */
protected void transferMessageHeaders( Message newMsg, Message oldMsg ) {
  if( oldMsg == null ) return;
  // For the present, simply copy all the headers 
  if( !oldMsg.getHeaders().isEmpty() ) newMsg.getHeaders().putAll( oldMsg.getHeaders() );
} // end transferMessageHeaders

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Extracts the RELATES_TO header from the message
 * @param msg - the Tuscany message
 * @return - the value of the RELATES_TO header as a String
 */
private String getMessageRelatesID( Message msg ) {
  return (String)msg.getHeaders().get("RELATES_TO");
} // end method getMessageRelatesID

代码示例来源:origin: org.apache.tuscany.sca/tuscany-policy-security

public static Principal getPrincipal(Message msg){
    
    return (Principal)msg.getHeaders().get(PrincipalString);
  }    
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public static Principal getPrincipal(Message msg){
    
    return (Principal)msg.getHeaders().get(PrincipalString);
  }    
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-policy-security

public static Subject getSubject(Message msg){
  
  Subject subject = (Subject)msg.getHeaders().get(SubjectString);
  
  if (subject == null){
    subject = new Subject(); 
    msg.getHeaders().put(SubjectString, subject); 
  }
  
  return subject;
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public static Subject getSubject(Message msg){
  
  Subject subject = (Subject)msg.getHeaders().get(SubjectString);
  
  if (subject == null){
    subject = new Subject(); 
    msg.getHeaders().put(SubjectString, subject); 
  }
  
  return subject;
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public ResponseDispatchImpl( Message msg ) {
  super();
  
  respInvoker = (AsyncResponseInvoker<?>)msg.getHeaders().get(Constants.ASYNC_RESPONSE_INVOKER);
  //if( respInvoker == null ) throw new ServiceRuntimeException("Async Implementation invoked with no response invoker");
  
  if( respInvoker == null ) {
    callbackRef = getAsyncCallbackRef( msg );
  } // end if 
  
  messageID = (String) msg.getHeaders().get(Constants.MESSAGE_ID);
  
} // end constructor

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-ws-runtime-axis2

/**
 * Handle a SOAP wsa:MessageID header - place the contents into the Tuscany message for use by any callback
 * @param header - the SOAP Headers
 * @param msg - the Tuscany Message
 */
private void handleMessageIDHeader( SOAPHeader header, Message msg ) {
  if( header == null ) return;
  OMElement messageID = header.getFirstChildWithName(QNAME_WSA_MESSAGEID);
  if (messageID != null) {
    String idValue = messageID.getText();
    // Store the value of the message ID element into the message under "WS_MESSAGE_ID"...
    msg.getHeaders().put(Constants.MESSAGE_ID, idValue);
  } // end if
} // end method handleMessageID

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public Subject getSecuritySubject() {
  
  Message msgContext = ThreadMessageContext.getMessageContext();
  
  if (msgContext == null){
    // message in thread context could be null if the user has 
    // spun up a new thread inside their component implementation 
    return null;
  }
  
  Subject subject = null;
  for (Object header : msgContext.getHeaders().values()){
    if (header instanceof Subject){
      subject  = (Subject)header;
      break;
    }
  }
  return subject;
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/** 
 * If you have a Tuscany message you can call this
 */
public void invokeAsyncResponse(Message responseMessage) {
  responseMessage.getHeaders().put(Constants.ASYNC_RESPONSE_INVOKER, this);
  responseMessage.getHeaders().put(Constants.RELATES_TO, relatesToMsgID);
  
  if (isNativeAsync){
    // process the response as a native async response
    requestEndpoint.invokeAsyncResponse(responseMessage);
  } else {
    // process the response as a non-native async response
    responseEndpointReference.invoke(responseMessage);
  }
} // end method invokeAsyncReponse(Message)

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-ws-runtime-axis2

/**
   * Handle a SOAP wsa:RelatesTo header - place the contents into the Tuscany message for use by any callback
   * @param header - the SOAP Headers
   * @param msg - the Tuscany Message
   */
  private void handleRelatesToHeader( SOAPHeader header, Message msg ) {
    if( header == null ) return;
    OMElement messageID = header.getFirstChildWithName(QNAME_WSA_RELATESTO);
    if (messageID != null) {
      String idValue = messageID.getText();
      // Store the value of the message ID element into the message under "RELATES_TO"...
      msg.getHeaders().put(Constants.RELATES_TO, idValue);
    } // end if
  } // end method handleMessageID
} // end class AsyncResponseHandler

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Handle a SOAP wsa:RelatesTo header - place the contents into the Tuscany message for use by any callback
 * @param header - the SOAP Headers
 * @param msg - the Tuscany Message
 */
private void handleRelatesToHeader( SOAPHeader header, Message msg ) {
  if( header == null ) return;
  Iterator<SOAPElement> it = header.getChildElements(QNAME_WSA_RELATESTO);
  SOAPElement relatesTo = it.hasNext() ? it.next() : null;        
  if (relatesTo != null) {
    String relatesToVal = relatesTo.getTextContent();
    msg.getHeaders().put(Constants.RELATES_TO, relatesToVal);
  } // end if
} // end method handleRelatesToHeader

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Handle a SOAP wsa:MessageID header - place the contents into the Tuscany message for use by any callback
 * @param header - the SOAP Headers
 * @param msg - the Tuscany Message
 */
private void handleMessageIDHeader( SOAPHeader header, Message msg ) {
  if( header == null ) return;
  Iterator<SOAPElement> it = header.getChildElements(QNAME_WSA_MESSAGEID);
  SOAPElement messageID = it.hasNext() ? it.next() : null;
  if (messageID != null) {
    String idValue = messageID.getTextContent();
    msg.getHeaders().put(Constants.MESSAGE_ID, idValue);
  } // end if
} // end method handleMessageID

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-jms-runtime

public Message invokeRequest(Message tuscanyMsg) {
  
  try {
  
    javax.jms.Message jmsMsg = tuscanyMsg.getBody();
    
    // Handle MESSAGE_ID field of the JMS message, which is used to correlate async callbacks
    String msgID = (String)jmsMsg.getObjectProperty("MESSAGE_ID");
    if( msgID != null ) {
      tuscanyMsg.getHeaders().put("MESSAGE_ID", msgID);
    } // end if 
    //
  
  } catch (JMSException e) {
    throw new JMSBindingException(e);
  } // end try
  
  return tuscanyMsg;
} // end method invokeRequest

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Sets the values of various headers in the response message
 */
private void setResponseHeaders() {
  // Is there an existing message context?
  Message msgContext = ThreadMessageContext.getMessageContext();
  if( msgContext == null ) {
    // Create a message context
    msgContext = msgFactory.createMessage();
  } // end if
  
  // Add in the header for the RelatesTo Message ID
  msgContext.getHeaders().put(Constants.RELATES_TO, messageID);
  
  ThreadMessageContext.setMessageContext(msgContext);
} // end method setResponseHeaders

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public Message invoke(Message msg) {
  // Deal with async callback
  // Ensure invocation chains are built...
  getInvocationChains();
  // async callback handling
  if( this.isAsyncInvocation() && !this.getCallbackEndpointReferences().isEmpty() ) {
    RuntimeEndpointReference asyncEPR = (RuntimeEndpointReference) this.getCallbackEndpointReferences().get(0);
    // Place a link to the callback EPR into the message headers...
    msg.getHeaders().put(Constants.ASYNC_CALLBACK, asyncEPR );
  } 
  // end of async callback handling
  return invoker.invokeBinding(msg);
}

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

public void invokeAsyncResponse(Message msg) {
  msg = processResponse(msg);
  // Handle async response Relates_To message ID value
  @SuppressWarnings("unchecked")
  AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = 
    (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
  // TODO - this deals with the Local case only - not distributed
  if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) {
    RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress();
    msg.setFrom(responseEPR);
    String msgID = respInvoker.getRelatesToMsgID();
    msg.getHeaders().put("RELATES_TO", msgID);
  } // end if
  InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious();
  if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg);
} // end method invokeAsyncResponse

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-ws-runtime-axis2

/**
 * Setup the necessary infrastructure for the Async response handling
 * @param msg
 * @param callbackAddress 
 */
private void setupAsyncResponse(Message msg, String callbackAddress) {
  if( !endpoint.isAsyncInvocation() ) return;
  endpoint.createAsyncServerCallback();
  RuntimeEndpointReference asyncCallback = endpoint.getAsyncServerCallback();
  
  // Create a response invoker, containing the callback address and add it to the message headers
  AsyncResponseInvoker<String> respInvoker = 
    new AsyncResponseInvoker<String>(endpoint, asyncCallback,
        callbackAddress, 
        (String)msg.getHeaders().get(Constants.MESSAGE_ID),
        msg.getOperation().getName(), messageFactory);
  msg.getHeaders().put(Constants.ASYNC_RESPONSE_INVOKER, respInvoker);
} // end method setupAsyncResponse

代码示例来源:origin: org.apache.tuscany.sca/tuscany-binding-sca-runtime

public void invokeAsyncResponse(Message msg) {
  msg = processResponse(msg);
  // Handle async response Relates_To message ID value
  @SuppressWarnings("unchecked")
  AsyncResponseInvoker<RuntimeEndpointReference> respInvoker = 
    (AsyncResponseInvoker<RuntimeEndpointReference>)msg.getHeaders().get("ASYNC_RESPONSE_INVOKER");
  // TODO - this deals with the Local case only - not distributed
  if( respInvoker != null && "SCA_LOCAL".equals(respInvoker.getBindingType()) ) {
    RuntimeEndpointReference responseEPR = respInvoker.getResponseTargetAddress();
    msg.setFrom(responseEPR);
    String msgID = respInvoker.getRelatesToMsgID();
    msg.getHeaders().put("RELATES_TO", msgID);
  } // end if
  InvokerAsyncResponse thePrevious = (InvokerAsyncResponse)getPrevious();
  if (thePrevious != null ) thePrevious.invokeAsyncResponse(msg);
} // end method invokeAsyncResponse

代码示例来源:origin: org.apache.tuscany.sca/tuscany-base-runtime

/**
 * Creates a service reference for the async callback, based on information contained in the supplied message
 * @param msg - the incoming message
 * @return - a CallBackServiceReference
 */
@SuppressWarnings("unchecked")
private ServiceReference<AsyncResponseHandler<?>> getAsyncCallbackRef( Message msg ) { 
  RuntimeEndpointReference callbackEPR = (RuntimeEndpointReference) msg.getHeaders().get(Constants.ASYNC_CALLBACK);
  if( callbackEPR == null ) return null;
  
  CompositeContext compositeContext = callbackEPR.getCompositeContext();
  registry = compositeContext.getExtensionPointRegistry();
  ProxyFactory proxyFactory = ExtensibleProxyFactory.getInstance(registry);
  msgFactory = getMessageFactory();
  List<EndpointReference> eprList = new ArrayList<EndpointReference>();
  eprList.add(callbackEPR);
  ObjectFactory<?> factory = new CallbackReferenceObjectFactory(AsyncResponseHandler.class, proxyFactory, eprList);
  
  return (ServiceReference<AsyncResponseHandler<?>>) factory.getInstance();
  
} // end method getAsyncCallbackEPR

相关文章