怎么使用Java在SAP C4C里创建销售订单
发表于:2025-02-05 作者:千家信息网编辑
千家信息网最后更新 2025年02月05日,本篇内容介绍了"怎么使用Java在SAP C4C里创建销售订单"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学
千家信息网最后更新 2025年02月05日怎么使用Java在SAP C4C里创建销售订单
本篇内容介绍了"怎么使用Java在SAP C4C里创建销售订单"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
需要创建的销售订单的明细通过硬编码指定:
比如销售订单的描述为Jerry Test 2019-1-23 16:05PM
执行之后,看到Status Code 201,说明创建成功:
到UI上能看到成功创建的销售订单:
实现代码:
package odata;import java.io.IOException;import java.io.UnsupportedEncodingException;import java.net.URI;import org.apache.http.HttpEntity;import org.apache.http.HttpHost;import org.apache.http.HttpResponse;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.config.RequestConfig;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.methods.HttpPost;import org.apache.http.entity.StringEntity;import org.apache.http.impl.client.HttpClientBuilder;public class SimpleOrderCreator { private final String SERVICEURL = "https://my5000jerry.c4c.saphybriscloud.cn/sap/c4c/odata/cust/v1/zjerrysalesorder/CustomerQuoteCollection"; HttpClient m_httpClient; private HttpClient getHttpClient() { if (this.m_httpClient == null) { this.m_httpClient = HttpClientBuilder.create().build(); } return this.m_httpClient; } private String getCSRFToken(){ final HttpGet get = new HttpGet(SERVICEURL); get.setHeader("Authorization", "Basic 0FOR0pFUlJZMTpTYXB0ZXN0MQ=="); get.setHeader("x-csrf-token", "fetch"); HttpHost proxy = new HttpHost("proxy.sha.sap.corp", 8080, "http"); RequestConfig config = RequestConfig.custom().setProxy(proxy).build(); get.setConfig(config); HttpResponse response; String token = null; try { response = getHttpClient().execute(get); /*Header[] header = response.getAllHeaders(); for( int i =0; i < header.length; i++){ System.out.println("Header: " + header[i].getValue()); }*/ token = response.getFirstHeader("x-csrf-token").getValue(); System.out.println("token: " + token); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException | UnsupportedOperationException e) { e.printStackTrace(); } return token; } private void createSO(String token,String body) { final HttpPost post = new HttpPost( URI.create(SERVICEURL)); post.setHeader("Authorization", "Basic 0FOR0pFUlJZMTpTYXB0ZXN0MQ=="); post.setHeader("Content-Type", "application/json"); post.setHeader("X-CSRF-Token", token); HttpEntity entity = null; try { entity = new StringEntity(body); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } post.setEntity(entity); HttpResponse response = null; try { response = getHttpClient().execute(post); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("Response statusCode for Batch => " + response.getStatusLine().getStatusCode()); } public static void main(String[] args) { SimpleOrderCreator tool = new SimpleOrderCreator(); String token = tool.getCSRFToken(); String body = "{" + "\"Name\": \"Jerry Test 2019-1-23 16:05PM\"," + "\"TypeCode\": \"2059\"," + "\"BuyerID\":\"ee\"," + "\"PartyID\":\"60102\", " + "\"CustomerQuoteText\":[{" + "\"Text\": \"test comment by Jerry Wang\", " + "\"TypeCode\": \"10024\"" + "}]," + "\"CustomerQuoteItem\":[{ " + "\"ProductID\": \"1042416\"" + "}]," + "\"CustomerQuoteItemProposal\":[{" + "\"ProductUUID\": \"00163E72-09C6-1EE8-BBDC-AC5F0CB0D795\"," + "\"Quantity\": \"1\"," + "\"unitCode\": \"EA\"" + "}]" + "}"; tool.createSO(token, body); }}
"怎么使用Java在SAP C4C里创建销售订单"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
订单
销售
成功
内容
更多
知识
实用
明细
学有所成
接下来
代码
困境
实际
情况
文章
案例
编带
编码
网站
行业
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
把数据库中的一张表导出
u盘大师制作初始化数据库
国外开源软件开发平台
软件开发面试常见错误是什么
华盾信安网络技术有限公司
璧山区软件开发招聘兼职吗
卡卡网络技术有限公司好吗
明日之后九游渠道服全部服务器
服务器记录值是ip地址吗
傻瓜软件开发pc
办公室网络服务器管理员
网络安全员主要学习内容
数据库创建脚本
人工智能编程与软件开发
长沙岑讯软件开发有限责任公司
软件开发行业研发费用比例
网络安全对应的工种
高科技互联网公司卖菜
中国自主互联网服务器概念股
河南易佳网络技术有限公司
查看mongdb数据库名称
行业并购数据库
服务器push
国产服务器有哪些 联想
sql备份用户数据库的能力
西安数据库大神
广州网络安全服务费用
安卓的软件开发服务方案多少钱
常德快速软件开发
所有的网络安全元素里最安全