Maximo 7.5 REST API를 사용하고 있으며 Java에서 REST 클라이언트를 작성하여이 RESTful 서비스를 사용하려고합니다. Maximo 사용자가 자체 REST 서비스에 액세스 할 수 있도록 Maximo 7.5 측에서 Maximo 보안을 사용 가능하게했습니다. 아래 Maximo RESTful 서비스에 대한 내 web.xml은 다음과 같습니다.Java 코드를 사용하여 Maximo RESTful 서비스를 사용하십시오.
<security-constraint>
<web-resource-collection>
<web-resource-name>REST Servlet for Web App</web-resource-name>
<description>Object Structure Service Servlet (HTTP POST) accessible by authorized users</description>
<url-pattern>/rest/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<description>Roles that have access to Object Structure Service Servlet (HTTP POST)</description>
<role-name>maximouser</role-name>
</auth-constraint>
<user-data-constraint>
<description>data transmission gaurantee</description>
<transport-guarantee>NONE</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>REST Web Application Realm</realm-name>
</login-config>
Chrome의 Postman 플러그인을 사용하여 Maximo REST 서비스를 성공적으로 쿼리 할 수 있습니다. 아래 2는 내 우편 배달부 (REST 클라이언트) 헤더입니다. 1 MAXAUTH - bWF4YWRtaW46bWF4YWRtaW4 = 수락 2. - 응용 프로그램/XML
을 내가 헤더의 인증 (MAXAUTH)을 준하지만, 나는 이름과 MAXIMO REST 서비스를 조회하는 암호를 입력 할 수있는 팝업 창을 얻기 위해 사용 . 자격 증명을 받으면 응답을받습니다 (아래 참조)
아래는 동일한 RESTful 서비스를 사용하는 Java 코드입니다. 나는 계속해서 401 오류를 얻고 있으며 자격 증명으로 자격 증명을 제공하고 있지만 승인하지는 않습니다.
이 이Output from Server ....1
Output from Server ....3
java.io.IOException: Server returned HTTP response code: 401 for URL: http://vhost0043.dc1.co.us.compute.ihost.com/maxrest/rest/os/mxperson?personid=maxadmin
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at RESTConsume.main(RESTConsume.java:35)
이 이 그것은 다른 RESTful 서비스 (하지 MAXIMO RESTful 서비스) 우리는 보안을 갖고 있지 않은 예상대로 응답을 얻기 위해 노력하고 있습니다
이 활성화되지 않은 : 다음
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class RESTConsume {
// http://localhost:8080/RESTfulExample/json/product/get
public static void main(String[] args) {
try {
URL url = new URL("HOSTNAME/maxrest/rest/os/mxperson?personid=maxadmin");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("Accept", "Application/xml");
connection.setRequestProperty("MAXAUTH", "bWF4YWRtaW46bWF4YWRtaW4=");
System.out.println("Output from Server ....1 \n");
/*
* if (conn.getResponseCode() != 200) {
* System.out.println("Output from Server ....2 \n");
*
* throw new RuntimeException("Failed : HTTP error code : "+
* conn.getResponseCode()); }
*/
System.out.println("Output from Server ....3 \n");
BufferedReader br = new BufferedReader(new InputStreamReader(
(connection.getInputStream())));
System.out.println("Output from Server ....4 \n");
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
내 출력 . Maximo RESTful 서비스를 사용하기 위해 추가 작업이 필요한지 알려주십시오.
Maximo 보안을 활성화 했으므로 서비스에서 사용자 이름과 비밀번호를 예상하지만 IBM 문서에 명시된대로 속성에 MAXAUTH ==> bWF4YWRtaW46bWF4YWRtaW4 =입니다. 이 링크 http://pic.dhe.ibm.com/infocenter/tivihelp/v50r1/index.jsp?topic=%2Fcom.ibm.mif.doc%2Fgp_intfrmwk%2Frest_api%2Fc_rest_security.html을 참조하십시오. – tasmohan