设为首页收藏本站

SAP Best Business Solution

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2221|回复: 0

java call SAP PI webservice

[复制链接]

20

主题

21

帖子

164

积分

注册会员

Rank: 2

积分
164
发表于 2016-10-20 23:05:26 | 显示全部楼层 |阅读模式
package org.wsjava.cxf.ws.consumer;

import java.math.BigDecimal;
import java.util.Map;
import javax.xml.ws.BindingProvider;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import com.rfmd.usp.utacdg.UTACDGRequest;
import com.rfmd.usp.utacdg.UTACDGResponse;
import com.rfmd.usp_utacdg.MIUSPUTACDGREQUEST;
import com.rfmd.usp_utacdg.MIUSPUTACDGREQUESTService;

public class ClientMain2 {

        public static void main(String[] args) {

               
                // 得到本地服务类
                MIUSPUTACDGREQUESTService service = new MIUSPUTACDGREQUESTService();

                // 得到接口的代理
                MIUSPUTACDGREQUEST stub = service.getHTTPSPort();

                Client client = ClientProxy.getClient(stub);

                // 添加In拦截器
           client.getInInterceptors().add(new LoggingInInterceptor());
                // 添加Out拦截器
                // client.getOutInterceptors().add(new
                // AdderHeaderInterceptor("wsjava","kevin"));

                client.getOutInterceptors().add(new LoggingOutInterceptor());
                String WS_URL = "https://b2btest.qorvo.com:9508/XISOAPAdapter/MessageServlet?channel=:BS_UTACDG:CC_UTACDG_SoapSender";
               
            //String WS_URL = "https://b2btest.qorvo.com:9508/webdynpro/welcome/wsdl/f8d7bb1e463732ccbe11d908a1d06dfe.wsdl";
                // 设置访问接口服务器的用户名和密码
                BindingProvider bp = (BindingProvider) stub;
                Map<String, Object> context = bp.getRequestContext();
                bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "User");
            bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "password");
                bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,WS_URL);

        /*        Map<String, Object> req_ctx = ((BindingProvider)stub).getRequestContext();
                req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL);
                Map<String, List<String>> headers = new HashMap<String, List<String>>();
                headers.put("Username", Collections.singletonList("mkyong"));
                headers.put("Password", Collections.singletonList("password"));
                req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);*/
               

                UTACDGRequest utacRequest = new UTACDGRequest();
                com.rfmd.usp.utacdg.ControlInfoRequired controlInfoRequired = new com.rfmd.usp.utacdg.ControlInfoRequired();
                controlInfoRequired.setTransactionType("07");
                controlInfoRequired.setTransactionReverse("N");
                controlInfoRequired.setTransactionWorkCenterCode("U30");
                controlInfoRequired.setTransactionEndUserID("KEVIN HUO");
                utacRequest.setControlInfoRequired(controlInfoRequired);

                com.rfmd.usp.utacdg.ControlInfoConditional controlInfoConditional = new com.rfmd.usp.utacdg.ControlInfoConditional();
                controlInfoConditional.setTransactionLocalDate("20161001");
                controlInfoConditional.setTransactionLocalTime("131200");
                utacRequest.setControlInfoConditional(controlInfoConditional);

                com.rfmd.usp.utacdg.ClientTransactionInfo clientTransactionInfo = new com.rfmd.usp.utacdg.ClientTransactionInfo();
                clientTransactionInfo.setClientTransactionReferenceNumber("test01101");
                utacRequest.setClientTransactionInfo(clientTransactionInfo);

                com.rfmd.usp.utacdg.PurchaseOrderInfo purchaseOrderInfo = new com.rfmd.usp.utacdg.PurchaseOrderInfo();
                purchaseOrderInfo.setPurchaseOrderNumber("po001");
                purchaseOrderInfo.setPurchaseOrderLineNumber("00010");
                utacRequest.setPurchaseOrderInfo(purchaseOrderInfo);

                com.rfmd.usp.utacdg.DeliveryReceiptInfo deliveryReceiptInfo = new com.rfmd.usp.utacdg.DeliveryReceiptInfo();
                deliveryReceiptInfo.setDeliveryNumber("dn001");
                utacRequest.setDeliveryReceiptInfo(deliveryReceiptInfo);

                com.rfmd.usp.utacdg.InventoryLocationInfo inventoryLocationInfo = new com.rfmd.usp.utacdg.InventoryLocationInfo();
                inventoryLocationInfo.setStorageLocation("U30-DIEBANK");
                // inventoryLocationInfo.setStorageLocationTo(value);
                utacRequest.setInventoryLocationInfo(inventoryLocationInfo);

                com.rfmd.usp.utacdg.BatchInfoRequired batchInfoRequired = new com.rfmd.usp.utacdg.BatchInfoRequired();
                batchInfoRequired.setBatchLabelSequenceNumber("utactest001");
                batchInfoRequired.setBatchMaterial("KIWI5_REVB");
                // batchInfoRequired.setBatchNumber();
                batchInfoRequired.setBatchQty(new BigDecimal(1000));
                batchInfoRequired.setBatchQtyUOM("EA");
                utacRequest.setBatchInfoRequired(batchInfoRequired);

                com.rfmd.usp.utacdg.BatchInfoConditional batchInfoConditional = new com.rfmd.usp.utacdg.BatchInfoConditional();
                // batchInfoConditional.setBatchAssemblyCOO(value);
                // batchInfoConditional.setBatchAssemblyDateCode(value);
                // batchInfoConditional.setScrapQty(new BigInteger(0));
                utacRequest.setBatchInfoConditional(batchInfoConditional);

                com.rfmd.usp.utacdg.ExternalBatchInfo externalBatchInfo = new com.rfmd.usp.utacdg.ExternalBatchInfo();
                // externalBatchInfo.setLotExpirationDate(value);
                externalBatchInfo.setVendorLotNumber("DA44G.1");
                // externalBatchInfo.setWaferLotNumber(value);
                utacRequest.setExternalBatchInfo(externalBatchInfo);

                UTACDGResponse response = new UTACDGResponse();
                // 执行接口
                try {
                        response = stub.miUSPUTACDGREQUEST(utacRequest);
                } catch (com.rfmd.usp_utacdg.FMTMessageFault e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
                System.out.print(response.getTransactionErrorInfo().getTransactionErrorItem().get(0).getErrorClass() + "\n");
                System.out.print(
                                response.getTransactionErrorInfo().getTransactionErrorItem().get(0).getErrorMessageNumber() + "\n");
                System.out.print(response.getTransactionErrorInfo().getTransactionErrorItem().get(0).getErrorType() + "\n");
                System.out.print(
                                response.getTransactionErrorInfo().getTransactionErrorItem().get(0).getErrorMessageText() + "\n");

        }

}


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



QQ|Archiver|手机版|小黑屋|www.sapbbs.com    

GMT+8, 2019-8-21 03:35 , Processed in 1.060489 second(s), 30 queries .

声明:本站严禁任何人以任何形式在本论坛发表与中华人民共和国法律相抵触的言论!

本站内容由网友原创或转载,如果侵犯了您的合法权益,请及时联系处理!© admin@sapbbs.com

快速回复 返回顶部 返回列表