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


Java Dispatch.getRequestContext方法代码示例

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


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

示例1: launchMobyAsyncService

import javax.xml.ws.Dispatch; //导入方法依赖的package包/类
/**
 * This method is used to launch an asynchronous MOBY job.
 *
 * @param endpoint
 *            The endpoint of the service.
 * @param msName
 *            The MOBY service name.
 * @param mobyXML
 *            The MOBY payload to be sent to the service.
 * @return The EndpointReference object which helds the details of the MOBY
 *         asynchronous job.
 * @throws MobyException
 */
private static EndpointReference launchMobyAsyncService(String endpoint,
		String msName, String mobyXML) throws MobyException {
	try {
		Service service = Service.create(new QName(
				MobyService.BIOMOBY_SERVICE_URI, msName + "Service"));
		QName mQName = new QName(MobyService.BIOMOBY_SERVICE_URI, msName
				+ "Port");

		service.addPort(mQName, SOAPBinding.SOAP11HTTP_BINDING, endpoint);
		Dispatch<SOAPMessage> dispatch = service.createDispatch(mQName,
				SOAPMessage.class, Service.Mode.MESSAGE);
		Map<String, Object> rc = dispatch.getRequestContext();
		rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, new Boolean(true));
		rc.put(BindingProvider.SOAPACTION_URI_PROPERTY,
				MobyService.BIOMOBY_SERVICE_URI + "#" + msName + "_submit");

		MessageFactory mf = MessageFactory.newInstance();
		SOAPMessage request = mf.createMessage();
		SOAPPart part = request.getSOAPPart();

		String mobyPrefix = "mobyws";
		String xsiPrefix = "xsi";

		// Obtain the SOAPEnvelope and header and body elements.
		SOAPEnvelope env = part.getEnvelope();
		SOAPBody body = env.getBody();

		// Now the SOAP body
		body.addNamespaceDeclaration(mobyPrefix,
				MobyService.BIOMOBY_SERVICE_URI);
		SOAPElement rootMessage = body.addChildElement(msName + "_submit",
				mobyPrefix, MobyService.BIOMOBY_SERVICE_URI);
		SOAPElement data = rootMessage.addChildElement("data", mobyPrefix,
				MobyService.BIOMOBY_SERVICE_URI);
		data.addNamespaceDeclaration(xsiPrefix,
				MobyPrefixResolver.XSI_NAMESPACE2001);
		data.addNamespaceDeclaration("xsd", XSD_NS);
		data.addAttribute(env.createName("type", xsiPrefix,
				MobyPrefixResolver.XSI_NAMESPACE2001), "xsd:string");
		data.addTextNode(mobyXML);

		request.saveChanges();
		SOAPMessage outputMessage = dispatch.invoke(request);
		DOMSource output = new DOMSource(outputMessage.getSOAPPart()
				.getEnvelope());

		StringWriter sw = new StringWriter();
		Transformer tr = TransformerFactory.newInstance().newTransformer();
		tr.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
		tr.transform(output, new StreamResult(sw));

		String response = sw.toString();
		return EndpointReference.createFromXML(response);
	} catch (SOAPException pce) {
		throw new MobyException(
				"Unable to create SOAP document builder for MOBY asynchronous call submission",
				pce);
	} catch (TransformerConfigurationException tce) {
		throw new MobyException(
				"Unable to create transformer factory for MOBY asynchronous call response",
				tce);
	} catch (TransformerException te) {
		throw new MobyException(
				"Unable to create transformer for MOBY asynchronous call response",
				te);
	}
}
 
开发者ID:apache,项目名称:incubator-taverna-plugin-bioinformatics,代码行数:81,代码来源:ExecuteAsyncMobyService.java


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