2013-11-26 5 views
1

여기 코드에 대해 묻지 않습니다! 나는 여기의 흐름에 대해 묻고있다.회사 하우스 XML 게이트웨이를 사용하여 회사 이름 검색 가능

XML gateway of Companies House을 통해 회사 명을 검색하고 싶습니다. Java에서 jabx를 사용하여 데이터를 마샬링 및 비 정렬 화하는 방법을 알고 있지만 응용 프로그램의 정확한 흐름을 알지 못합니다. 아무도 어디서부터 시작해야할지 말해 줄 수 있습니까? Companies House는 sample XML requestsample XML response을 제공합니다.

내 코드를 찾으십시오.

package Classes; 

import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.InputStream; 
import org.apache.commons.httpclient.HttpClient; 
import org.apache.commons.httpclient.methods.InputStreamRequestEntity; 
import org.apache.commons.httpclient.methods.PostMethod; 


public class PostXML { 

    public static void main(String args[]) throws FileNotFoundException { 
     // Get target URL 
     String strURL = "http://xmlgw.companieshouse.gov.uk/v1-0/xmlgw/Gateway" ; 

     // Get file to be posted 
     String strXMLFilename = "F:\\12-8\\CompanyFormation\\CompanyFormation\\web\\file.xml"; 
     File input = new File(strXMLFilename); 

     // Prepare HTTP post 
     PostMethod post = new PostMethod(strURL); 

     // Request content will be retrieved directly 
     // from the input stream 
     // Per default, the request content needs to be buffered 
     // in order to determine its length. 
     // Request body buffering can be avoided when 
     // content length is explicitly specified 
     post.setRequestEntity(new InputStreamRequestEntity(new FileInputStream(input), input.length())); 

     // Specify content type and encoding 
     // If content encoding is not explicitly specified 
     // ISO-8859-1 is assumed 
     post.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1"); 

     // Get HTTP client 
     HttpClient httpclient = new HttpClient(); 

     // Execute request 
     try { 
      int result = httpclient.executeMethod(post); 

      // Display status code 
      System.out.println("Response status code: " + result); 

      // Display response 
      System.out.println("Response body: "); 
      System.out.println(post.getResponseBodyAsString()); 


     } catch (Exception e) { 
      e.printStackTrace(); 

     } finally { 
      // Release current connection to the connection pool 
      // once you are done 
      post.releaseConnection(); 
     } 

    } 
} 

내 생성 요청 :

<GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v1-0/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
    <EnvelopeVersion>1.0</EnvelopeVersion> 
    <Header> 
    <MessageDetails> 
     <Class>NameSearch</Class> 
     <Qualifier>request</Qualifier> 
     <TransactionID>1</TransactionID> 
    </MessageDetails> 
    <SenderDetails> 
     <IDAuthentication> 
     <SenderID>XMLGatewayTestUserID</SenderID> 
     <Authentication> 
      <Method>CHMD5</Method> 
      <Value>XMLGatewayTestPassword</Value> 
     </Authentication> 
     </IDAuthentication> 
    </SenderDetails> 
    </Header> 
    <GovTalkDetails> 
    <Keys/> 
    </GovTalkDetails> 
    <Body> 
<NameSearchRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlgw.companieshouse.gov.uk/v1-0/schema/NameSearch.xsd"> 
<CompanyName>SPECIALIST PENSION SERVICES LIMITED</CompanyName> 
<DataSet>LIVE</DataSet> 
<SameAs>0</SameAs> 
<SearchRows>100</SearchRows> 
</NameSearchRequest> 
    </Body> 
</GovTalkMessage> 

OUTPUT

응답 상태 코드 : 200 응답 본체 : 2014년 1월 7일 오후 12시 30분 2초의 org.apache.commons.httpclient .HttpMethodBase getResponseBody 경고 : 크기가 크거나 알 수없는 버퍼 응답 본문으로 이동합니다. 대신 getResponseBodyAsStream을 사용하는 것이 좋습니다. <MessageDetails>에서

<?xml version="1.0" encoding="UTF-8" ?> 
<GovTalkMessage xsi:schemaLocation="http://www.govtalk.gov.uk/CM/envelope http://xmlgw.companieshouse.gov.uk/v1-0/schema/Egov_ch-v2-0.xsd" xmlns="http://www.govtalk.gov.uk/CM/envelope" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:gt="http://www.govtalk.gov.uk/schemas/govtalk/core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
    <EnvelopeVersion>1.0</EnvelopeVersion> 
    <Header> 
    <MessageDetails> 
     <Class>NameSearch</Class> 
     <Qualifier>error</Qualifier> 
     <TransactionID>1</TransactionID> 
     <GatewayTimestamp>2014-01-07T06:59:50-00:00</GatewayTimestamp> 
    </MessageDetails> 
    <SenderDetails> 
     <IDAuthentication> 
     <SenderID>XMLGatewayTestUserID</SenderID> 
     <Authentication> 
      <Method>CHMD5</Method> 
      <Value>XMLGatewayTestPassword</Value> 
     </Authentication> 
     </IDAuthentication> 
    </SenderDetails> 
    </Header> 
    <GovTalkDetails> 
    <Keys/> 
    <GovTalkErrors> 
     <Error> 
     <RaisedBy>NameSearch</RaisedBy> 
     <Number>502</Number> 
     <Type>fatal</Type> 
     <Text>Authorisation Failure</Text> 
     <Location></Location> 
     </Error> 
    </GovTalkErrors> 
    </GovTalkDetails> 
    <Body> 
    </Body> 
</GovTalkMessage> 
+0

http://stackoverflow.com/questions/15085648/jaxb-unmarshalled-fields-are-null –

+0

"* the flow *"란 무엇을 의미합니까? 아마도 이미 작성한 코드를 게시하고 어디서 붙어 있는지 설명 할 수 있습니까? –

+0

hello @Duncan 전달 된 XML 및 출력 XML과 함께 Java 코드를 게시했습니다. 제발 제안하십시오. –

답변

2

<Class> 태그가 잘못되었습니다. 나는 당신이 원하는 가치가 NameSearch (공백없이)라고 믿습니다.

+0

안녕하세요 톰! 고마워, 그게 내 608 오류를 해결하지만, 지금은 502 인증 오류를 얻을, 비록 내가 올바른 테스트 자격 증명을 입력 한 제발 내 편집 된 질문 및 코드를 봐. –