当前位置: 首页>>代码示例>>Java>>正文


Java Header.getObject方法代码示例

本文整理汇总了Java中org.apache.cxf.headers.Header.getObject方法的典型用法代码示例。如果您正苦于以下问题:Java Header.getObject方法的具体用法?Java Header.getObject怎么用?Java Header.getObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cxf.headers.Header的用法示例。


在下文中一共展示了Header.getObject方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleMessage

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
	Header header = message.getHeader(new QName("equella"));
	if( header != null )
	{
		Element e = (Element) header.getObject();
		PropBagEx equella = new PropBagEx(e);
		String token = equella.getNode("token");
		if( !Check.isEmpty(token) )
		{
			HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
			try
			{
				userService.loginWithToken(token, userService.getWebAuthenticationDetails(request), true);
			}
			catch( RuntimeException ex )
			{
				LOGGER.error("Error initialising session with SOAP header token '" + token + "' for URL "
					+ request.getRequestURL().toString());
				throw ex;
			}
		}
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:26,代码来源:TokenHeaderInInterceptor.java

示例2: validateReturnedOutOfBandHeader

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext, boolean expect) {
    OutofBandHeader hdrToTest = null;
    List<Header> oobHdr = CastUtils.cast((List<?>)responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }

    assertTrue("HeaderHolder list expected to conain 1 object received " + oobHdr.size(),
               oobHdr.size() == 1);

    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>)JAXBContext
                    .newInstance(org.apache.cxf.outofband.header.ObjectFactory.class)
                    .createUnmarshaller().unmarshal((Node)hdr1.getObject());
                hdrToTest = (OutofBandHeader)job.getValue();
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }

    assertNotNull("out-of-band header should not be null", hdrToTest);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :"
               + hdrToTest.getName(), "testOobReturnHeaderName".equals(hdrToTest.getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :"
               + hdrToTest.getValue(), "testOobReturnHeaderValue".equals(hdrToTest.getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :"
               + hdrToTest.getHdrAttribute(), "testReturnHdrAttribute"
        .equals(hdrToTest.getHdrAttribute()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:CxfMessageHeadersRelayTest.java

示例3: handleMessage

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
public void handleMessage(SoapMessage message) throws Fault {
	List<Header> headers = message.getHeaders();
    
    if(headers==null){
    	throw new Fault(new SOAPException("Request must include authentication token.")); 
    }
    
    boolean foundToken = false;
    String systemId = "";
    String systemPw = "";
    for (Header header : headers) {
    	Element element = (Element) header.getObject();
    	
    	if(ELEMENT_TOKEN.equalsIgnoreCase(element.getNodeName())
    			&& NAMESPACE_URI.equalsIgnoreCase(element.getNamespaceURI())){
    		//found
    		foundToken = true;
    		
    		//SYSTEM_ID
    		Node systemIdNode = element.getFirstChild();
    		systemId = systemIdNode.getTextContent();
    		
    		//SYSTEM_PW
    		Node systemPwNode = element.getLastChild();
    		systemPw = systemPwNode.getTextContent();
    		
    		break;
    	}else{
    		//continue finding
    		continue;
    	}
    }
    
    if(!foundToken){
    	throw new Fault(new SOAPException("Request must include authentication token: " + ELEMENT_TOKEN)); 
    }else{
    	System.out.println("==>Received " + ELEMENT_SYSTEM_ID + "=" + systemId);
    	System.out.println("==>Received " + ELEMENT_SYSTEM_PW + "=" + systemPw);
    }
}
 
开发者ID:brightzheng100,项目名称:learning-spring-cxf,代码行数:41,代码来源:SystemTokenServerInterceptor.java

示例4: extractDelegationIdentifierFromHeaders

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
private DelegationIdentifier extractDelegationIdentifierFromHeaders() throws CDSInternalFaultFaultMessage {
    DelegationIdentifier did = null;

    List<Header> headers = getHeaders();
    if (headers != null) {
        for (Header h : headers) {
            QName hName = h.getName();
            if (hName.equals(RESOURCE_KEY)) {
                logger.debug("Found resource key.");
                Object o = h.getObject();
                try {
                    did = getDelegationId((Node) o);
                    if (did != null) {
                        break;
                    }
                    // JAXBContext jaxbContext = JAXBUtils.getJAXBContext(DelegationIdentifier.class);
                    // o = jaxbContext.createUnmarshaller().unmarshal((Node) o);
                    // if (o instanceof DelegationIdentifier) {
                    // did = (DelegationIdentifier) o;
                    // logger.debug("Set resource key to:" + did);
                    // break;
                    // } else {
                    // logger.error("Problem deserializing soap header; got unexpected type.");
                    // throw new CDSInternalFaultFaultMessage("Problem deserializing soap header; got unexpected type.");
                    // }
                    // } catch (JAXBException e) {
                } catch (Exception e) {
                    logger.error("Problem deserializing soap header: " + e.toString(), e);
                    throw new CDSInternalFaultFaultMessage("Problem deserializing soap header: " + e.getMessage());
                }
            } else {
                logger.debug("Ignoring header:" + hName);
            }
        }
    } else {
        logger.error("Unable to locate SOAP headers.");
        throw new CDSInternalFaultFaultMessage("Unable to locate SOAP headers.");
    }
    return did;
}
 
开发者ID:NCIP,项目名称:cagrid2,代码行数:41,代码来源:DCSWSRFImpl.java

示例5: getUsername

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
private String getUsername() {
    MessageContext messageContext = context.getMessageContext();
    if (messageContext == null || !(messageContext instanceof WrappedMessageContext)) {
        LOG.error("Message context is null or not an instance of WrappedMessageContext.");
        return null;
    }

    Message message = ((WrappedMessageContext) messageContext).getWrappedMessage();
    List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
    if (headers != null) {
        for (Header h : headers) {
            Object o = h.getObject();
            // Unwrap the node using JAXB
            if (o instanceof Node) {
                JAXBContext jaxbContext;
                try {
                    // TODO: Check performance
                    jaxbContext = new JAXBDataBinding(Credentials.class).getContext();
                    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
                    o = unmarshaller.unmarshal((Node) o);
                } catch (JAXBException e) {
                    // failed to get the credentials object from the headers
                    LOG.error("JAXB error trying to unwrap credentials", e);
                }
            }
            if (o instanceof Credentials) {
                Credentials c = (Credentials) o;

                // Note: We're using the username as session ID.
                String username = c.getSessionId();
                if (username == null) {
                    LOG.debug("No session id in credentials object, get from login");
                    username = c.getLogin().getUsername();
                }
                return username;
            } else {
                LOG.error("No credentials object");
            }
        }
    } else {
        LOG.error("No headers found");
    }
    return null;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:45,代码来源:SonosService.java

示例6: validateReturnedOutOfBandHeaderWithInsertion

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
protected static void validateReturnedOutOfBandHeaderWithInsertion(Map<String, Object> responseContext, boolean expect) {
    List<OutofBandHeader> hdrToTest = new ArrayList<OutofBandHeader>();
    List<Header> oobHdr = CastUtils.cast((List<?>)responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }

    assertTrue("HeaderHolder list expected to conain 2 object received " + oobHdr.size(),
               oobHdr.size() == 2);
    
    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>)JAXBContext
                    .newInstance(org.apache.cxf.outofband.header.ObjectFactory.class)
                    .createUnmarshaller().unmarshal((Node)hdr1.getObject());
                hdrToTest.add((OutofBandHeader)job.getValue());
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }

    assertTrue("out-of-band header should not be null", hdrToTest.size() > 0);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :"
               + hdrToTest.get(0).getName(), "testOobReturnHeaderName".equals(hdrToTest.get(0).getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :"
               + hdrToTest.get(0).getValue(), "testOobReturnHeaderValue".equals(hdrToTest.get(0).getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :"
               + hdrToTest.get(0).getHdrAttribute(), "testReturnHdrAttribute"
        .equals(hdrToTest.get(0).getHdrAttribute()));
    
    assertTrue("Expected out-of-band Header name New_testOobHeader recevied :"
               + hdrToTest.get(1).getName(), "New_testOobHeader".equals(hdrToTest.get(1).getName()));
    assertTrue("Expected out-of-band Header value New_testOobHeaderValue recevied :"
               + hdrToTest.get(1).getValue(), "New_testOobHeaderValue".equals(hdrToTest.get(1).getValue()));
    assertTrue("Expected out-of-band Header attribute testHdrAttribute recevied :"
               + hdrToTest.get(1).getHdrAttribute(), "testHdrAttribute"
        .equals(hdrToTest.get(1).getHdrAttribute()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:47,代码来源:CxfMessageHeadersRelayTest.java

示例7: getCredentialsFromHeaders

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
private Credentials getCredentialsFromHeaders() {
	if(isDebug) {
		Credentials c = new Credentials();
		LoginToken t = new LoginToken();
		t.setHouseholdId("[thehouseholdid]");
		t.setToken("[thetoken]");
		c.setLoginToken(t);
		return c;
	}
	if(context == null)
		return null;
	MessageContext messageContext = context.getMessageContext();
	if (messageContext == null
			|| !(messageContext instanceof WrappedMessageContext)) {
		logger.error("Message context is null or not an instance of WrappedMessageContext.");
		return null;
	}

	Message message = ((WrappedMessageContext) messageContext)
			.getWrappedMessage();
	List<Header> headers = CastUtils.cast((List<?>) message
			.get(Header.HEADER_LIST));
	if (headers != null) {
		for (Header h : headers) {
			Object o = h.getObject();
			// Unwrap the node using JAXB
			if (o instanceof Node) {
				JAXBContext jaxbContext;
				try {
					jaxbContext = new JAXBDataBinding(Credentials.class)
							.getContext();
					Unmarshaller unmarshaller = jaxbContext
							.createUnmarshaller();
					o = unmarshaller.unmarshal((Node) o);
				} catch (JAXBException e) {
					// failed to get the credentials object from the headers
					logger.error(
							"JaxB error trying to unwrapp credentials", e);
				}
			}
			if (o instanceof Credentials) {
				return (Credentials) o;										
			} else {
				logger.error("no Credentials object");
			}
		}
	} else {
		logger.error("no headers found");
	}
	return null;
}
 
开发者ID:bertique,项目名称:SonosNPROneServer,代码行数:52,代码来源:SonosService.java

示例8: sendResponse

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
protected void sendResponse (HashMap<String,String> returnParameters) {

	// Extract message
	WrappedMessageContext wrappedContext = (WrappedMessageContext) context.getMessageContext();
	Message message = wrappedContext.getWrappedMessage();
	
	// Extract headers from message
	List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
	
	// Find ReplyTo and MessageID SOAP Header
	String replyTo = null;
	String messageID = null;
	for (Header iter : headers) {
					
		Object headerObject = iter.getObject();

		// Unmarshall to org.w3c.dom.Node
		if (headerObject instanceof Node) {
			Node node = (Node) headerObject;
			String localPart = iter.getName().getLocalPart();
			String content = node.getTextContent();
			
			// Extract ReplyTo Header value
			if ("ReplyTo".equals(localPart)) {
				replyTo = content;
			}
			
			// Extract MessageID Header value
			if ("MessageID".equals(localPart)) {
				messageID = content;
			}
		}						
	}
	
	// Create asynchronous SOAP Response Message
	StringBuilder builder = new StringBuilder();
	
	builder.append("<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:sch='http://siserver.org/schema'>");
	builder.append("   <soapenv:Header/>");
	builder.append("   <soapenv:Body>");
	builder.append("      <sch:invokeResponse>");
	builder.append("         <sch:MessageID>" + messageID + "</sch:MessageID>");

	// Insert return parameters into asynchronous SOAP Response Message
	for (Entry<String, String> paramIter : returnParameters.entrySet()) {
		
		String key = paramIter.getKey();
		String value = paramIter.getValue();
		
		builder.append("         <" + key + ">" + value + "</" + key +">");
	}

	builder.append("      </sch:invokeResponse>");			
	builder.append("	</soapenv:Body>");
	builder.append("</soapenv:Envelope>");
	
	// Send SOAP Response Message back to requester
	if(replyTo == null) {
		System.err.println("No 'ReplyTo' header found!\nTherefore, reply message is printed here:\n" + builder.toString());
	} else {
		HighLevelRestApi.Post(replyTo, builder.toString(), "");
	}
}
 
开发者ID:tosca-types,项目名称:openstack,代码行数:64,代码来源:AbstractIAService.java

示例9: sendFaultResponse

import org.apache.cxf.headers.Header; //导入方法依赖的package包/类
protected void sendFaultResponse (String faultcode, String faultstring) {
	
	// Extract message
	WrappedMessageContext wrappedContext = (WrappedMessageContext) context.getMessageContext();
	Message message = wrappedContext.getWrappedMessage();
	
	//System.out.println("SOAP wrappedContext"+wrappedContext.isEmpty());
	
	// Extract headers from message
	List<Header> headers = CastUtils.cast((List<?>) message.get(Header.HEADER_LIST));
	
	// Find ReplyTo and MessageID SOAP Header
	String replyTo = null;
	String messageID = null;
	for (Header iter : headers) {
					
		Object headerObject = iter.getObject();

		// Unmarshall to org.w3c.dom.Node
		if (headerObject instanceof Node) {
			Node node = (Node) headerObject;
			String localPart = iter.getName().getLocalPart();
			String content = node.getTextContent();
			
			// Extract ReplyTo Header value
			if ("ReplyTo".equals(localPart)) {
				replyTo = content;
			}
			
			// Extract MessageID Header value
			if ("MessageID".equals(localPart)) {
				messageID = content;
			}
		}						
	}
	
	// Create asynchronous SOAP Response Message
	StringBuilder builder = new StringBuilder();
	
	builder.append("<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>");
	builder.append("   <soapenv:Header/>");
	builder.append("   <soapenv:Body>");
	builder.append("   	<soapenv:Fault>");		

	// Insert return parameters into asynchronous SOAP Response Message
		
	builder.append("       <faultcode>" + faultcode + "</faultcode>");
	builder.append("       <faultstring>" + faultstring + "</faultstring>");	
	
	builder.append("     </soapenv:Fault>");
	builder.append("	</soapenv:Body>");
	builder.append("</soapenv:Envelope>");
	
	// Send SOAP Response Message back to requester
	if(replyTo == null) {
		System.err.println("No 'ReplyTo' header found!\nTherefore, reply message is printed here:\n" + builder.toString());
	} else 
	{			
		HighLevelRestApi.Post(replyTo, builder.toString(), "");
	}
}
 
开发者ID:tosca-types,项目名称:openstack,代码行数:62,代码来源:AbstractIAService.java


注:本文中的org.apache.cxf.headers.Header.getObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。